// SPDX-License-Identifier: MIT // Copyright (c) 2021 KikooDX // This file is part of [KBLE](https://sr.ht/~kikoodx/kble), which is // MIT licensed. The MIT license requires this copyright notice to be // included in all copies and substantial portions of the software. const std = @import("std"); const expect = std.testing.expect; const conf = @import("conf.zig"); const movement = @import("movement.zig"); const scaling = @import("scaling.zig"); const verbs = @import("verbs.zig"); const Vec2 = @import("vec2.zig"); const Level = @import("level.zig"); const Mode = @import("modes.zig").Mode; pub const ActionCat = enum { none, // do nothing movement, // move and change selection verb, // do stuff with selection scale, // change draw scaling file, // load/save, file related stuff mode, // change mode }; pub const Action = struct { category: ActionCat, // Only one of these should be set, and only one should be used. function_move: fn (*Vec2, conf.arg_type) movement.SelectionUpdate = movement.move_left, function_verb: fn (*Level, conf.arg_type) void = verbs.delete, function_scale: fn (scaling.scale_type) scaling.scale_type = scaling.scale_reset, function_file: fn (*Level, *std.mem.Allocator, [*:0]const u8) void = Level.action_write, next_mode: Mode = Mode.normal, }; pub const ActionsDef = .{ .none = Action{ .category = ActionCat.none, }, // Movement. // Reset selection. .move_but_dont = Action{ .category = ActionCat.movement, .function_move = movement.move_but_dont, }, // Left. .move_left = Action{ .category = ActionCat.movement, .function_move = movement.move_left, }, // Right. .move_right = Action{ .category = ActionCat.movement, .function_move = movement.move_right, }, // Up. .move_up = Action{ .category = ActionCat.movement, .function_move = movement.move_up, }, // Down. .move_down = Action{ .category = ActionCat.movement, .function_move = movement.move_down, }, // Up-left. .move_up_left = Action{ .category = ActionCat.movement, .function_move = movement.move_up_left, }, // Up-right. .move_up_right = Action{ .category = ActionCat.movement, .function_move = movement.move_up_right, }, // Down-left. .move_down_left = Action{ .category = ActionCat.movement, .function_move = movement.move_down_left, }, // Down-right. .move_down_right = Action{ .category = ActionCat.movement, .function_move = movement.move_down_right, }, // Verbs. .verb_clear_selection = Action{ .category = ActionCat.verb, .function_verb = verbs.clear_selection, }, .verb_delete = Action{ .category = ActionCat.verb, .function_verb = verbs.delete, }, .verb_replace = Action{ .category = ActionCat.verb, .function_verb = verbs.replace, }, // Scale. .scale_reset = Action{ .category = ActionCat.scale, .function_scale = scaling.scale_reset, }, .scale_up = Action{ .category = ActionCat.scale, .function_scale = scaling.scale_up, }, .scale_down = Action{ .category = ActionCat.scale, .function_scale = scaling.scale_down, }, // File .file_read = Action{ .category = ActionCat.file, .function_file = Level.action_read, }, .file_write = Action{ .category = ActionCat.file, .function_file = Level.action_write, }, // Mode change. .mode_normal = Action{ .category = ActionCat.mode, .next_mode = Mode.normal, }, .mode_select = Action{ .category = ActionCat.mode, .next_mode = Mode.select, }, .mode_rectangle = Action{ .category = ActionCat.mode, .next_mode = Mode.rectangle, }, .mode_camera = Action{ .category = ActionCat.mode, .next_mode = Mode.camera, }, };