Files
tidewall/test/client/test_game_settings.gd
claudeandClaude Opus 5.5 8142e39ab3 A13: Gamepad and accessibility
Gamepad: PadInput reads pad events in one fixed layout (sticks move and
look, triggers aim and fire, bumpers step slots and build pieces, Start
pauses), fed through ClientInput alongside the keys and mouse. Menus take
South to choose and East or Start to go back. The tutorial names pad
buttons once the pad is used.

Aim assist (option, on by default, pad only): friction across an
opponent in plain sight near the look, and a pull of at most 9 deg/s
while aiming. Client look only; never through cover.

Accessibility (new Access tab): colour-vision sets for the signal colours
(red-green, blue-yellow), checked by simulated colour vision in
test_palette; interface size 90-130%, with the HUD hotbar refitting at the
larger sizes; captions for key sounds with direction; reduce motion
(calmer aim zoom and hurt flash).

Tests for the pad, aim assist, captions, palettes, settings, the menus
driven from a pad, and a pad playing through a real offline session.
make access-captures renders the new screens and options.

Closes #53

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-15 08:53:30 -05:00

279 lines
12 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"]))
func test_presets_rise_from_low_to_high() -> void:
var settings: GameSettings = GameSettings.new()
var previous: Dictionary = {}
for quality: int in GameSettings.QUALITY_NAMES.size():
settings.quality = quality
var preset: Dictionary = GameSettings.QUALITY[quality]
assert_true([1, 2, 4].has(settings.shadow_splits()), "%s has 1, 2 or 4 shadow splits" % GameSettings.QUALITY_NAMES[quality])
assert_true(preset["msaa"] == Viewport.MSAA_DISABLED or not preset["fxaa"], "no preset pays for both MSAA and FXAA")
if not previous.is_empty():
assert_true(float(preset["shadow_distance"]) >= float(previous["shadow_distance"]))
assert_true(int(preset["shadow_splits"]) >= int(previous["shadow_splits"]))
assert_true(float(preset["render_scale"]) >= float(previous["render_scale"]))
previous = preset
settings.quality = GameSettings.QUALITY_HIGH
assert_eq(settings.shadow_splits(), 4)
func test_a_preset_sets_the_viewport_and_the_sun() -> void:
var viewport: SubViewport = SubViewport.new()
var settings: GameSettings = GameSettings.new()
settings.quality = GameSettings.QUALITY_LOW
settings.apply_to_viewport(viewport)
assert_near(viewport.scaling_3d_scale, 0.75, 0.001)
assert_eq(viewport.msaa_3d, Viewport.MSAA_DISABLED)
assert_eq(viewport.screen_space_aa, Viewport.SCREEN_SPACE_AA_FXAA)
settings.quality = GameSettings.QUALITY_HIGH
settings.apply_to_viewport(viewport)
assert_near(viewport.scaling_3d_scale, 1.0, 0.001)
assert_eq(viewport.msaa_3d, Viewport.MSAA_2X)
assert_eq(viewport.screen_space_aa, Viewport.SCREEN_SPACE_AA_DISABLED)
viewport.free()
var view: MatchView = MatchView.new()
view.sun = Look.sun()
view.add_child(view.sun)
settings.quality = GameSettings.QUALITY_MEDIUM
view.apply_settings(settings)
assert_true(view.sun.shadow_enabled)
assert_eq(view.sun.directional_shadow_mode, DirectionalLight3D.SHADOW_PARALLEL_2_SPLITS)
settings.quality = GameSettings.QUALITY_LOW
view.apply_settings(settings)
assert_false(view.sun.shadow_enabled, "low has no shadows")
view.free()
func test_no_sun_shadows_under_the_opengl_fallback() -> void:
# H14: Compatibility adds a shadowed sun's pass in sRGB, which washes out sunlit
# ground, so the sun casts no shadows there whatever the preset.
assert_true(Look.sun_shadows_supported("forward_plus"))
assert_true(Look.sun_shadows_supported("mobile"))
assert_false(Look.sun_shadows_supported("gl_compatibility"))
var expected: bool = Look.sun_shadows_supported()
var sun: DirectionalLight3D = Look.sun()
assert_eq(sun.shadow_enabled, expected, "Look.sun follows the renderer")
sun.free()
var view: MatchView = MatchView.new()
view.sun = Look.sun()
view.add_child(view.sun)
var settings: GameSettings = GameSettings.new()
settings.quality = GameSettings.QUALITY_HIGH
view.apply_settings(settings)
assert_eq(view.sun.shadow_enabled, expected, "presets don't turn them back on")
view.free()
func test_presets_never_change_how_far_cover_is_drawn() -> void:
# A lower preset must never let a player see through trees and rocks it stopped
# drawing: nothing about props is in the presets.
for preset: Dictionary in GameSettings.QUALITY:
for key: String in preset:
assert_false(key.contains("range") or key.contains("detail") or (key.contains("distance") and key != "shadow_distance"), "preset key %s" % key)
func test_renderer_fallback_notice() -> void:
var none: PackedStringArray = PackedStringArray()
assert_eq(RendererCheck.notice_for("forward_plus", "forward_plus", none), "", "the renderer asked for")
assert_eq(RendererCheck.notice_for("forward_plus", "gl_compatibility", none), RendererCheck.NOTICE, "fell back to OpenGL")
assert_eq(RendererCheck.notice_for("forward_plus", "gl_compatibility", PackedStringArray(["--rendering-method", "gl_compatibility"])), "", "the player chose OpenGL")
assert_eq(RendererCheck.notice_for("forward_plus", "gl_compatibility", PackedStringArray(["--rendering-driver=opengl3"])), "", "the player chose OpenGL")
assert_eq(RendererCheck.fallback_notice(), "", "nothing to say headless")
func test_gamepad_and_accessibility_round_trip_and_fall_back() -> void:
var settings: GameSettings = GameSettings.new()
assert_true(settings.mouse.aim_assist, "aim assist starts on")
assert_false(settings.captions)
assert_false(settings.reduce_motion)
settings.mouse.pad_sensitivity = 1.75
settings.mouse.aim_assist = false
settings.vision = Palette.VISION_RED_GREEN
settings.ui_scale = 1.15
settings.captions = true
settings.reduce_motion = true
assert_eq(settings.save(PATH), OK)
var loaded: GameSettings = GameSettings.load_from(PATH)
assert_near(loaded.mouse.pad_sensitivity, 1.75, 0.0001)
assert_false(loaded.mouse.aim_assist)
assert_eq(loaded.vision, Palette.VISION_RED_GREEN)
assert_eq(loaded.ui_scale, 1.15)
assert_true(loaded.captions)
assert_true(loaded.reduce_motion)
var config: ConfigFile = ConfigFile.new()
config.set_value("access", "vision", 42)
config.set_value("access", "ui_scale", 7.0)
config.set_value("access", "captions", "yes")
config.set_value("input", "pad_sensitivity", 99.0)
config.set_value("input", "aim_assist", 3)
config.save(PATH)
loaded = GameSettings.load_from(PATH)
assert_eq(loaded.vision, Palette.VISION_NAMES.size() - 1, "clamped")
assert_eq(loaded.ui_scale, 1.0, "a scale not offered is the default")
assert_false(loaded.captions)
assert_near(loaded.mouse.pad_sensitivity, InputSettings.MAX_PAD_SENSITIVITY, 0.0001)
assert_true(loaded.mouse.aim_assist)
func test_applying_sets_the_colour_vision_and_interface_size() -> void:
var tree: SceneTree = Engine.get_main_loop() as SceneTree
var settings: GameSettings = GameSettings.new()
settings.vision = Palette.VISION_BLUE_YELLOW
settings.ui_scale = 1.3
settings.apply_to_program(tree)
assert_eq(Palette.vision, Palette.VISION_BLUE_YELLOW)
assert_near(tree.root.content_scale_factor, 1.3, 0.0001)
GameSettings.new().apply_to_program(tree)
assert_eq(Palette.vision, Palette.VISION_STANDARD)
assert_near(tree.root.content_scale_factor, 1.0, 0.0001)
func test_reduce_motion_calms_the_aim_zoom() -> void:
var rig: CameraRig = CameraRig.new()
rig.update_aim(true, 0.1)
var quick: float = rig.aim_blend
rig.aim_blend = 1.0
var full_zoom: float = rig.fov()
var calm: CameraRig = CameraRig.new()
calm.reduce_motion = true
calm.update_aim(true, 0.1)
assert_true(calm.aim_blend < quick, "eases in more slowly")
calm.aim_blend = 1.0
assert_true(calm.fov() > full_zoom + 10.0, "zooms in less: %.0f against %.0f" % [calm.fov(), full_zoom])
var view: MatchView = MatchView.new()
var settings: GameSettings = GameSettings.new()
settings.reduce_motion = true
view.apply_settings(settings)
assert_true(view.rig.reduce_motion)
view.free()