Use new struct for actions

This commit is contained in:
Dusk 2022-12-01 12:01:55 +01:00
parent 52f35807d3
commit 6c77226652
1 changed files with 17 additions and 7 deletions

View File

@ -11,12 +11,20 @@ const Action = @import("Action.zig");
const Self = @This();
action_list: [5]Action = .{
Action.init(SDL.Scancode.right, actionTabRight), // Tab Right
Action.init(SDL.Scancode.left, actionTabLeft), // Tab left
Action.init(SDL.Scancode.down, actionSelDown), // Go down
Action.init(SDL.Scancode.up, actionSelUp), // Go up
Action.init(SDL.Scancode.@"return", actionSelect), // Select
const ActionList = struct {
right: Action,
left: Action,
down: Action,
up: Action,
select: Action,
};
action_list: ActionList = .{
.right = Action.init(SDL.Scancode.right, actionTabRight), // Tab Right
.left = Action.init(SDL.Scancode.left, actionTabLeft), // Tab left
.down = Action.init(SDL.Scancode.down, actionSelDown), // Go down
.up = Action.init(SDL.Scancode.up, actionSelUp), // Go up
.select = Action.init(SDL.Scancode.@"return", actionSelect), // Select
},
tab_list: [3]MenuTab = .{
@ -95,7 +103,9 @@ pub fn tick(self: *Self) State {
//const tab = self.getTab();
var key_state = SDL.getKeyboardState();
for (self.action_list) |*action| {
const action_fields = std.meta.fields(ActionList);
inline for (action_fields) |field| {
const action = &@field(self.action_list, field.name);
if (key_state.isPressed(action.*.scancode) and !action.*.holding) {
action.*.holding = true;
action.*.activate = true;