diff options
Diffstat (limited to 'src/config.zig')
-rw-r--r-- | src/config.zig | 72 |
1 files changed, 43 insertions, 29 deletions
diff --git a/src/config.zig b/src/config.zig index 86eb6d8..2e028f1 100644 --- a/src/config.zig +++ b/src/config.zig @@ -140,30 +140,32 @@ pub const Config = extern struct { music: bool = true, mouse_sensitivity: f32 = 1.0, - // TODO: Convert to Key enum key: extern struct { - forwards: c_int = @enumToInt(Key.W), - backwards: c_int = @enumToInt(Key.S), - left: c_int = @enumToInt(Key.A), - right: c_int = @enumToInt(Key.D), - crouch: c_int = @enumToInt(Key.LEFT_CONTROL), - accelerate: c_int = @enumToInt(Key.LEFT_SHIFT), - dive: c_int = @enumToInt(Key.SPACE), - reload: c_int = @enumToInt(Key.R), - aim: c_int = @enumToInt(Key.E), - psychic_aim: c_int = @enumToInt(Key.Q), - psychic: c_int = @enumToInt(Key.Z), - laser_sight: c_int = @enumToInt(Key.L), + forwards: Key = .W, + backwards: Key = .S, + left: Key = .A, + right: Key = .D, + crouch: Key = .LEFT_CONTROL, + accelerate: Key = .LEFT_SHIFT, + dive: Key = .SPACE, + reload: Key = .R, + aim: Key = .E, + psychic_aim: Key = .Q, + psychic: Key = .Z, + laser_sight: Key = .L, + + switch_view: Key = .TAB, + switch_weapon: Key = .X, + skip: Key = .K, + pause: Key = .P, + slomo: Key = .B, + force: Key = .F, } = .{}, levels: extern struct { ptr: [*]Level = undefined, len: usize = 0 } = .{}, debug: bool = false, }; -fn parseKey(str: []const u8) c_int { - return @enumToInt(stringToEnum(Key, str).?); -} - /// Parse config.ini in the given base directory. pub fn parse(base_dir: []const u8) !Config { const config_dir = try join(allocator, &.{ base_dir, "blackshades" }); @@ -204,29 +206,41 @@ pub fn parse(base_dir: []const u8) !Config { if (eql(u8, kv.key, "mouse sensitivity")) config.mouse_sensitivity = try parseFloat(f32, kv.value) else if (eql(u8, kv.key, "forwards key")) - config.key.forwards = parseKey(kv.value) + config.key.forwards = stringToEnum(Key, kv.value).? else if (eql(u8, kv.key, "backwards key")) - config.key.backwards = parseKey(kv.value) + config.key.backwards = stringToEnum(Key, kv.value).? else if (eql(u8, kv.key, "left key")) - config.key.left = parseKey(kv.value) + config.key.left = stringToEnum(Key, kv.value).? else if (eql(u8, kv.key, "right key")) - config.key.right = parseKey(kv.value) + config.key.right = stringToEnum(Key, kv.value).? else if (eql(u8, kv.key, "crouch key")) - config.key.crouch = parseKey(kv.value) + config.key.crouch = stringToEnum(Key, kv.value).? else if (eql(u8, kv.key, "accelerate key")) - config.key.accelerate = parseKey(kv.value) + config.key.accelerate = stringToEnum(Key, kv.value).? else if (eql(u8, kv.key, "dive key")) - config.key.dive = parseKey(kv.value) + config.key.dive = stringToEnum(Key, kv.value).? else if (eql(u8, kv.key, "reload key")) - config.key.reload = parseKey(kv.value) + config.key.reload = stringToEnum(Key, kv.value).? else if (eql(u8, kv.key, "aim key")) - config.key.aim = parseKey(kv.value) + config.key.aim = stringToEnum(Key, kv.value).? else if (eql(u8, kv.key, "psychic aim key")) - config.key.psychic_aim = parseKey(kv.value) + config.key.psychic_aim = stringToEnum(Key, kv.value).? else if (eql(u8, kv.key, "psychic key")) - config.key.psychic = parseKey(kv.value) + config.key.psychic = stringToEnum(Key, kv.value).? else if (eql(u8, kv.key, "laser sight key")) - config.key.laser_sight = parseKey(kv.value) + config.key.laser_sight = stringToEnum(Key, kv.value).? + else if (eql(u8, kv.key, "switch view key")) + config.key.switch_view = stringToEnum(Key, kv.value).? + else if (eql(u8, kv.key, "switch weapon key")) + config.key.switch_weapon = stringToEnum(Key, kv.value).? + else if (eql(u8, kv.key, "skip key")) + config.key.skip = stringToEnum(Key, kv.value).? + else if (eql(u8, kv.key, "pause key")) + config.key.pause = stringToEnum(Key, kv.value).? + else if (eql(u8, kv.key, "slomo key")) + config.key.slomo = stringToEnum(Key, kv.value).? + else if (eql(u8, kv.key, "force key")) + config.key.force = stringToEnum(Key, kv.value).? else return error.InvalidData; } else if (eql(u8, section, "misc")) { if (eql(u8, kv.key, "custom levels")) |