2021-01-30 16:13:06 +01:00
|
|
|
// 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;
|
|
|
|
|
2021-02-25 17:13:12 +01:00
|
|
|
const Parameter = @import("parameter.zig");
|
2021-01-30 16:13:06 +01:00
|
|
|
const movement = @import("movement.zig");
|
2021-01-30 16:43:55 +01:00
|
|
|
const scaling = @import("scaling.zig");
|
2021-01-30 23:59:25 +01:00
|
|
|
const verbs = @import("verbs.zig");
|
2021-01-30 16:13:06 +01:00
|
|
|
const Vec2 = @import("vec2.zig");
|
|
|
|
const Level = @import("level.zig");
|
2021-02-02 14:21:12 +01:00
|
|
|
const Mode = @import("modes.zig").Mode;
|
2021-01-30 16:13:06 +01:00
|
|
|
|
|
|
|
pub const ActionCat = enum {
|
|
|
|
none, // do nothing
|
2021-02-25 17:13:12 +01:00
|
|
|
parameter, // add key to Parameter buffer
|
2021-01-30 16:13:06 +01:00
|
|
|
movement, // move and change selection
|
|
|
|
verb, // do stuff with selection
|
|
|
|
scale, // change draw scaling
|
2021-02-24 15:48:32 +01:00
|
|
|
file, // load/save, file related stuff
|
2021-02-02 14:21:12 +01:00
|
|
|
mode, // change mode
|
2021-01-30 16:13:06 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
pub const Action = struct {
|
|
|
|
category: ActionCat,
|
|
|
|
// Only one of these should be set, and only one should be used.
|
2021-02-25 17:13:12 +01:00
|
|
|
function_parameter: fn (*Parameter, u8) void = Parameter.process_key,
|
|
|
|
function_move: fn (*Vec2, Parameter.buffer_type) movement.SelectionUpdate = movement.move_left,
|
|
|
|
function_verb: fn (*Level, Parameter.buffer_type) void = verbs.delete,
|
|
|
|
function_scale: fn (scaling.scale_type, Parameter.buffer_type) scaling.scale_type = scaling.scale_reset,
|
2021-02-24 23:11:06 +01:00
|
|
|
function_file: fn (*Level, *std.mem.Allocator, [*:0]const u8) void = Level.action_write,
|
2021-02-02 14:21:12 +01:00
|
|
|
next_mode: Mode = Mode.normal,
|
2021-01-30 16:13:06 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
pub const ActionsDef = .{
|
|
|
|
.none = Action{
|
|
|
|
.category = ActionCat.none,
|
|
|
|
},
|
2021-02-25 17:13:12 +01:00
|
|
|
// Parameter/repetition.
|
|
|
|
.parameter = Action{
|
|
|
|
.category = ActionCat.parameter,
|
|
|
|
.function_parameter = Parameter.process_key,
|
|
|
|
},
|
|
|
|
|
2021-01-30 16:13:06 +01:00
|
|
|
// Movement.
|
2021-01-30 23:59:25 +01:00
|
|
|
// Reset selection.
|
|
|
|
.move_but_dont = Action{
|
|
|
|
.category = ActionCat.movement,
|
|
|
|
.function_move = movement.move_but_dont,
|
|
|
|
},
|
2021-01-30 16:13:06 +01:00
|
|
|
// 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,
|
2021-01-30 16:47:49 +01:00
|
|
|
.function_move = movement.move_down_left,
|
2021-01-30 16:13:06 +01:00
|
|
|
},
|
|
|
|
// Down-right.
|
|
|
|
.move_down_right = Action{
|
|
|
|
.category = ActionCat.movement,
|
|
|
|
.function_move = movement.move_down_right,
|
|
|
|
},
|
2021-01-30 16:43:55 +01:00
|
|
|
|
2021-01-30 16:47:49 +01:00
|
|
|
// Verbs.
|
2021-02-02 14:21:12 +01:00
|
|
|
.verb_clear_selection = Action{
|
|
|
|
.category = ActionCat.verb,
|
|
|
|
.function_verb = verbs.clear_selection,
|
|
|
|
},
|
2021-01-30 16:47:49 +01:00
|
|
|
.verb_delete = Action{
|
|
|
|
.category = ActionCat.verb,
|
2021-01-30 23:59:25 +01:00
|
|
|
.function_verb = verbs.delete,
|
|
|
|
},
|
|
|
|
.verb_replace = Action{
|
|
|
|
.category = ActionCat.verb,
|
|
|
|
.function_verb = verbs.replace,
|
2021-01-30 16:47:49 +01:00
|
|
|
},
|
|
|
|
|
2021-01-30 16:43:55 +01:00
|
|
|
// 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,
|
|
|
|
},
|
2021-02-02 14:21:12 +01:00
|
|
|
|
2021-02-24 15:48:32 +01:00
|
|
|
// File
|
|
|
|
.file_read = Action{
|
|
|
|
.category = ActionCat.file,
|
|
|
|
.function_file = Level.action_read,
|
|
|
|
},
|
|
|
|
.file_write = Action{
|
|
|
|
.category = ActionCat.file,
|
|
|
|
.function_file = Level.action_write,
|
|
|
|
},
|
|
|
|
|
2021-02-02 14:21:12 +01:00
|
|
|
// 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,
|
|
|
|
},
|
2021-01-30 16:13:06 +01:00
|
|
|
};
|