summary refs log tree commit diff
path: root/src/config.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/config.zig')
-rw-r--r--src/config.zig36
1 files changed, 32 insertions, 4 deletions
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"))