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>
131 lines
5.2 KiB
GDScript
131 lines
5.2 KiB
GDScript
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"]))
|