Use new struct for actions
This commit is contained in:
parent
52f35807d3
commit
6c77226652
|
@ -11,12 +11,20 @@ const Action = @import("Action.zig");
|
||||||
|
|
||||||
const Self = @This();
|
const Self = @This();
|
||||||
|
|
||||||
action_list: [5]Action = .{
|
const ActionList = struct {
|
||||||
Action.init(SDL.Scancode.right, actionTabRight), // Tab Right
|
right: Action,
|
||||||
Action.init(SDL.Scancode.left, actionTabLeft), // Tab left
|
left: Action,
|
||||||
Action.init(SDL.Scancode.down, actionSelDown), // Go down
|
down: Action,
|
||||||
Action.init(SDL.Scancode.up, actionSelUp), // Go up
|
up: Action,
|
||||||
Action.init(SDL.Scancode.@"return", actionSelect), // Select
|
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 = .{
|
tab_list: [3]MenuTab = .{
|
||||||
|
@ -95,7 +103,9 @@ pub fn tick(self: *Self) State {
|
||||||
//const tab = self.getTab();
|
//const tab = self.getTab();
|
||||||
var key_state = SDL.getKeyboardState();
|
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) {
|
if (key_state.isPressed(action.*.scancode) and !action.*.holding) {
|
||||||
action.*.holding = true;
|
action.*.holding = true;
|
||||||
action.*.activate = true;
|
action.*.activate = true;
|
||||||
|
|
Loading…
Reference in New Issue