~sircmpwn/tetrominoes

tetrominoes/config.ha -rw-r--r-- 944 bytes
7209df15Drew DeVault Update for integer changes 3 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
use format::ini;
use fs;
use io;
use os;
use sdl2;

fn config(
	keybindings: *[](sdl2::keycode, action),
	cfg: io::handle,
) (void | ini::error | sdl2::error) = {
	let sc = ini::scan(cfg);
	defer ini::finish(&sc);
	for (true) match (ini::next(&sc)?) {
	case io::EOF =>
		break;
	case let e: ini::entry =>
		switch (e.0) {
		case "keyboard" =>
			const action = switch (e.1) {
			case "commit" =>
				yield action::COMMIT;
			case "down" =>
				yield action::DOWN;
			case "left" =>
				yield action::LEFT;
			case "right" =>
				yield action::RIGHT;
			case "rotleft" =>
				yield action::ROTLEFT;
			case "rotright" =>
				yield action::ROTRIGHT;
			case =>
				continue;
			};
			let keycode = sdl2::get_key_from_name(e.2)?;
			for (let i = 0z; i < len(keybindings); i += 1) {
				if (keybindings[i].0 == keycode) {
					delete(keybindings[i]);
					i -= 1;
				};
			};
			append(keybindings, (keycode, action));
		case => void;
		};
	};
};