diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/GameInitDispose.cpp | 14 | ||||
-rw-r--r-- | src/config.h | 4 | ||||
-rw-r--r-- | src/config.zig | 36 | ||||
-rw-r--r-- | src/main.zig | 5 |
4 files changed, 46 insertions, 13 deletions
diff --git a/src/GameInitDispose.cpp b/src/GameInitDispose.cpp index 2928d5f..c4e1518 100644 --- a/src/GameInitDispose.cpp +++ b/src/GameInitDispose.cpp @@ -80,13 +80,13 @@ Game* makeGame(Config config, Scores scores) game->musictoggle = config.music; game->mouse_sensitivity = config.mouse_sensitivity; - forwardskey = GLFW_KEY_W; - backwardskey = GLFW_KEY_S; - leftkey = GLFW_KEY_A; - rightkey = GLFW_KEY_D; - aimkey = GLFW_KEY_E; - psychicaimkey = GLFW_KEY_Q; - psychickey = GLFW_KEY_Z; + forwardskey = config.key.forwards; + backwardskey = config.key.backwards; + leftkey = config.key.left; + rightkey = config.key.right; + aimkey = config.key.aim; + psychicaimkey = config.key.psychic_aim; + psychickey = config.key.psychic; game->levels = config.levels.ptr; game->nummissions = config.levels.len; diff --git a/src/config.h b/src/config.h index f6d7283..f4ed20d 100644 --- a/src/config.h +++ b/src/config.h @@ -24,6 +24,10 @@ struct Config { bool music; float mouse_sensitivity; + struct { + int forwards, backwards, left, right; + int aim, psychic_aim, psychic; + } key; struct { struct Level *ptr; diff --git a/src/config.zig b/src/config.zig index 4a1840d..64785f8 100644 --- a/src/config.zig +++ b/src/config.zig @@ -18,11 +18,13 @@ const Dir = std.fs.Dir; const File = std.fs.File; +const Key = gfz.Key; const allocator = std.heap.c_allocator; const c = @import("main.zig").c; const cwd = std.fs.cwd; const data_dir = @import("build_options").data_dir; const eql = std.mem.eql; +const gfz = @import("gfz"); const ini = @import("ini"); const join = std.fs.path.join; const maxInt = std.math.maxInt; @@ -31,6 +33,7 @@ const parseBool = @import("misc.zig").parseBool; const parseFloat = std.fmt.parseFloat; const parseInt = std.fmt.parseInt; const std = @import("std"); +const stringToEnum = std.meta.stringToEnum; const tokenize = std.mem.tokenize; const default_levels_len = 13; @@ -138,14 +141,25 @@ 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), + aim: c_int = @enumToInt(Key.E), + psychic_aim: c_int = @enumToInt(Key.Q), + psychic: c_int = @enumToInt(Key.Z), + } = .{}, - levels: extern struct { - ptr: [*]Level, - len: usize, - } = .{ .ptr = undefined, .len = 0 }, + 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" }); @@ -185,6 +199,20 @@ pub fn parse(base_dir: []const u8) !Config { } else if (eql(u8, section, "input")) { 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) + else if (eql(u8, kv.key, "backwards key")) + config.key.backwards = parseKey(kv.value) + else if (eql(u8, kv.key, "left key")) + config.key.left = parseKey(kv.value) + else if (eql(u8, kv.key, "right key")) + config.key.right = parseKey(kv.value) + else if (eql(u8, kv.key, "aim key")) + config.key.aim = parseKey(kv.value) + else if (eql(u8, kv.key, "psychic aim key")) + config.key.psychic_aim = parseKey(kv.value) + else if (eql(u8, kv.key, "psychic key")) + config.key.psychic = parseKey(kv.value) else return error.InvalidData; } else if (eql(u8, section, "misc")) { if (eql(u8, kv.key, "custom levels")) diff --git a/src/main.zig b/src/main.zig index 4e93a8a..f019a61 100644 --- a/src/main.zig +++ b/src/main.zig @@ -22,6 +22,7 @@ pub const c = @cImport({ }); const Loca = @import("loca").Loca; +const Key = gf.Key; const Window = gf.Window; const Scores = misc.Scores; const al = @import("zeal"); @@ -41,9 +42,9 @@ fn resizeWindow(window: Window, width: c_int, height: c_int) void { c.resizeWindow(game, width, height); } -fn handleKey(window: Window, key: c_int, scancode: c_int, +fn handleKey(window: Window, key: Key, scancode: c_int, action: c_int, mods: c_int) void { - c.handleKey(game, key, action, mods); + c.handleKey(game, @enumToInt(key), action, mods); } fn look(window: Window, xpos: f64, ypos: f64) void { |