Implement input configuration loading from i32

This commit is contained in:
Dusk 2023-10-02 15:38:07 +02:00
parent 174c247e43
commit 3477be28e8
1 changed files with 15 additions and 2 deletions

View File

@ -21,8 +21,21 @@ pub const Input = struct {
}; };
pub fn loadConfig() void { pub fn loadConfig() void {
for (comptime getInputNames()) |name| { var iter = config.getConfigIterator("input.ini") catch {
std.debug.print("{s}\n", .{name}); 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});
}
}
}
} }
} }