A10: Menus and settings
The game now opens on a main menu when it has a window: practice against bots (count and skill), join a server (by address, or from a LAN search list), settings, and quit. In a match, Escape brings up a pause menu (the match goes on) with settings and leave; when a match the player was in ends, a results screen shows their place, eliminations and the last of the feed. - KeyBindings: every action rebindable to a key or mouse button. bind() refuses an input another action uses and names it; Escape is reserved. ClientInput reads keys through the bindings. - GameSettings: bindings, mouse, graphics (quality preset and the print pass), audio (master, music and effects buses), display (window mode, vsync, frame cap), name, last server and practice choices, saved in user://settings.cfg. Missing, unreadable or corrupt files and bad values fall back to defaults, value by value; hand-edited key clashes are repaired on load. - Menus (src/ui): paper-and-ink panels, brass focus edge, keyboard navigable; a drawn sea-and-tide-post backdrop, or an ink wash over a match. AppShell runs menus and the session. - LocalServer takes a bot difficulty. - make menu-captures renders every screen. Closes #50 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,85 @@
|
||||
extends TestCase
|
||||
|
||||
## A10: key bindings, rebinding and conflicts.
|
||||
|
||||
|
||||
func test_defaults_are_the_documented_keys_and_none_clash() -> void:
|
||||
var bindings: KeyBindings = KeyBindings.new()
|
||||
assert_eq(bindings.code_of("forward"), KEY_W)
|
||||
assert_eq(bindings.code_of("build"), KEY_B)
|
||||
assert_eq(bindings.code_of("fire"), -MOUSE_BUTTON_LEFT)
|
||||
assert_eq(bindings.code_of("slot_0"), KEY_1)
|
||||
assert_eq(bindings.conflicts(), [] as Array[String])
|
||||
for action: Dictionary in KeyBindings.ACTIONS:
|
||||
assert_true(KeyBindings.is_valid_code(int(action["default"])), String(action["id"]))
|
||||
|
||||
|
||||
func test_rebinding_to_a_free_key_works() -> void:
|
||||
var bindings: KeyBindings = KeyBindings.new()
|
||||
assert_eq(bindings.bind("jump", KEY_F), "")
|
||||
assert_eq(bindings.code_of("jump"), KEY_F)
|
||||
assert_eq(bindings.bind("aim", -MOUSE_BUTTON_MIDDLE), "")
|
||||
assert_eq(bindings.action_using(-MOUSE_BUTTON_MIDDLE), "aim")
|
||||
|
||||
|
||||
func test_rebinding_to_a_used_key_is_refused_and_names_the_clash() -> void:
|
||||
var bindings: KeyBindings = KeyBindings.new()
|
||||
assert_eq(bindings.bind("jump", KEY_W), "forward")
|
||||
assert_eq(bindings.code_of("jump"), KEY_SPACE, "unchanged")
|
||||
assert_eq(bindings.bind("aim", -MOUSE_BUTTON_LEFT), "fire")
|
||||
# Binding an action to the key it already has is no clash.
|
||||
assert_eq(bindings.bind("forward", KEY_W), "")
|
||||
|
||||
|
||||
func test_escape_wheel_and_nonsense_cannot_be_bound() -> void:
|
||||
var bindings: KeyBindings = KeyBindings.new()
|
||||
assert_eq(bindings.bind("jump", KEY_ESCAPE), "reserved")
|
||||
assert_eq(bindings.bind("jump", -MOUSE_BUTTON_WHEEL_UP), "not an input")
|
||||
assert_eq(bindings.bind("jump", 0), "not an input")
|
||||
assert_eq(bindings.bind("fly", KEY_F), "unknown action")
|
||||
|
||||
|
||||
func test_a_hand_edited_clash_is_repaired_on_load() -> void:
|
||||
var config: ConfigFile = ConfigFile.new()
|
||||
config.set_value("keys", "jump", KEY_W)
|
||||
config.set_value("keys", "sprint", "shift")
|
||||
config.set_value("keys", "reload", KEY_ESCAPE)
|
||||
var bindings: KeyBindings = KeyBindings.read(config)
|
||||
assert_eq(bindings.code_of("forward"), KEY_W, "the first in the list keeps it")
|
||||
assert_eq(bindings.code_of("jump"), KEY_SPACE, "the clashing one goes back to its default")
|
||||
assert_eq(bindings.code_of("sprint"), KEY_SHIFT)
|
||||
assert_eq(bindings.code_of("reload"), KEY_R)
|
||||
assert_eq(bindings.conflicts(), [] as Array[String])
|
||||
|
||||
|
||||
func test_events_find_their_action() -> void:
|
||||
var bindings: KeyBindings = KeyBindings.new()
|
||||
var key: InputEventKey = InputEventKey.new()
|
||||
key.physical_keycode = KEY_B
|
||||
key.pressed = true
|
||||
assert_eq(bindings.action_for_event(key), "build")
|
||||
key.echo = true
|
||||
assert_eq(bindings.action_for_event(key), "", "a held key's repeats don't act")
|
||||
var click: InputEventMouseButton = InputEventMouseButton.new()
|
||||
click.button_index = MOUSE_BUTTON_RIGHT
|
||||
click.pressed = true
|
||||
assert_eq(bindings.action_for_event(click), "aim")
|
||||
|
||||
|
||||
func test_client_input_follows_rebound_keys() -> void:
|
||||
var input: ClientInput = ClientInput.new()
|
||||
assert_eq(input.bindings.bind("build", KEY_Q), "")
|
||||
var key: InputEventKey = InputEventKey.new()
|
||||
key.physical_keycode = KEY_Q
|
||||
key.pressed = true
|
||||
input.handle(key, true)
|
||||
assert_true(input.build_mode, "Q now toggles build mode")
|
||||
key.physical_keycode = KEY_B
|
||||
input.handle(key, true)
|
||||
assert_true(input.build_mode, "B no longer does")
|
||||
|
||||
|
||||
func test_describe_names_keys_and_buttons() -> void:
|
||||
assert_eq(KeyBindings.describe(KEY_W), "W")
|
||||
assert_eq(KeyBindings.describe(-MOUSE_BUTTON_LEFT), "Left mouse")
|
||||
assert_eq(KeyBindings.describe(0), "None")
|
||||
Reference in New Issue
Block a user