From 3477be28e8a534aa0cdd7c586323da7b310edfd8 Mon Sep 17 00:00:00 2001 From: dusk Date: Mon, 2 Oct 2023 15:38:07 +0200 Subject: [PATCH] Implement input configuration loading from i32 --- src/input.zig | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/input.zig b/src/input.zig index d529ab0..9c473b6 100644 --- a/src/input.zig +++ b/src/input.zig @@ -21,8 +21,21 @@ pub const Input = struct { }; pub fn loadConfig() void { - for (comptime getInputNames()) |name| { - std.debug.print("{s}\n", .{name}); + var iter = config.getConfigIterator("input.ini") catch { + std.debug.print("Error loading input config, using defaults...\n", .{}); + return; + }; + + while (iter.next()) |option| { + inline for (comptime getInputNames()) |name| { + if (std.mem.eql(u8, option.key, name)) { + if (std.fmt.parseInt(i32, option.value, 10) catch null) |value| { + @field(Self, name).code = value; + } else { + std.debug.print("Invalid input value '{s}' in config, ignoring.", .{option.value}); + } + } + } } }