Files
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

141 lines
6.5 KiB
GDScript

extends TestCase
## A1: every colour the client draws with comes from Palette (docs/STYLE.md).
## Scripts allowed literal Color() values, and why.
const ALLOWED: Dictionary = {
"res://src/client/style/palette.gd": "the palette itself",
"res://src/client/terrain/terrain_chunk_builder.gd": "splat weights carried in vertex colours, not colours",
}
## A Color() made only of number literals, or a named engine colour other than the
## neutral ones used as multipliers.
const LITERAL: String = "Color\\(\\s*-?[0-9.]+\\s*,\\s*-?[0-9.]+\\s*,\\s*-?[0-9.]+\\s*(,\\s*-?[0-9.]+\\s*)?\\)"
const NAMED: String = "Color\\.(?!WHITE\\b|BLACK\\b|TRANSPARENT\\b)[A-Z_]+\\b|Color8\\(|Color\\.html\\("
func test_client_colours_come_from_the_palette() -> void:
var literal: RegEx = RegEx.create_from_string(LITERAL)
var named: RegEx = RegEx.create_from_string(NAMED)
var paths: Array[String] = _scripts_under("res://src/client")
paths.append_array(_scripts_under("res://src/app"))
paths.append_array(_scripts_under("res://src/ui"))
assert_true(paths.size() > 10, "expected client scripts")
for path: String in paths:
if ALLOWED.has(path):
continue
for line: String in FileAccess.get_file_as_string(path).split("\n"):
var code: String = line.get_slice("#", 0)
if literal.search(code) != null or named.search(code) != null:
fail("%s has a colour outside Palette: %s" % [path, code.strip_edges()])
func test_scanner_catches_literals_and_named_colours() -> void:
var literal: RegEx = RegEx.create_from_string(LITERAL)
var named: RegEx = RegEx.create_from_string(NAMED)
assert_not_null(literal.search("var c: Color = Color(0.5, 0.2, 0.1)"))
assert_not_null(literal.search("Color(1, 0, 0, 0.5)"))
assert_null(literal.search("Color(base.r + shift, 0.0, 1.0)"))
assert_not_null(named.search("x = Color.RED"))
assert_not_null(named.search("Color.html(\"#fff\")"))
assert_null(named.search("tint = Color.WHITE"))
func test_palette_matches_the_style_guide() -> void:
# Each named colour is listed in docs/STYLE.md, so the guide can't fall behind.
var guide: String = FileAccess.get_file_as_string("res://docs/STYLE.md")
assert_true(not guide.is_empty(), "docs/STYLE.md should exist")
var names: PackedStringArray = PackedStringArray()
for constant: String in (Palette as Script).get_script_constant_map():
names.append(constant)
assert_true(names.size() > 20, "expected the palette's colours")
for constant: String in names:
assert_true(guide.contains("`%s`" % constant), "docs/STYLE.md should list `%s`" % constant)
func _scripts_under(dir_path: String) -> Array[String]:
var found: Array[String] = []
for name: String in DirAccess.get_files_at(dir_path):
if name.ends_with(".gd"):
found.append(dir_path.path_join(name))
for name: String in DirAccess.get_directories_at(dir_path):
found.append_array(_scripts_under(dir_path.path_join(name)))
return found
# --- A13: colour vision -------------------------------------------------------------
## Machado, Oliveira and Fernandes (2009), full severity, applied in linear RGB.
const SIMULATE: Dictionary = {
"protan": [[0.152286, 1.052583, -0.204868], [0.114503, 0.786281, 0.099216], [-0.003882, -0.048116, 1.051998]],
"deutan": [[0.367322, 0.860646, -0.227968], [0.280085, 0.672501, 0.047413], [-0.011820, 0.042940, 0.968881]],
"tritan": [[1.255528, -0.076749, -0.178779], [-0.078411, 0.930809, 0.147602], [0.004733, 0.691367, 0.303900]],
}
## Each set, and the colour visions it is for.
const SETS_FOR: Dictionary = {
Palette.VISION_RED_GREEN: ["protan", "deutan"],
Palette.VISION_BLUE_YELLOW: ["tritan"],
}
## How far apart (in Oklab) the two colours of a signal must look.
const APART: float = 0.25
func after_each() -> void:
super.after_each()
Palette.vision = Palette.VISION_STANDARD
static func _seen(colour: Color, vision: String) -> Vector3:
var linear: Color = colour.srgb_to_linear()
var rgb: Array[float] = [linear.r, linear.g, linear.b]
var out: Array[float] = [0.0, 0.0, 0.0]
var matrix: Array = SIMULATE[vision]
for row: int in 3:
for column: int in 3:
out[row] += float(matrix[row][column]) * rgb[column]
var r: float = clampf(out[0], 0.0, 1.0)
var g: float = clampf(out[1], 0.0, 1.0)
var b: float = clampf(out[2], 0.0, 1.0)
var l: float = pow(0.4122214708 * r + 0.5363325363 * g + 0.0514459929 * b, 1.0 / 3.0)
var m: float = pow(0.2119034982 * r + 0.6806995451 * g + 0.1073969566 * b, 1.0 / 3.0)
var s: float = pow(0.0883024619 * r + 0.2817188376 * g + 0.6299787005 * b, 1.0 / 3.0)
return Vector3(0.2104542553 * l + 0.7936177850 * m - 0.0040720468 * s,
1.9779984951 * l - 2.4285922050 * m + 0.4505937099 * s,
0.0259040371 * l + 0.7827717662 * m - 0.8086757660 * s)
static func _apart(a: Color, b: Color, vision: String) -> float:
return _seen(a, vision).distance_to(_seen(b, vision))
func test_each_colour_vision_set_keeps_its_signals_apart_for_those_eyes() -> void:
for vision: int in SETS_FOR:
Palette.vision = vision
for eyes: String in SETS_FOR[vision]:
var ghost: float = _apart(Palette.ghost_ok(), Palette.ghost_refused(), eyes)
var danger: float = _apart(Palette.warning(), Palette.own(), eyes)
assert_true(ghost >= APART, "%s set, %s: allowed and refused %.3f apart" % [Palette.VISION_NAMES[vision], eyes, ghost])
assert_true(danger >= APART, "%s set, %s: danger and own marks %.3f apart" % [Palette.VISION_NAMES[vision], eyes, danger])
func test_the_sets_do_better_than_the_standard_colours_where_they_are_weakest() -> void:
# The standard ghost is hardest for deutan eyes, and danger against your own marks for
# tritan ones; the sets made for them must be clearly better there.
var standard_ghost: float = _apart(Palette.GHOST_OK, Palette.GHOST_REFUSED, "deutan")
var standard_danger: float = _apart(Palette.WARNING, Palette.OILSKIN, "tritan")
assert_true(standard_ghost < APART, "the standard ghost is a real problem for deutan eyes (%.3f)" % standard_ghost)
Palette.vision = Palette.VISION_RED_GREEN
assert_true(_apart(Palette.ghost_ok(), Palette.ghost_refused(), "deutan") > standard_ghost * 1.5)
Palette.vision = Palette.VISION_BLUE_YELLOW
assert_true(_apart(Palette.warning(), Palette.own(), "tritan") > standard_danger * 1.5)
func test_the_standard_set_is_the_documented_colours() -> void:
Palette.vision = Palette.VISION_STANDARD
assert_eq(Palette.ghost_ok(), Palette.GHOST_OK)
assert_eq(Palette.ghost_refused(), Palette.GHOST_REFUSED)
assert_eq(Palette.warning(), Palette.WARNING)
assert_eq(Palette.own(), Palette.OILSKIN)
Palette.vision = 99
assert_eq(Palette.vision, Palette.VISION_BLUE_YELLOW, "clamped")
assert_eq(Palette.VISION_NAMES.size(), Palette.VISION_SIGNALS.size())