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:
2026-11-13 11:30:09 -05:00
co-authored by Claude Opus 5.5
parent 386653f782
commit c504551b28
39 changed files with 2022 additions and 50 deletions
+130
View File
@@ -0,0 +1,130 @@
extends TestCase
## A10: settings saved between launches, and corrupt files falling back to defaults.
const PATH: String = "user://test_game_settings.cfg"
func after_each() -> void:
super.after_each()
DirAccess.remove_absolute(ProjectSettings.globalize_path(PATH))
func test_everything_round_trips() -> void:
var settings: GameSettings = GameSettings.new()
settings.mouse.mouse_sensitivity = 2.5
settings.mouse.invert_y = true
assert_eq(settings.bindings.bind("jump", KEY_F), "")
settings.quality = GameSettings.QUALITY_LOW
settings.print_pass = false
settings.master_volume = 0.3
settings.music_volume = 0.0
settings.effects_volume = 0.55
settings.window_mode = 1
settings.vsync = false
settings.max_fps = 144
settings.player_name = " Wren of the Point "
settings.last_server = "example.org:24650"
settings.practice_bots = 7
settings.practice_difficulty = 2
assert_eq(settings.save(PATH), OK)
var loaded: GameSettings = GameSettings.load_from(PATH)
assert_near(loaded.mouse.mouse_sensitivity, 2.5, 0.0001)
assert_true(loaded.mouse.invert_y)
assert_eq(loaded.bindings.code_of("jump"), KEY_F)
assert_eq(loaded.quality, GameSettings.QUALITY_LOW)
assert_false(loaded.print_pass)
assert_near(loaded.master_volume, 0.3, 0.0001)
assert_near(loaded.music_volume, 0.0, 0.0001)
assert_near(loaded.effects_volume, 0.55, 0.0001)
assert_eq(loaded.window_mode, 1)
assert_false(loaded.vsync)
assert_eq(loaded.max_fps, 144)
assert_eq(loaded.player_name, "Wren of the Point")
assert_eq(loaded.last_server, "example.org:24650")
assert_eq(loaded.practice_bots, 7)
assert_eq(loaded.practice_difficulty, 2)
assert_eq(loaded.shadow_distance(), 0.0, "low has no shadows")
func test_a_missing_file_gives_defaults() -> void:
var loaded: GameSettings = GameSettings.load_from("user://no_such_settings.cfg")
_assert_defaults(loaded)
func test_a_corrupt_file_gives_defaults() -> void:
# The engine reports each file it can't parse; that's expected here.
expect_error("ConfigFile parse error")
expect_error("ConfigFile parse error")
for garbage: PackedByteArray in [
"[graphics\nquality=???\n".to_utf8_buffer() + PackedByteArray([0, 1]),
PackedByteArray([0xFF, 0xFE, 0x00, 0x13, 0x37, 0x80, 0x81]),
"quality = 2 = 3 [[[".to_utf8_buffer(),
]:
var file: FileAccess = FileAccess.open(PATH, FileAccess.WRITE)
file.store_buffer(garbage)
file.close()
_assert_defaults(GameSettings.load_from(PATH))
func test_wrong_types_and_ranges_fall_back_value_by_value() -> void:
var config: ConfigFile = ConfigFile.new()
config.set_value("graphics", "quality", 99)
config.set_value("graphics", "print_pass", "yes")
config.set_value("audio", "master", 7.0)
config.set_value("audio", "music", NAN)
config.set_value("audio", "effects", [1, 2])
config.set_value("display", "window_mode", -4)
config.set_value("display", "max_fps", 77)
config.set_value("player", "name", 12)
config.set_value("practice", "bots", 400)
config.set_value("input", "mouse_sensitivity", INF)
config.set_value("keys", "forward", KEY_UP)
assert_eq(config.save(PATH), OK)
var loaded: GameSettings = GameSettings.load_from(PATH)
assert_eq(loaded.quality, GameSettings.QUALITY_HIGH, "clamped to the top preset")
assert_true(loaded.print_pass, "not a bool: the default")
assert_near(loaded.master_volume, 1.0, 0.0001, "clamped")
assert_near(loaded.music_volume, GameSettings.new().music_volume, 0.0001, "NaN: the default")
assert_near(loaded.effects_volume, GameSettings.new().effects_volume, 0.0001)
assert_eq(loaded.window_mode, 0)
assert_eq(loaded.max_fps, 0, "not an offered cap")
assert_eq(loaded.player_name, ClientConfig.DEFAULT_NAME)
assert_eq(loaded.practice_bots, Tuning.SOLO_PLAYERS - 1)
assert_near(loaded.mouse.mouse_sensitivity, 1.0, 0.0001)
assert_eq(loaded.bindings.code_of("forward"), KEY_UP, "the one good value is kept")
func test_old_mouse_only_files_still_load() -> void:
var old: InputSettings = InputSettings.new()
old.mouse_sensitivity = 3.0
assert_eq(old.save(PATH), OK)
var loaded: GameSettings = GameSettings.load_from(PATH)
assert_near(loaded.mouse.mouse_sensitivity, 3.0, 0.0001)
assert_eq(loaded.bindings.code_of("jump"), KEY_SPACE)
func test_applying_settings_sets_the_audio_buses() -> void:
var settings: GameSettings = GameSettings.new()
settings.music_volume = 0.0
settings.effects_volume = 0.5
settings.apply_to_program(null)
var music: int = AudioServer.get_bus_index("Music")
var effects: int = AudioServer.get_bus_index("Effects")
assert_true(music > 0 and effects > 0, "made the buses")
assert_true(AudioServer.is_bus_mute(music))
assert_near(AudioServer.get_bus_volume_db(effects), linear_to_db(0.5), 0.01)
settings.apply_to_program(null)
assert_eq(AudioServer.bus_count, 3, "no extra buses the second time")
func _assert_defaults(loaded: GameSettings) -> void:
var fresh: GameSettings = GameSettings.new()
assert_eq(loaded.quality, fresh.quality)
assert_eq(loaded.print_pass, fresh.print_pass)
assert_eq(loaded.master_volume, fresh.master_volume)
assert_eq(loaded.window_mode, fresh.window_mode)
assert_eq(loaded.player_name, fresh.player_name)
assert_eq(loaded.mouse.mouse_sensitivity, fresh.mouse.mouse_sensitivity)
for action: Dictionary in KeyBindings.ACTIONS:
assert_eq(loaded.bindings.code_of(action["id"]), int(action["default"]))
+1
View File
@@ -0,0 +1 @@
uid://cta4a1dero8fu
+85
View File
@@ -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")
+1
View File
@@ -0,0 +1 @@
uid://d0svqwutsfu5y