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>
This commit is contained in:
2026-11-15 08:53:30 -05:00
co-authored by Claude Opus 5.5
parent dbe1ef923a
commit 8142e39ab3
48 changed files with 1627 additions and 49 deletions
+1
View File
@@ -41,6 +41,7 @@ continuity.
| `tools/godot.sh -- --connect=HOST:PORT --autoplay --client-seconds=N` | Runs the client headless against a server for N seconds, played by its script, and prints one JSON line saying how far it got. `--offline` plays a server in the same process instead. On a real display, with no options, the game opens on its main menu (`AppShell`); see `src/app/client_config.gd`. |
| `make tutorial-check` | A12: the tutorial's scripted player (`TutorialPilot`) plays it from the barge to the end on 12 seeds through a real `ClientSession` and its offline server (about 40 s). `TUTORIAL_SEEDS`, `TUTORIAL_FIRST` change the seeds. `tidewall --tutorial --autoplay` does the same in one process in real time. |
| `make tutorial-captures` | Renders the tutorial's card at the move, build and tide steps and the first-launch welcome (`captures/tutorial_*.png`, `menu_welcome.png`, about 2 min). Needs Docker. Look at them. |
| `make access-captures` | A13: renders the Gamepad and Access settings tabs, the menus and HUD at 130%, the build ghost allowed and refused in the red-green colour set, captions on the HUD, and the aim zoom with and without reduce motion (`captures/access_*.png`, about 6 min). Needs Docker. Look at them. Gamepad and accessibility tests are in `test/client/test_pad_input.gd`, `test_aim_assist.gd`, `test_captions.gd`, `test/ui/test_menus.gd` and `test/project/test_palette.gd`. |
| `make client-check` | Starts a server and a client as two processes, joins them over loopback UDP and checks the client plays (about a minute, real time). |
| `tools/godot.sh -- --list-server [--port=N]` | Runs a list server (default UDP port 24660). Game servers started with `--listen --list=HOST[:PORT] --name=NAME` register with it; see `src/server/list_server.gd`. |
| `tools/godot.sh -- --browse [--list=HOST[:PORT]] [--lan-target=IP] [--lan-port=N]` | Looks for servers on the LAN and in list servers and prints them as one JSON line. The join menu (A10) shows the same list. |
+7 -1
View File
@@ -1,7 +1,7 @@
# Tidewall build entry points. Everything runs headless with the repo-local engine.
GODOT := tools/godot.sh
.PHONY: tutorial-check tutorial-captures qa-captures effects-captures app-icon deb deb-check bench dist dist-check build-captures poi-captures art figure figure-captures sea-captures models item-captures audio audio-check check import parse test test-selfcheck smoke capture-test terrain-capture binaries verify-engine balance bot-matches duo-matches bot-builds match match-captures client-check client-captures hud-captures style-captures menu-captures chart-captures discovery-check fuzz stability soak soak-selfcheck server-package-check
.PHONY: access-captures tutorial-check tutorial-captures qa-captures effects-captures app-icon deb deb-check bench dist dist-check build-captures poi-captures art figure figure-captures sea-captures models item-captures audio audio-check check import parse test test-selfcheck smoke capture-test terrain-capture binaries verify-engine balance bot-matches duo-matches bot-builds match match-captures client-check client-captures hud-captures style-captures menu-captures chart-captures discovery-check fuzz stability soak soak-selfcheck server-package-check
## A8: regenerates every sound in assets/audio/ from tools/audio/ (about 6 s).
audio: import
@@ -175,6 +175,12 @@ hud-captures: import
@CAPTURE_SIZE=1280x720 tools/capture.sh client_hud_downed captures/hud_downed_720.png
@CAPTURE_SIZE=3840x2160 tools/capture.sh client_hud captures/hud_2160.png
## A13: the Gamepad and Access settings, the menus and HUD at 130%, the build ghost in
## the red-green set, captions on the HUD, and the aim zoom with and without reduce
## motion (captures/access_*.png, about 6 min). Needs Docker. Look at them.
access-captures: import
@for scene in menu_settings_gamepad menu_settings_access menu_main_large menu_settings_large client_build_red_green client_build_refused_red_green client_hud_captions client_hud_large camera_aim camera_aim_calm; do CAPTURE_SIZE=1280x720 tools/capture.sh $$scene captures/access_$$scene.png; done
## A10: every menu screen (captures/menu_*.png, about 5 min). Needs Docker. Look at them.
menu-captures: import
@for scene in menu_welcome menu_main menu_practice menu_join menu_settings menu_settings_mouse menu_pause menu_results; do tools/capture.sh $$scene captures/$$scene.png; done
+1 -1
View File
@@ -30,7 +30,7 @@ All of this is checked headless or with **software rendering in a container**. N
- **The 1.0.0 packages are solo only.** Duos with downs and revives ([#30](https://gitea.eom.dev/claude/tidewall/issues/30)) are on `main` since 1.0.0 was tagged: `--team-size=2` on a server, `--duos` or the Practice menu's Crew offline. Bots play as teammates and revive, but don't otherwise stick together.
- Bots carry powder kegs but don't throw them ([#83](https://gitea.eom.dev/claude/tidewall/issues/83)).
- Most bots fall early in a match ([#74](https://gitea.eom.dev/claude/tidewall/issues/74)). Bots build on `main` since 1.0.0 was tagged ([#29](https://gitea.eom.dev/claude/tidewall/issues/29)), but only cover walls, ramps and a last-stand ring of breakwaters, not forts. The 1.0.0 packages have bots that don't build.
- **No gamepad support or tutorial** ([#53](https://gitea.eom.dev/claude/tidewall/issues/53), [#52](https://gitea.eom.dev/claude/tidewall/issues/52)). No character customization ([#43](https://gitea.eom.dev/claude/tidewall/issues/43)) or editing of placed pieces ([#18](https://gitea.eom.dev/claude/tidewall/issues/18)).
- **The 1.0.0 packages have no gamepad support, accessibility options or tutorial.** All three are on `main` since 1.0.0 was tagged ([#53](https://gitea.eom.dev/claude/tidewall/issues/53), [#52](https://gitea.eom.dev/claude/tidewall/issues/52)); the gamepad has only been tested with simulated input. No character customization ([#43](https://gitea.eom.dev/claude/tidewall/issues/43)) or editing of placed pieces ([#18](https://gitea.eom.dev/claude/tidewall/issues/18)).
- **The Join menu only searches the LAN** ([#82](https://gitea.eom.dev/claude/tidewall/issues/82)). List servers work from the command line (`--browse --list=...`); in the menu, join other servers by address.
- Under OpenGL (the fallback when Vulkan can't start) the sun casts no shadows, because that renderer drew them with washed-out colours ([#81](https://gitea.eom.dev/claude/tidewall/issues/81)).
- One network soak saw a single transient world-hash mismatch that hasn't been reproduced since ([#80](https://gitea.eom.dev/claude/tidewall/issues/80)).
+55 -2
View File
@@ -80,7 +80,7 @@ practice. Crewmates can't hurt each other, with any weapon or keg.
## Controls
Every key can be rebound in Settings → Controls. Mouse sensitivity and inversion are on
the Mouse tab. Escape opens the pause menu and can't be rebound. Keys are matched by
the Mouse tab. A gamepad works too (below). Escape opens the pause menu and can't be rebound. Keys are matched by
position, so they sit in the same place on any keyboard layout.
| Action | Default |
@@ -101,7 +101,60 @@ position, so they sit in the same place on any keyboard layout.
| In build mode: next material | Tab |
| Chart (the full map) | M |
Gamepads aren't supported in this release.
### Gamepad
A gamepad works alongside the keyboard and mouse, with one fixed layout (listed in
Settings → Gamepad). Buttons are named by position, so they sit the same on any pad:
South is A on most pads.
| Action | Gamepad |
|---|---|
| Move | Left stick |
| Look | Right stick |
| Sprint (until you stop) | Click the left stick |
| Jump, leap, open the wing-sail | South (A) |
| Crouch, dive | East (B) |
| Reload | West (X) |
| Pick up or open a chest | North (Y) |
| Use, fire, harvest or place | Right trigger |
| Aim | Left trigger |
| Next / previous slot, or piece in build mode | Right / left bumper |
| Build mode on and off | Click the right stick |
| In build mode: next / previous material | D-pad right / left |
| Chart | D-pad up |
| Drop the held item | D-pad down |
| Pause menu | Start |
In the menus the D-pad or the left stick moves between controls, South chooses and East
or Start goes back. Settings → Gamepad sets the stick's look speed and turns **aim
assist** on or off (on by default). Aim assist only works with the stick, never the
mouse, and only on an opponent in plain sight close to where you already look: the
stick turns more slowly across them, and while aiming the view eases towards them, by
at most 9° a second. It moves your view only, as your thumb would; the server judges
every shot the same way. Speed while aiming and Invert on the Mouse tab apply to the
stick too. The tutorial names pad buttons once you use the pad.
Gamepads were tested with simulated input only; no physical pad has been tried yet.
## Accessibility
Settings → Access:
- **Colour vision.** Standard, Red-green (protan, deutan) or Blue-yellow (tritan).
Changes the build preview's allowed and refused colours, danger marks (the tide's
next line, low health, "not enough") and your own marks (the tide gauge pointer, your
lines in the feed) to colours that stay apart for that kind of colour blindness.
Nothing in the HUD relies on colour alone in any set: there are words, numbers and
patterns too.
- **Interface size.** 90%, 100%, 115% or 130%: menus and HUD drawn larger or smaller.
At the larger sizes the hotbar moves beside the health panel and its slots narrow.
- **Captions for sounds.** Names the sounds that matter, and which way they came from
(ahead, left, right, behind): the tide's foghorn, bell, surges and lighthouse,
gunfire, shots striking someone, keg blasts, footsteps within 20 m, building and
breaking, splashes, and being hit. Your own sounds aren't captioned.
- **Reduce motion.** Aiming zooms in less (62° rather than 48° of view) and more
slowly, and the flash at the screen's edge when you're hurt is gentler. Tidewall has
no camera shake or head bob.
## How a match goes
+21
View File
@@ -87,6 +87,27 @@ or `src/app`, and on any palette colour this table doesn't list. Values are sRGB
| `WARNING` | 0.86, 0.32, 0.22 | HUD danger: the tide's next line, low health |
| `SEA_INK` | 0.20, 0.34, 0.42 | The sea on the tide gauge and map |
### Colour vision (A13)
The signals above are the `Standard` set. Red against green (the build ghost) and rust
against oilskin yellow (danger beside the player's own marks) are hard to tell apart
for many players, so the Access settings offer a set for each common kind of colour
blindness (`VISION_NAMES`: `VISION_STANDARD`, `VISION_RED_GREEN`, `VISION_BLUE_YELLOW`).
Everything that signals asks `Palette.ghost_ok()`, `ghost_refused()`, `warning()` and
`own()` for its colour, which read `VISION_SIGNALS` for the set in use.
| Set | Allowed | Refused | Danger | Own marks |
|---|---|---|---|---|
| Standard | `GHOST_OK` | `GHOST_REFUSED` | `WARNING` | `OILSKIN` |
| Red-green (protan, deutan) | blue 0.22, 0.52, 0.95 | orange 0.98, 0.56, 0.08 | magenta 0.78, 0.16, 0.62 | `OILSKIN` |
| Blue-yellow (tritan) | teal 0.16, 0.70, 0.74 | vermilion 0.90, 0.16, 0.20 | red 0.88, 0.14, 0.18 | pale blue 0.62, 0.86, 0.98 |
`test_palette` checks each set with a simulation of the colour vision it is for
(Machado, Oliveira and Fernandes 2009, at full severity): each pair must be at least
0.25 apart in Oklab, and clearly further apart than the standard colours where those
are weakest (the standard ghost is only 0.18 apart for deutan eyes). Simulations are a
guide, not a substitute for asking players with colour blindness.
The terrain shader's sand, marsh, grass, rock and summit colours are shader uniforms
and follow the same rules. The sea shader's colours are set from the `SEA_` entries
above by `WaterView`. Water goes from `SEA_SHALLOW` to `SEA_DEEP` with its depth and
+6 -2
View File
@@ -1,4 +1,4 @@
.TH TIDEWALL 6 "2026-11-14" "Tidewall" "Games"
.TH TIDEWALL 6 "2026-11-15" "Tidewall" "Games"
.SH NAME
tidewall \- build-and-survive battle royale on a drowning island
.SH SYNOPSIS
@@ -14,6 +14,10 @@ server on the local network, or join one by address. The sea rises in phases
and swallows the low ground; gather salvage, build, and be the last one
standing.
.PP
Play with the keyboard and mouse or a gamepad. Keys, the gamepad layout, aim assist,
colour vision, interface size, captions for sounds and reduced motion are in the
Settings menu; the player guide, docs/PLAY.md in the source, has the details.
.PP
The game's own options below may be given on their own or after
.BR \-\- ;
any other option goes to the Godot engine.
@@ -41,7 +45,7 @@ building, firing and the tide, using your own key bindings.
.SH FILES
.TP
.I ~/.local/share/godot/app_userdata/Tidewall/
Settings and key bindings.
Settings, key bindings and accessibility options.
.SH SEE ALSO
.BR tidewall\-server (6)
.PP
+49 -5
View File
@@ -46,6 +46,10 @@ var _status: Label = null
var _fx_seen: int = 0
## The hit marker and hurt flash (A7).
var feedback: HitFeedback = HitFeedback.new()
## Captions for key sounds (A13), shown when the setting is on.
var captions: Captions = Captions.new()
## How strong the hurt flash is with reduce motion on (A13).
const CALM_HURT: float = 0.35
## The tutorial (A12), when this session is one, its card on the HUD, and the script
## that plays it when nobody is at the keyboard (`input.autoplay`).
var tutorial: Tutorial = null
@@ -123,11 +127,14 @@ func status_text() -> String:
func pump(delta: float) -> void:
frames += 1
if paused:
# Nothing held while a menu is up, so the player stops rather than runs on.
# Nothing held while a menu is up, so the player stops rather than runs on. The
# pad's events go to the menu meanwhile, so forget what it held.
input.move = Vector2.ZERO
input.buttons = 0
input.pad.release()
else:
input.poll()
_aim_targets()
input.poll(delta)
if link != null:
game.poll()
if local != null:
@@ -181,24 +188,37 @@ func _process(delta: float) -> void:
sound.rain = view.weather.weather.rain()
sound.gale = view.weather.weather.wind()
sound.update(game, mirror.own_id, view.camera.global_position if view != null else Vector3.ZERO, delta)
_hear_captions(delta)
if _status != null:
_status.text = status_text()
if hud != null:
var state: HudState = hud_state()
feedback.update(state.health if state.playing else -1, delta)
state.hit = feedback.hit()
state.hurt = feedback.hurt()
state.hurt = feedback.hurt() * (CALM_HURT if settings.reduce_motion else 1.0)
hud.show_state(state)
if tutorial_card != null:
tutorial_card.show_tutorial(tutorial, game.playing())
_show_charts(delta)
## Passes this frame's sounds to the captions, heard from the camera.
func _hear_captions(delta: float) -> void:
if not settings.captions or view == null:
captions.clear()
return
var forward: Vector3 = -view.camera.global_transform.basis.z
var own: Vector3 = game.own_position() if game.playing() else Vector3.INF
captions.hear(sound.cues, view.camera.global_position, atan2(forward.x, forward.z), own, delta)
## What the HUD should show now.
func hud_state() -> HudState:
var state: HudState = HudState.from_client(game, input, own_handle())
state.hit = feedback.hit()
state.hurt = feedback.hurt()
state.hurt = feedback.hurt() * (CALM_HURT if settings.reduce_motion else 1.0)
if settings.captions:
state.captions = captions.lines()
return state
@@ -206,7 +226,9 @@ func _unhandled_input(event: InputEvent) -> void:
var captured: bool = Input.mouse_mode == Input.MOUSE_MODE_CAPTURED
var key: InputEventKey = event as InputEventKey
var click: InputEventMouseButton = event as InputEventMouseButton
if key != null and key.pressed and not key.echo and key.physical_keycode == KEY_ESCAPE:
var pad: InputEventJoypadButton = event as InputEventJoypadButton
var start: bool = pad != null and pad.pressed and pad.button_index == JOY_BUTTON_START
if start or (key != null and key.pressed and not key.echo and key.physical_keycode == KEY_ESCAPE):
# Escape lets go of the mouse and asks for the pause menu; a click takes the
# mouse back when there is no menu.
Input.mouse_mode = Input.MOUSE_MODE_VISIBLE
@@ -222,6 +244,28 @@ func _exit_tree() -> void:
leave()
## Gives aim assist (A13) the camera and the chests of the opponents in the world:
## players still in, not downed, and not on the player's own team. Only gathered when
## the gamepad is in use and the setting is on.
func _aim_targets() -> void:
input.targets.clear()
if not (input.pad.active and input.settings.aim_assist and game.playing() and view != null and game.world != null):
return
var world: Simulation = game.world
var me: SimEntity = world.entities.find(mirror.own_id)
if me == null:
return
input.eye = view.camera.global_position if view.camera.is_inside_tree() else view.camera.position
if not input.clear.is_valid():
input.clear = func(from: Vector3, to: Vector3) -> bool: return game.world != null and game.world.ground.raycast(from, to) >= 1.0
for entity: SimEntity in world.entities.entities():
if entity.archetype != SimEntity.ARCHETYPE_PLAYER or entity.id == me.id or entity.eliminated or entity.downed:
continue
if world.are_teammates(me, entity) or entity.drop_state != Drop.NONE:
continue
input.targets.append(entity.position + Vector3(0.0, Movement.body_height(entity) * 0.7, 0.0))
func _sample(tick: int) -> PlayerCommand:
if pilot != null:
return pilot.command(tick, game)
+19 -5
View File
@@ -38,6 +38,8 @@ var step: int = LEAP
## Seconds spent on each step, by index, for the scripted check's report.
var step_seconds: PackedFloat32Array = PackedFloat32Array()
var bindings: KeyBindings = KeyBindings.new()
## True while the player is using a gamepad: prompts name its buttons (A13).
var pad: bool = false
var _landed_at: Vector3 = Vector3.ZERO
var _walked: float = 0.0
@@ -67,6 +69,7 @@ func step_name() -> String:
## Looks at the match as this client sees it, once a frame, and moves on when the
## step is done. `input` says whether the chart is open.
func update(game: ClientGame, input: ClientInput, delta: float) -> void:
pad = input.pad.active
step_seconds[step] += delta
var fresh: Array[Dictionary] = _fresh_fx(game)
if step == DONE or not game.playing():
@@ -131,11 +134,11 @@ func instruction() -> String:
LEAP:
return "You're aboard the barge, high over the island. When it's over land, press %s to leap." % _key("jump")
GLIDE:
return "Steer with %s %s %s %s as you fall. Press %s to open your sail, or it opens by itself near the ground. Aim for open ground." % [
_key("forward"), _key("left"), _key("back"), _key("right"), _key("jump")]
return "Steer with %s as you fall. Press %s to open your sail, or it opens by itself near the ground. Aim for open ground." % [
_moves(), _key("jump")]
MOVE:
return "Walk with %s %s %s %s and look with the mouse. Hold %s to sprint, press %s to jump." % [
_key("forward"), _key("left"), _key("back"), _key("right"), _key("sprint"), _key("jump")]
return "Walk with %s and look with the %s. %s to sprint, press %s to jump." % [
_moves(), "right stick" if pad else "mouse", ("Click %s" if pad else "Hold %s") % _key("sprint"), _key("jump")]
HARVEST:
return "Press %s for the boathook. Walk up to driftwood, a rock or scrap and press %s to cut it." % [_key("slot_0"), _key("fire")]
BUILD:
@@ -147,7 +150,7 @@ func instruction() -> String:
TIDE:
return "The sea rises in stages and drowns whoever it catches. Press %s to open the chart and see the tide's next line, then climb above where it will reach after that." % _key("map")
_:
return "That's the whole of it. Others carry weapons too, and chests and crates hold more (%s opens and picks up). Press Escape and leave when you're ready, or stay and look around." % _key("interact")
return "That's the whole of it. Others carry weapons too, and chests and crates hold more (%s opens and picks up). Press %s and leave when you're ready, or stay and look around." % [_key("interact"), _key("pause")]
## How far along the step is, or "" when there is nothing to count.
@@ -177,9 +180,20 @@ func _advance() -> void:
func _key(action: String) -> String:
if pad:
return "[%s]" % PadInput.describe(action)
if action == "pause":
return "[Escape]"
return "[%s]" % KeyBindings.describe(bindings.code_of(action))
## The movement keys, or the stick.
func _moves() -> String:
if pad:
return _key("forward")
return "%s %s %s %s" % [_key("forward"), _key("left"), _key("back"), _key("right")]
func _fresh_fx(game: ClientGame) -> Array[Dictionary]:
var fresh: int = mini(game.fx_received - _fx_seen, game.fx.size())
_fx_seen = game.fx_received
+68
View File
@@ -0,0 +1,68 @@
## Aim assist for the gamepad (A13), an option, on by default, and never applied to the
## mouse. Two gentle effects, both only for an opponent in plain sight close to where
## the player is already looking:
##
## - Friction: the right stick turns more slowly across an opponent, so a stick can
## settle on them instead of sliding past.
## - Pull: while aiming down sights and moving (the stick or the player), the look
## eases towards the opponent's chest, by no more than PULL_RADIANS_PER_SECOND.
##
## It only turns the client's look, the same as a player's own thumb, so it changes
## nothing the server judges. It never aims through cover: `clear` decides what is
## in sight, and the session passes the world's own line test.
class_name AimAssist
extends RefCounted
## How far either side of the look an opponent can be and still count.
const CONE_RADIANS: float = deg_to_rad(6.0)
## Further than this, nobody counts.
const RANGE_METRES: float = 90.0
## Look speed at the very centre of an opponent, against 1 away from them.
const FRICTION: float = 0.45
## The fastest the pull turns the look.
const PULL_RADIANS_PER_SECOND: float = deg_to_rad(9.0)
## The opponent nearest the look within the cone: {"point", "angle"}, or {} for none.
## `clear` takes (eye, point) and returns true when nothing is between them.
static func nearest(eye: Vector3, yaw: float, pitch: float, targets: Array[Vector3], clear: Callable = Callable()) -> Dictionary:
var look: Vector3 = CameraRig.look_direction(yaw, pitch)
var best: Dictionary = {}
var best_angle: float = CONE_RADIANS
for point: Vector3 in targets:
var to: Vector3 = point - eye
var distance: float = to.length()
if distance < 0.5 or distance > RANGE_METRES:
continue
var angle: float = look.angle_to(to / distance)
if angle >= best_angle:
continue
if clear.is_valid() and not bool(clear.call(eye, point)):
continue
best_angle = angle
best = {"point": point, "angle": angle}
return best
## How much the stick's turn is slowed: 1 with nobody near the look, down to FRICTION
## at an opponent's centre.
static func friction(found: Dictionary) -> float:
if found.is_empty():
return 1.0
return lerpf(FRICTION, 1.0, clampf(float(found["angle"]) / CONE_RADIANS, 0.0, 1.0))
## The look after `delta` seconds of pull towards `found`: Vector2(yaw, pitch). Pulls
## harder the closer the look already is, and never past the opponent.
static func pull(eye: Vector3, yaw: float, pitch: float, found: Dictionary, delta: float) -> Vector2:
if found.is_empty():
return Vector2(yaw, pitch)
var to: Vector3 = Vector3(found["point"]) - eye
var want_yaw: float = atan2(to.x, to.z)
var want_pitch: float = atan2(to.y, Vector2(to.x, to.z).length())
var turn: Vector2 = Vector2(angle_difference(yaw, want_yaw), want_pitch - pitch)
var closeness: float = 1.0 - clampf(float(found["angle"]) / CONE_RADIANS, 0.0, 1.0)
var step: float = PULL_RADIANS_PER_SECOND * closeness * delta
if turn.length() > step:
turn = turn.normalized() * step
return Vector2(fposmod(yaw + turn.x, TAU), clampf(pitch + turn.y, -InputSettings.PITCH_LIMIT, InputSettings.PITCH_LIMIT))
+1
View File
@@ -0,0 +1 @@
uid://u6jrr2nuxaod
+5 -3
View File
@@ -1,10 +1,12 @@
## The placement preview: a translucent copy of the piece where fire would put it, sea
## green when the server would accept it and rust red when it wouldn't. It asks the same
## The placement preview: a translucent copy of the piece where fire would put it, in the
## colour-vision set's allowed colour (sea green as standard) when the server would
## accept it and its refused colour (rust red) when it wouldn't. It asks the same
## Building.target() and Building.check() the server runs, so the ghost and the server
## agree on the client's predicted state.
class_name BuildGhost
extends Node3D
## The standard set's colours; Palette.vision can change what is shown.
const VALID_COLOUR: Color = Palette.GHOST_OK
const INVALID_COLOUR: Color = Palette.GHOST_REFUSED
@@ -44,7 +46,7 @@ func update(sim: Simulation, player: SimEntity, kind: int, material: int) -> voi
if key != _shown_key:
_shown_key = key
_mesh.mesh = PieceMesher.box_mesh(Building.boxes_for_target(target, sim.ground), Color.WHITE)
_surface.albedo_color = VALID_COLOUR if valid else INVALID_COLOUR
_surface.albedo_color = Palette.ghost_ok() if valid else Palette.ghost_refused()
func colour() -> Color:
+7 -2
View File
@@ -21,15 +21,20 @@ const CLEARANCE: float = 0.1
const CLEAR_STEPS: int = 16
## Seconds to move most of the way between hip and aim.
const AIM_BLEND_SECONDS: float = 0.12
## With reduce motion on (A13): a smaller zoom, eased in over longer. Tidewall has no
## camera shake, so the aim zoom is the largest camera motion the player doesn't make.
const CALM_AIM_FOV: float = 62.0
const CALM_AIM_BLEND_SECONDS: float = 0.3
## 0 at the hip, 1 fully aimed. Advanced by `update_aim`.
var aim_blend: float = 0.0
var reduce_motion: bool = false
## Eases aim_blend towards aiming or not over `delta` seconds.
func update_aim(aiming: bool, delta: float) -> void:
var target: float = 1.0 if aiming else 0.0
var rate: float = 1.0 - exp(-delta * 3.0 / AIM_BLEND_SECONDS)
var rate: float = 1.0 - exp(-delta * 3.0 / (CALM_AIM_BLEND_SECONDS if reduce_motion else AIM_BLEND_SECONDS))
aim_blend = lerpf(aim_blend, target, rate)
if absf(aim_blend - target) < 0.001:
aim_blend = target
@@ -66,7 +71,7 @@ func solve(feet: Vector3, yaw: float, pitch: float, crouching: bool, ground: Sim
func fov() -> float:
return lerpf(FOV, AIM_FOV, aim_blend)
return lerpf(FOV, CALM_AIM_FOV if reduce_motion else AIM_FOV, aim_blend)
## Moves from `from` towards `to`, stopping MARGIN short of the first surface.
+53 -4
View File
@@ -6,7 +6,8 @@
## 1 the boathook, 2 to 6 the five slots · B build mode on and off ·
## in build mode 1 to 5 pick wall, floor, ramp, roof or breakwater, Tab the material,
## and left mouse places · M the chart.
## Gamepads come with A13.
## A gamepad works alongside them, in PadInput's fixed layout (A13), with AimAssist
## on its right stick when the setting is on.
##
## With `autoplay` on, a simple script plays instead: it leaps from the barge over
## land, glides, and walks about. That is for tests and for checking a connection with
@@ -31,6 +32,15 @@ var map_open: bool = false
var build_kind: int = StructureSet.WALL
var material: int = Materials.DRIFTWOOD
var autoplay: bool = false
## The gamepad's state, fed by handle().
var pad: PadInput = PadInput.new()
## For aim assist: where the camera is, and the chests of opponents in the world.
## The session fills these each frame; `clear` is its line-of-sight test.
var eye: Vector3 = Vector3.ZERO
var targets: Array[Vector3] = []
var clear: Callable = Callable()
## Sprint latched by clicking the left stick, until the stick is let go.
var _pad_sprint: bool = false
## Actions held down, and the command buttons they hold.
const HELD: Dictionary = {
@@ -45,18 +55,43 @@ func aiming() -> bool:
return buttons & PlayerCommand.BUTTON_AIM != 0 and not build_mode
## Reads what is held down from the keyboard and mouse. Call once a frame.
func poll() -> void:
## Reads what is held down from the keyboard, the mouse and the gamepad, and turns
## the look by the right stick over `delta` seconds. Call once a frame.
func poll(delta: float = 0.0) -> void:
if autoplay:
return
move = Vector2(
_axis("right", "left"),
_axis("forward", "back"),
)
var stick: Vector2 = pad.move()
if stick != Vector2.ZERO:
move = (move + stick).limit_length(1.0)
elif _pad_sprint and move == Vector2.ZERO:
_pad_sprint = false
buttons = 0
for action: String in HELD:
if bindings.is_held(action):
if bindings.is_held(action) or pad.is_held(action):
buttons |= int(HELD[action])
if _pad_sprint:
buttons |= PlayerCommand.BUTTON_SPRINT
_pad_look(delta)
## Turns the look by the right stick, with aim assist when it's on.
func _pad_look(delta: float) -> void:
var stick: Vector2 = pad.look()
var found: Dictionary = {}
if settings.aim_assist and pad.active and not targets.is_empty():
found = AimAssist.nearest(eye, yaw, pitch, targets, clear)
if stick != Vector2.ZERO:
var look: Vector2 = settings.apply_stick(stick, yaw, pitch, aiming(), delta, AimAssist.friction(found))
yaw = look.x
pitch = look.y
if not found.is_empty() and aiming() and (stick != Vector2.ZERO or move != Vector2.ZERO):
var pulled: Vector2 = AimAssist.pull(eye, yaw, pitch, found, delta)
yaw = pulled.x
pitch = pulled.y
## Takes one input event: mouse motion turns the look, and keys that act once per
@@ -64,6 +99,10 @@ func poll() -> void:
func handle(event: InputEvent, captured: bool) -> void:
if autoplay:
return
if pad.feed(event):
for action: String in pad.take_presses():
act(action)
return
var motion: InputEventMouseMotion = event as InputEventMouseMotion
if motion != null and captured:
turn(motion.relative)
@@ -95,6 +134,16 @@ func act(action: String) -> void:
map_open = not map_open
elif action == "material" and build_mode:
material = (material + 1) % Materials.NAMES.size()
elif action == "material_back" and build_mode:
material = posmod(material - 1, Materials.NAMES.size())
elif action == "slot_next" or action == "slot_back":
var step: int = 1 if action == "slot_next" else -1
if build_mode:
build_kind = posmod(build_kind + step, StructureSet.KINDS.size())
else:
slot = posmod(slot + step, Inventory.slot_count() + 1)
elif action == "sprint":
_pad_sprint = true
elif action.begins_with("slot_"):
var number: int = action.substr(5).to_int()
if build_mode:
+30 -3
View File
@@ -31,6 +31,8 @@ const WINDOW_MODES: Array[String] = ["Windowed", "Fullscreen", "Exclusive fullsc
## Frame caps offered, 0 for none.
const FRAME_CAPS: Array[int] = [0, 30, 60, 90, 120, 144, 165, 240]
const MAX_NAME_LENGTH: int = 24
## Interface scales offered (A13): menus and HUD drawn this much larger.
const UI_SCALES: Array[float] = [0.9, 1.0, 1.15, 1.3]
var bindings: KeyBindings = KeyBindings.new()
var mouse: InputSettings = InputSettings.new()
@@ -78,6 +80,22 @@ var practice_team_size: int = 1:
## The tutorial (A12): offered on the first launch until answered, and finished once.
var tutorial_offered: bool = false
var tutorial_done: bool = false
## Accessibility (A13). Colour vision: an index into Palette.VISION_NAMES.
var vision: int = Palette.VISION_STANDARD:
set(value):
vision = clampi(value, 0, Palette.VISION_NAMES.size() - 1)
## How large the menus and HUD are drawn: one of UI_SCALES.
var ui_scale: float = 1.0:
set(value):
ui_scale = 1.0
for offered: float in UI_SCALES:
if absf(offered - value) < 0.001:
ui_scale = offered
## Captions for the sounds that matter in play (Captions).
var captions: bool = false
## Less motion and flashing: a smaller zoom when aiming, eased in more slowly, and a
## gentler flash when hurt.
var reduce_motion: bool = false
func shadow_distance() -> float:
@@ -109,9 +127,7 @@ func apply_to_viewport(viewport: Viewport) -> void:
func save(path: String = DEFAULT_PATH) -> Error:
var config: ConfigFile = ConfigFile.new()
# The mouse keeps its own section, as InputSettings has always saved it.
config.set_value(InputSettings.SECTION, "mouse_sensitivity", mouse.mouse_sensitivity)
config.set_value(InputSettings.SECTION, "aim_sensitivity_scale", mouse.aim_sensitivity_scale)
config.set_value(InputSettings.SECTION, "invert_y", mouse.invert_y)
mouse.write(config)
bindings.write(config)
config.set_value("graphics", "quality", quality)
config.set_value("graphics", "print_pass", print_pass)
@@ -128,6 +144,10 @@ func save(path: String = DEFAULT_PATH) -> Error:
config.set_value("practice", "team_size", practice_team_size)
config.set_value("tutorial", "offered", tutorial_offered)
config.set_value("tutorial", "done", tutorial_done)
config.set_value("access", "vision", vision)
config.set_value("access", "ui_scale", ui_scale)
config.set_value("access", "captions", captions)
config.set_value("access", "reduce_motion", reduce_motion)
return config.save(path)
@@ -157,6 +177,10 @@ static func load_from(path: String = DEFAULT_PATH) -> GameSettings:
settings.practice_team_size = _int(config, "practice", "team_size", settings.practice_team_size)
settings.tutorial_offered = _bool(config, "tutorial", "offered", settings.tutorial_offered)
settings.tutorial_done = _bool(config, "tutorial", "done", settings.tutorial_done)
settings.vision = _int(config, "access", "vision", settings.vision)
settings.ui_scale = _float(config, "access", "ui_scale", settings.ui_scale)
settings.captions = _bool(config, "access", "captions", settings.captions)
settings.reduce_motion = _bool(config, "access", "reduce_motion", settings.reduce_motion)
return settings
@@ -165,6 +189,9 @@ static func load_from(path: String = DEFAULT_PATH) -> GameSettings:
## when there is none.
func apply_to_program(tree: SceneTree) -> void:
_apply_audio()
Palette.vision = vision
if tree != null:
tree.root.content_scale_factor = ui_scale
if DisplayServer.get_name() == "headless":
return
Engine.max_fps = max_fps
+109
View File
@@ -0,0 +1,109 @@
## Captions for the sounds that matter in play (A13), for players who can't hear them
## or play with the sound down: what was heard and, for placed sounds, which way it
## came from against where the camera looks. It reads the cues SoundDirector decided
## each frame, so a caption is shown exactly when its sound is played.
##
## Repeats of a caption refresh it rather than stacking ("Footsteps, behind" stays one
## line while they go on), the newest line is last, and lines fade after SECONDS.
## Sounds the player makes themselves (their own steps, shots and pieces) aren't
## captioned: they know.
class_name Captions
extends RefCounted
const SECONDS: float = 3.0
const MAX_LINES: int = 4
## Placed sounds closer than this to the player are their own.
const OWN_METRES: float = 2.5
## Footsteps further than this aren't worth a line.
const STEP_METRES: float = 20.0
## Each sound's words. Footsteps, shots and pieces go by prefix (see words_for()).
const WORDS: Dictionary = {
"foghorn": "Foghorn: the sea is rising",
"bell": "Ship's bell",
"surge": "A surge breaks",
"lighthouse": "Lighthouse tone: high water, last land",
"hurt": "You're hit",
"eliminated": "Someone is out",
"keg_blast": "Powder keg blast",
"hit_player": "Shot strikes someone",
"splash": "Splash",
"swim": "Swimming",
"swing_boathook": "Boathook swing",
"chest_open": "Chest opened",
}
## Live lines: words -> {"words", "side", "left" (seconds)}, newest last.
var _lines: Array[Dictionary] = []
## The words for a sound, or "" for one that isn't captioned.
static func words_for(sound: String) -> String:
if sound.begins_with("step_"):
return "Footsteps"
if sound.begins_with("shot_"):
return "Gunfire"
if sound.begins_with("break_"):
return "A piece breaks"
if sound.begins_with("build_"):
return "Building"
return String(WORDS.get(sound, ""))
## Which way `at` is from a listener at `eye` looking along `yaw` (simulation
## convention): "ahead", "right", "behind" or "left".
static func side_of(eye: Vector3, yaw: float, at: Vector3) -> String:
var to: Vector2 = Vector2(at.x - eye.x, at.z - eye.z)
if to.length() < 0.01:
return ""
var turn: float = angle_difference(yaw, atan2(to.x, to.y))
# Positive turn is to the left: yaw grows anticlockwise seen from above.
if absf(turn) <= PI / 4.0:
return "ahead"
if absf(turn) >= PI * 3.0 / 4.0:
return "behind"
return "left" if turn > 0.0 else "right"
## Takes a frame's cues. `eye` and `yaw` are the camera's; `own` is where the player
## is, or Vector3.INF with no player.
func hear(cues: Array[Dictionary], eye: Vector3, yaw: float, own: Vector3, delta: float) -> void:
for line: Dictionary in _lines:
line["left"] = float(line["left"]) - delta
_lines = _lines.filter(func(line: Dictionary) -> bool: return float(line["left"]) > 0.0)
for cue: Dictionary in cues:
var words: String = words_for(String(cue["sound"]))
if words.is_empty():
continue
var side: String = ""
if bool(cue["spatial"]):
var at: Vector3 = cue["at"]
if own != Vector3.INF and at.distance_to(own) < OWN_METRES:
continue
if words == "Footsteps" and own != Vector3.INF and at.distance_to(own) > STEP_METRES:
continue
side = side_of(eye, yaw, at)
_show(words, side)
func _show(words: String, side: String) -> void:
var text: String = words if side.is_empty() else "%s, %s" % [words, side]
for index: int in _lines.size():
if _lines[index]["text"] == text:
_lines.remove_at(index)
break
_lines.append({"text": text, "left": SECONDS})
while _lines.size() > MAX_LINES:
_lines.remove_at(0)
## The lines to show now, oldest first.
func lines() -> Array[String]:
var shown: Array[String] = []
for line: Dictionary in _lines:
shown.append(String(line["text"]))
return shown
func clear() -> void:
_lines.clear()
+1
View File
@@ -0,0 +1 @@
uid://cx1cgtph7dshj
+3 -3
View File
@@ -174,8 +174,8 @@ func _draw_overlay() -> void:
var coming: PackedByteArray = coming_flood(world)
var per_cell: int = maxi(roundi(PIXELS / float(flood.side)), 1)
var taken: Color = Color(Palette.SEA_INK.lightened(0.3), 0.7)
var hatch: Color = Color(Palette.WARNING, 0.95)
var wash: Color = Color(Palette.WARNING, 0.16)
var hatch: Color = Color(Palette.warning(), 0.95)
var wash: Color = Color(Palette.warning(), 0.16)
for cz: int in flood.side:
for cx: int in flood.side:
var index: int = cz * flood.side + cx
@@ -241,7 +241,7 @@ func _draw() -> void:
var ahead: Vector2 = Vector2(sin(facing), cos(facing))
var side: Vector2 = Vector2(ahead.y, -ahead.x)
var arrow: PackedVector2Array = PackedVector2Array([at + ahead * 11.0, at - ahead * 7.0 + side * 7.0, at - ahead * 3.0, at - ahead * 7.0 - side * 7.0])
draw_colored_polygon(arrow, Palette.OILSKIN)
draw_colored_polygon(arrow, Palette.own())
arrow.append(arrow[0])
draw_polyline(arrow, Palette.INK, 2.0)
# North, and the frame's ink edge.
+72 -13
View File
@@ -30,6 +30,8 @@ var _build: Label
var _down: Label
var _reticle: Reticle
var _hurt: HurtEdge
## Captions for key sounds (A13), above the materials, newest at the bottom.
var _captions: VBoxContainer
## When a feed line was first shown (msec), so lines fade after HudState.FEED_SECONDS.
var _feed_seen: Dictionary = {}
## Captures turn this off to keep every line of the feed.
@@ -81,11 +83,13 @@ func _init() -> void:
add_child(_vitals)
_hotbar = HBoxContainer.new()
_hotbar.set_anchors_preset(Control.PRESET_CENTER_BOTTOM)
# Placed by _fit_bottom(): centred, unless a larger interface size (A13) leaves no
# room, when it moves clear of the vitals and its slots narrow.
_hotbar.set_anchors_preset(Control.PRESET_BOTTOM_LEFT)
_hotbar.add_theme_constant_override("separation", 6)
_hotbar.alignment = BoxContainer.ALIGNMENT_CENTER
_hotbar.size = Vector2(6.0 * 86.0 + 5.0 * 6.0, 112.0)
_hotbar.position = Vector2(-_hotbar.size.x * 0.5, -112.0 - MARGIN)
_hotbar.position = Vector2(640.0 - _hotbar.size.x * 0.5, -112.0 - MARGIN)
add_child(_hotbar)
_build = _label(FONT_BODY, Palette.PAPER)
@@ -94,7 +98,7 @@ func _init() -> void:
_build.size = Vector2(520.0, 24.0)
_build.position = Vector2(-260.0, -112.0 - MARGIN - 30.0)
add_child(_build)
_down = _label(FONT_BODY, Palette.WARNING)
_down = _label(FONT_BODY, Palette.warning())
_down.set_anchors_preset(Control.PRESET_CENTER_BOTTOM)
_down.horizontal_alignment = HORIZONTAL_ALIGNMENT_CENTER
_down.size = Vector2(720.0, 24.0)
@@ -109,9 +113,23 @@ func _init() -> void:
_materials.position = Vector2(-190.0 - MARGIN, -84.0 - MARGIN)
_materials.add_theme_constant_override("separation", 2)
add_child(_materials)
_captions = VBoxContainer.new()
_captions.set_anchors_preset(Control.PRESET_BOTTOM_RIGHT)
_captions.size = Vector2(420.0, 4.0 * 24.0)
# Above the build line and the hotbar's top, so a long caption never runs into them.
_captions.position = Vector2(-420.0 - MARGIN, -112.0 - MARGIN - 52.0 - _captions.size.y)
_captions.alignment = BoxContainer.ALIGNMENT_END
_captions.add_theme_constant_override("separation", 2)
add_child(_captions)
show_state(state)
func _notification(what: int) -> void:
if what == NOTIFICATION_RESIZED and _hotbar != null:
_fit_bottom()
## Shows `shown`, and nothing that isn't in it.
func show_state(shown: HudState) -> void:
state = shown
@@ -134,7 +152,7 @@ func show_state(shown: HudState) -> void:
for index: int in lines.size():
var label: Label = _feed.get_child(index) as Label
label.text = String(lines[index]["text"])
label.add_theme_color_override("font_color", Palette.OILSKIN if lines[index]["you"] else Palette.PAPER)
label.add_theme_color_override("font_color", Palette.own() if lines[index]["you"] else Palette.PAPER)
if shown.feed.is_empty():
_feed_seen.clear()
@@ -155,6 +173,7 @@ func show_state(shown: HudState) -> void:
var box: SlotBox = SlotBox.new()
box.custom_minimum_size = Vector2(86.0, 112.0)
_hotbar.add_child(box)
_fit_bottom()
for index: int in _hotbar.get_child_count():
var box: SlotBox = _hotbar.get_child(index) as SlotBox
box.visible = index < shown.slots.size()
@@ -169,13 +188,53 @@ func show_state(shown: HudState) -> void:
var count: int = shown.materials[code] if code < shown.materials.size() else 0
(_materials.get_child(code) as Label).text = "%s %d" % [Materials.NAMES[code].replace("_", " ").capitalize(), count]
_fit_labels(_captions, shown.captions.size(), HORIZONTAL_ALIGNMENT_RIGHT)
for index: int in shown.captions.size():
(_captions.get_child(index) as Label).text = "[ %s ]" % shown.captions[index]
_down.visible = shown.playing and shown.downed
_down.add_theme_color_override("font_color", Palette.warning())
_build.visible = shown.playing and not shown.build.is_empty()
if _build.visible:
var build: Dictionary = shown.build
_build.text = "BUILDING · %s in %s · costs %d%s" % [String(build["kind"]).capitalize(), String(build["material"]).replace("_", " "),
int(build["cost"]), "" if build["affordable"] else " · NOT ENOUGH"]
_build.add_theme_color_override("font_color", Palette.PAPER if build["affordable"] else Palette.WARNING)
_build.add_theme_color_override("font_color", Palette.PAPER if build["affordable"] else Palette.warning())
## The narrowest a hotbar slot gets when there isn't room for the full width.
const SLOT_WIDTH: float = 86.0
const SLOT_MIN_WIDTH: float = 66.0
## Places the hotbar between the vitals and the materials: centred when there is room,
## as at 1280x720; on a narrower canvas (a larger interface size) beside the vitals,
## with its slots narrowed to fit.
func _fit_bottom() -> void:
var count: int = maxi(_hotbar.get_child_count(), 1)
var gap: float = 6.0
var left: float = MARGIN + _vitals.size.x + 10.0
var right: float = size.x - MARGIN - _materials.size.x - 10.0
var slot: float = clampf((right - left - gap * (count - 1)) / count, SLOT_MIN_WIDTH, SLOT_WIDTH)
var width: float = slot * count + gap * (count - 1)
for child: Node in _hotbar.get_children():
(child as Control).custom_minimum_size = Vector2(slot, 112.0)
_hotbar.size = Vector2(width, 112.0)
var x: float = clampf(size.x * 0.5 - width * 0.5, left, maxf(left, right - width))
_hotbar.position = Vector2(x, size.y - 112.0 - MARGIN)
## Where the hotbar is drawn, for tests.
func hotbar_rect() -> Rect2:
return Rect2(_hotbar.position, _hotbar.size)
func vitals_rect() -> Rect2:
return Rect2(_vitals.position, _vitals.size)
func materials_rect() -> Rect2:
return Rect2(_materials.position, _materials.size)
## Keeps exactly `count` labels in `box`, adding or removing at the end.
@@ -262,12 +321,12 @@ class TidePost:
# The next level: a rust notch cut into both sides, with a dashed line across.
if next > sea + 0.05:
var next_y: float = to_y.call(next)
draw_dashed_line(Vector2(post.position.x - 6.0, next_y), Vector2(post.end.x + 6.0, next_y), Palette.WARNING, 2.0, 4.0)
draw_colored_polygon(PackedVector2Array([Vector2(post.position.x - 10.0, next_y - 5.0), Vector2(post.position.x - 2.0, next_y), Vector2(post.position.x - 10.0, next_y + 5.0)]), Palette.WARNING)
draw_dashed_line(Vector2(post.position.x - 6.0, next_y), Vector2(post.end.x + 6.0, next_y), Palette.warning(), 2.0, 4.0)
draw_colored_polygon(PackedVector2Array([Vector2(post.position.x - 10.0, next_y - 5.0), Vector2(post.position.x - 2.0, next_y), Vector2(post.position.x - 10.0, next_y + 5.0)]), Palette.warning())
# The player's own height: a yellow pointer on the right of the post.
if not is_nan(feet):
var feet_y: float = to_y.call(feet)
draw_colored_polygon(PackedVector2Array([Vector2(post.end.x + 2.0, feet_y), Vector2(post.end.x + 12.0, feet_y - 6.0), Vector2(post.end.x + 12.0, feet_y + 6.0)]), Palette.OILSKIN)
draw_colored_polygon(PackedVector2Array([Vector2(post.end.x + 2.0, feet_y), Vector2(post.end.x + 12.0, feet_y - 6.0), Vector2(post.end.x + 12.0, feet_y + 6.0)]), Palette.own())
draw_polyline(PackedVector2Array([Vector2(post.end.x + 2.0, feet_y), Vector2(post.end.x + 12.0, feet_y - 6.0), Vector2(post.end.x + 12.0, feet_y + 6.0), Vector2(post.end.x + 2.0, feet_y)]), Palette.INK, 1.0)
var x: float = post.end.x + 26.0
@@ -285,12 +344,12 @@ class TidePost:
timing = "HIGH WATER · last land"
_:
timing = "Slack water"
Hud.draw_text(self, Vector2(x, 54.0), timing, Hud.FONT_BODY, Palette.WARNING if stage != Tide.HOLD else Palette.INK, width)
Hud.draw_text(self, Vector2(x, 54.0), timing, Hud.FONT_BODY, Palette.warning() if stage != Tide.HOLD else Palette.INK, width)
Hud.draw_text(self, Vector2(x, 74.0), "Sea %.1f m · next %.1f m" % [sea, next], Hud.FONT_SMALL, Palette.INK, width)
if not is_nan(feet):
var above: float = feet - next
var line: String = "You: %.1f m above the next line" % above if above >= 0.0 else "You: %.1f m BELOW the next line" % -above
Hud.draw_text(self, Vector2(x, 92.0), line, Hud.FONT_SMALL, Palette.INK if above >= 0.0 else Palette.WARNING, width)
Hud.draw_text(self, Vector2(x, 92.0), line, Hud.FONT_SMALL, Palette.INK if above >= 0.0 else Palette.warning(), width)
## Health and armour bars: each a number, a word, notches every quarter and its own
@@ -314,7 +373,7 @@ class Vitals:
Hud.draw_text(self, Vector2(10.0, rect.position.y + rect.size.y * 0.5 + 5.0), word, Hud.FONT_SMALL)
draw_rect(rect, Color(Palette.INK, 0.15))
var filled: Rect2 = Rect2(rect.position, Vector2(rect.size.x * clampf(float(value) / most, 0.0, 1.0), rect.size.y))
var fill: Color = Palette.WARNING if low else (Palette.SEA_PAINT if striped else Palette.OCHRE_RED.lerp(Palette.TAR, 0.1))
var fill: Color = Palette.warning() if low else (Palette.SEA_PAINT if striped else Palette.OCHRE_RED.lerp(Palette.TAR, 0.1))
draw_rect(filled, fill)
if striped or low:
# Armour is hatched one way; low health the other.
@@ -370,7 +429,7 @@ class SlotBox:
return
Hud.draw_card(self, rect, selected)
if selected:
draw_rect(Rect2(rect.position, Vector2(rect.size.x, 6.0)), Palette.OILSKIN)
draw_rect(Rect2(rect.position, Vector2(rect.size.x, 6.0)), Palette.own())
draw_rect(Rect2(rect.position, Vector2(rect.size.x, 6.0)), Palette.INK, false, 1.0)
Hud.draw_text(self, rect.position + Vector2(5.0, 15.0), str(number), Hud.FONT_SMALL - 2, Palette.INK)
var picture: Texture2D = ItemModels.icon(String(slot.get("id", "")))
@@ -450,7 +509,7 @@ class HurtEdge:
for step: int in steps:
var inset: float = band * step / steps
var alpha: float = 0.42 * strength * (1.0 - float(step) / steps)
var colour: Color = Color(Palette.WARNING, alpha / steps * 2.0)
var colour: Color = Color(Palette.warning(), alpha / steps * 2.0)
var width: float = band / steps
draw_rect(Rect2(inset, inset, size.x - inset * 2.0, width), colour)
draw_rect(Rect2(inset, size.y - inset - width, size.x - inset * 2.0, width), colour)
+2
View File
@@ -33,6 +33,8 @@ var reticle: bool = false
## flash for being hurt, each 1 just after and 0 when gone.
var hit: float = 0.0
var hurt: float = 0.0
## Captions for key sounds (A13, Captions), oldest first; empty when they're off.
var captions: Array[String] = []
## The HUD for a client: its own predicted player, the world's tide and the server's feed.
+35 -1
View File
@@ -10,6 +10,8 @@ const MIN_SENSITIVITY: float = 0.05
const MAX_SENSITIVITY: float = 10.0
## Looking straight up or down flips the camera basis, so stop just short.
const PITCH_LIMIT: float = deg_to_rad(85.0)
const MIN_PAD_SENSITIVITY: float = 0.2
const MAX_PAD_SENSITIVITY: float = 3.0
var mouse_sensitivity: float = 1.0:
set(value):
@@ -19,6 +21,12 @@ var aim_sensitivity_scale: float = 0.6:
set(value):
aim_sensitivity_scale = clampf(value, 0.1, 2.0)
var invert_y: bool = false
## The gamepad's right stick, against PadInput.LOOK_RADIANS_PER_SECOND (A13).
var pad_sensitivity: float = 1.0:
set(value):
pad_sensitivity = clampf(value, MIN_PAD_SENSITIVITY, MAX_PAD_SENSITIVITY)
## Aim assist for the gamepad (AimAssist). Never applies to the mouse.
var aim_assist: bool = true
## Applies a mouse motion to a look direction. Returns Vector2(yaw, pitch) in radians.
@@ -33,13 +41,33 @@ func apply_mouse(relative: Vector2, yaw: float, pitch: float, aiming: bool) -> V
return Vector2(new_yaw, new_pitch)
## Applies `delta` seconds of the right stick (PadInput.look(): x right, y down) to a
## look direction, slowed by `friction` (AimAssist). Returns Vector2(yaw, pitch).
## Pushing right turns right and pushing up looks up, unless invert_y is set.
func apply_stick(stick: Vector2, yaw: float, pitch: float, aiming: bool, delta: float, friction: float = 1.0) -> Vector2:
var scale: float = PadInput.LOOK_RADIANS_PER_SECOND * pad_sensitivity * delta * friction
if aiming:
scale *= aim_sensitivity_scale
var vertical: float = stick.y if invert_y else -stick.y
var new_yaw: float = fposmod(yaw - stick.x * scale, TAU)
var new_pitch: float = clampf(pitch + vertical * scale, -PITCH_LIMIT, PITCH_LIMIT)
return Vector2(new_yaw, new_pitch)
func save(path: String = DEFAULT_PATH) -> Error:
var config: ConfigFile = ConfigFile.new()
config.load(path) # Keep other sections; a missing file is fine.
write(config)
return config.save(path)
## Writes these settings into `config`'s input section.
func write(config: ConfigFile) -> void:
config.set_value(SECTION, "mouse_sensitivity", mouse_sensitivity)
config.set_value(SECTION, "aim_sensitivity_scale", aim_sensitivity_scale)
config.set_value(SECTION, "invert_y", invert_y)
return config.save(path)
config.set_value(SECTION, "pad_sensitivity", pad_sensitivity)
config.set_value(SECTION, "aim_assist", aim_assist)
## Loads saved settings. Missing or malformed values keep their defaults.
@@ -57,4 +85,10 @@ static func load_from(path: String = DEFAULT_PATH) -> InputSettings:
var invert: Variant = config.get_value(SECTION, "invert_y", false)
if invert is bool:
settings.invert_y = invert
var pad: Variant = config.get_value(SECTION, "pad_sensitivity", 1.0)
if (pad is float and is_finite(pad)) or pad is int:
settings.pad_sensitivity = float(pad)
var assist: Variant = config.get_value(SECTION, "aim_assist", true)
if assist is bool:
settings.aim_assist = assist
return settings
+1
View File
@@ -39,6 +39,7 @@ func apply_settings(settings: GameSettings) -> void:
print_pass.visible = settings.print_pass
if effects != null:
effects.budget = settings.particle_budget()
rig.reduce_motion = settings.reduce_motion
## Builds the scene for `simulation`. `local_id` is the player this client plays, or 0.
+177
View File
@@ -0,0 +1,177 @@
## The gamepad (A13): one fixed layout, read from the input events the game is given
## rather than from the Input singleton, so tests can drive it with simulated events and
## any pad (device) works. Buttons use Godot's JoyButton positions, named here as on the
## common layouts (south A, east B, west X, north Y).
##
## Left stick move · right stick look · click the left stick to sprint (until you stop)
## South jump · East crouch · West reload · North pick up or open
## Right trigger use, fire or place · left trigger aim
## Right bumper next slot or piece · left bumper the one before
## Click the right stick: build mode · D-pad up the chart · D-pad down drop the held item
## D-pad right / left: next / previous material · Start the pause menu
##
## In the menus the D-pad and the left stick move the focus (Godot's own ui_ actions),
## South chooses and East or Start goes back (install_menu_actions()).
class_name PadInput
extends RefCounted
## Sticks inside this radius count as centred.
const DEADZONE: float = 0.18
## A trigger pulled further than this is held.
const TRIGGER_PULL: float = 0.45
## Radians a second the look turns with the right stick pushed fully, at look speed 1.
const LOOK_RADIANS_PER_SECOND: float = 3.2
## The look's response: stick deflection (past the dead zone) raised to this, so small
## pushes turn finely and full pushes turn fast.
const LOOK_CURVE: float = 1.7
## Actions held while their button is.
const HELD_BUTTONS: Dictionary = {
"jump": JOY_BUTTON_A, "crouch": JOY_BUTTON_B, "reload": JOY_BUTTON_X,
"interact": JOY_BUTTON_Y,
}
## Actions held while their trigger is pulled.
const HELD_TRIGGERS: Dictionary = {
"fire": JOY_AXIS_TRIGGER_RIGHT, "aim": JOY_AXIS_TRIGGER_LEFT,
}
## Actions that happen once per press. "drop" is also held (the command's drop button),
## so it is in both: pressed() reports it and held() holds it.
const PRESS_BUTTONS: Dictionary = {
JOY_BUTTON_RIGHT_STICK: "build", JOY_BUTTON_DPAD_UP: "map",
JOY_BUTTON_DPAD_RIGHT: "material", JOY_BUTTON_DPAD_LEFT: "material_back",
JOY_BUTTON_RIGHT_SHOULDER: "slot_next", JOY_BUTTON_LEFT_SHOULDER: "slot_back",
JOY_BUTTON_LEFT_STICK: "sprint", JOY_BUTTON_START: "pause",
}
const DROP_BUTTON: JoyButton = JOY_BUTTON_DPAD_DOWN
## Names for the settings menu and the tutorial, by action.
const NAMES: Dictionary = {
"forward": "Left stick", "back": "Left stick", "left": "Left stick", "right": "Left stick",
"look": "Right stick", "jump": "South (A)", "crouch": "East (B)", "reload": "West (X)",
"interact": "North (Y)", "fire": "Right trigger", "aim": "Left trigger",
"sprint": "Click left stick", "build": "Click right stick", "map": "D-pad up",
"drop": "D-pad down", "material": "D-pad right", "material_back": "D-pad left",
"slot_next": "Right bumper", "slot_back": "Left bumper", "pause": "Start",
}
## The layout as the settings menu lists it: [what, which].
const LAYOUT: Array[Array] = [
["Move", "Left stick"], ["Look", "Right stick"], ["Sprint (until you stop)", "Click left stick"],
["Jump", "South (A)"], ["Crouch", "East (B)"], ["Reload", "West (X)"],
["Pick up or open", "North (Y)"], ["Use, fire or place", "Right trigger"],
["Aim", "Left trigger"], ["Next slot or piece", "Right bumper"],
["Slot or piece before", "Left bumper"], ["Build mode", "Click right stick"],
["Chart", "D-pad up"], ["Drop held item", "D-pad down"],
["Next / previous material", "D-pad right / left"], ["Pause menu", "Start"],
]
var _buttons: Dictionary = {}
var _axes: PackedFloat32Array = PackedFloat32Array()
## Presses since the last take_presses(), as action ids, in order.
var _presses: Array[String] = []
## True once the pad has been used since the keyboard or mouse last was, so prompts
## can name pad buttons.
var active: bool = false
func _init() -> void:
_axes.resize(JOY_AXIS_MAX)
## Takes one input event. Returns true if it was the pad's.
func feed(event: InputEvent) -> bool:
var button: InputEventJoypadButton = event as InputEventJoypadButton
if button != null:
var index: int = int(button.button_index)
var was: bool = bool(_buttons.get(index, false))
_buttons[index] = button.pressed
if button.pressed and not was:
active = true
if PRESS_BUTTONS.has(index):
_presses.append(String(PRESS_BUTTONS[index]))
return true
var motion: InputEventJoypadMotion = event as InputEventJoypadMotion
if motion != null:
var axis: int = int(motion.axis)
if axis >= 0 and axis < _axes.size():
_axes[axis] = clampf(motion.axis_value, -1.0, 1.0)
if absf(motion.axis_value) > 0.5:
active = true
return true
if event is InputEventKey or event is InputEventMouseButton:
active = false
return false
## The once-per-press actions since the last call, oldest first.
func take_presses() -> Array[String]:
var taken: Array[String] = _presses
_presses = []
return taken
func is_held(action: String) -> bool:
if action == "drop":
return bool(_buttons.get(int(DROP_BUTTON), false))
if HELD_BUTTONS.has(action):
return bool(_buttons.get(int(HELD_BUTTONS[action]), false))
if HELD_TRIGGERS.has(action):
return _axes[int(HELD_TRIGGERS[action])] > TRIGGER_PULL
return false
## The left stick as Vector2(strafe right, forward), dead zone removed, length up to 1.
func move() -> Vector2:
var stick: Vector2 = _stick(JOY_AXIS_LEFT_X, JOY_AXIS_LEFT_Y)
return Vector2(stick.x, -stick.y)
## The right stick, dead zone removed and curved: x right, y down, length up to 1.
func look() -> Vector2:
var stick: Vector2 = _stick(JOY_AXIS_RIGHT_X, JOY_AXIS_RIGHT_Y)
var length: float = stick.length()
if length <= 0.0:
return Vector2.ZERO
return stick / length * pow(length, LOOK_CURVE)
## Forgets everything held (the pad was unplugged, or a menu opened).
func release() -> void:
_buttons.clear()
_axes.fill(0.0)
_presses.clear()
## A stick with a radial dead zone, rescaled so it starts from 0 at the zone's edge.
func _stick(x_axis: JoyAxis, y_axis: JoyAxis) -> Vector2:
var raw: Vector2 = Vector2(_axes[int(x_axis)], _axes[int(y_axis)])
var length: float = raw.length()
if length <= DEADZONE:
return Vector2.ZERO
return raw / length * minf((length - DEADZONE) / (1.0 - DEADZONE), 1.0)
## The name of the pad input for `action`, for prompts.
static func describe(action: String) -> String:
if action.begins_with("slot_") and not NAMES.has(action):
return "Bumpers"
return String(NAMES.get(action, "?"))
## Adds the pad to Godot's menu actions: South chooses, East and Start go back. The
## D-pad and the left stick already move the focus. Safe to call more than once.
static func install_menu_actions() -> void:
_add_button("ui_accept", JOY_BUTTON_A)
_add_button("ui_cancel", JOY_BUTTON_B)
_add_button("ui_cancel", JOY_BUTTON_START)
static func _add_button(action: String, index: JoyButton) -> void:
if not InputMap.has_action(action):
return
for existing: InputEvent in InputMap.action_get_events(action):
var pad: InputEventJoypadButton = existing as InputEventJoypadButton
if pad != null and pad.button_index == index:
return
var event: InputEventJoypadButton = InputEventJoypadButton.new()
event.button_index = index
event.device = -1
InputMap.action_add_event(action, event)
+1
View File
@@ -0,0 +1 @@
uid://bftj1asrutyll
+46
View File
@@ -116,3 +116,49 @@ const GHOST_REFUSED: Color = Color(0.86, 0.32, 0.22, 0.38)
const WARNING: Color = Color(0.86, 0.32, 0.22)
## The sea on the HUD's tide gauge and map.
const SEA_INK: Color = Color(0.20, 0.34, 0.42)
# --- Colour vision (A13) ------------------------------------------------------------
## The signal colours above suit most eyes, but red against green (the build ghost) and
## rust against oilskin yellow are hard for many people to tell apart. The settings
## offer a set for each common kind of colour blindness; everything that signals asks
## for its colour through the functions below, so the set chosen applies everywhere.
## test_palette checks each set with a simulation of the colour vision it is for.
const VISION_NAMES: Array[String] = ["Standard", "Red-green (protan, deutan)", "Blue-yellow (tritan)"]
const VISION_STANDARD: int = 0
const VISION_RED_GREEN: int = 1
const VISION_BLUE_YELLOW: int = 2
## Per set: allowed and refused in the build ghost, danger, and the player's own marks.
const VISION_SIGNALS: Array[Dictionary] = [
{"ghost_ok": GHOST_OK, "ghost_refused": GHOST_REFUSED, "warning": WARNING, "own": OILSKIN},
# Blue for allowed and orange for refused; danger a deep magenta, apart from the
# yellow of the player's own marks.
{"ghost_ok": Color(0.22, 0.52, 0.95, 0.40), "ghost_refused": Color(0.98, 0.56, 0.08, 0.40),
"warning": Color(0.78, 0.16, 0.62), "own": OILSKIN},
# Teal for allowed and vermilion for refused; the player's marks turn white-blue,
# since yellow and pink run together.
{"ghost_ok": Color(0.16, 0.70, 0.74, 0.40), "ghost_refused": Color(0.90, 0.16, 0.20, 0.40),
"warning": Color(0.88, 0.14, 0.18), "own": Color(0.62, 0.86, 0.98)},
]
## Which set is in use. GameSettings.apply_to_program sets it.
static var vision: int = VISION_STANDARD:
set(value):
vision = clampi(value, 0, VISION_SIGNALS.size() - 1)
static func ghost_ok() -> Color:
return VISION_SIGNALS[vision]["ghost_ok"]
static func ghost_refused() -> Color:
return VISION_SIGNALS[vision]["ghost_refused"]
## Danger on the HUD and chart (WARNING in the standard set).
static func warning() -> Color:
return VISION_SIGNALS[vision]["warning"]
## The player's own marks on the HUD and chart (OILSKIN in the standard set).
static func own() -> Color:
return VISION_SIGNALS[vision]["own"]
+83 -4
View File
@@ -1,10 +1,11 @@
## The game's menus (A10), in the paper-and-ink motifs of docs/STYLE.md: the welcome
## that offers the tutorial on the first launch (A12), the main menu, practice against bots, joining a server (with the LAN and list-server browser),
## settings (controls, mouse, graphics, audio, display), the pause menu and the results.
## settings (controls, mouse, gamepad, graphics, audio, display, accessibility), the pause menu and the results.
##
## Menus only edit `settings` and say what the player asked for through signals; the
## program (Main) starts and leaves matches. Every screen can be driven from the
## keyboard: each grabs focus on its first control when shown, and Escape goes back.
## keyboard or a gamepad: each grabs focus on its first control when shown, the arrows
## or the D-pad move it, and Escape, or East or Start on the pad, goes back (A13).
## show_screen() and the buttons' `pressed` signals are what the UI test drives.
class_name Menus
extends Control
@@ -62,6 +63,12 @@ var _volumes: Dictionary = {}
var _window_mode: OptionButton
var _vsync: CheckButton
var _max_fps: OptionButton
var _pad_speed: HSlider
var _aim_assist: CheckButton
var _vision: OptionButton
var _ui_scale: OptionButton
var _captions: CheckButton
var _reduce_motion: CheckButton
## Results.
var _results_title: Label
var _results_body: Label
@@ -79,6 +86,7 @@ var over_match: bool = false:
func _init() -> void:
name = "Menus"
PadInput.install_menu_actions()
set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT)
theme = MenuTheme.make()
backdrop = MenuBackdrop.new()
@@ -208,7 +216,11 @@ func _unhandled_input(event: InputEvent) -> void:
return
if not listening_for.is_empty():
var code: int = KeyBindings.code_of_event(event)
if code == KEY_ESCAPE:
var pad: InputEventJoypadButton = event as InputEventJoypadButton
if pad != null and pad.pressed and (pad.button_index == JOY_BUTTON_B or pad.button_index == JOY_BUTTON_START):
back()
get_viewport().set_input_as_handled()
elif code == KEY_ESCAPE:
back()
get_viewport().set_input_as_handled()
elif code != 0:
@@ -497,6 +509,7 @@ func _build_settings() -> void:
var controls_scroll: ScrollContainer = ScrollContainer.new()
controls_scroll.name = "Controls"
controls_scroll.horizontal_scroll_mode = ScrollContainer.SCROLL_MODE_DISABLED
controls_scroll.follow_focus = true
_tabs.add_child(controls_scroll)
var controls: VBoxContainer = VBoxContainer.new()
controls.size_flags_horizontal = Control.SIZE_EXPAND_FILL
@@ -527,6 +540,38 @@ func _build_settings() -> void:
_invert.toggled.connect(func(on: bool) -> void: settings.mouse.invert_y = on)
_row(mouse, "Invert up and down", _invert)
var pad_scroll: ScrollContainer = ScrollContainer.new()
pad_scroll.name = "Gamepad"
pad_scroll.horizontal_scroll_mode = ScrollContainer.SCROLL_MODE_DISABLED
pad_scroll.follow_focus = true
_tabs.add_child(pad_scroll)
var pad_tab: VBoxContainer = VBoxContainer.new()
pad_tab.size_flags_horizontal = Control.SIZE_EXPAND_FILL
pad_tab.add_theme_constant_override("separation", 10)
pad_scroll.add_child(pad_tab)
_pad_speed = _slider(InputSettings.MIN_PAD_SENSITIVITY, InputSettings.MAX_PAD_SENSITIVITY, 0.05)
_pad_speed.value_changed.connect(func(value: float) -> void: settings.mouse.pad_sensitivity = value)
_slider_row(pad_tab, "Stick look speed", _pad_speed)
_aim_assist = CheckButton.new()
_aim_assist.toggled.connect(func(on: bool) -> void: settings.mouse.aim_assist = on)
_row(pad_tab, "Aim assist", _aim_assist)
var assist_note: Label = _note(pad_tab)
assist_note.text = "Aim assist slows the stick across an opponent in plain sight and, while aiming, eases towards them. It never acts on the mouse. Speed while aiming and Invert (Mouse tab) apply to the stick too."
# The layout in two columns of what and which.
var layout: GridContainer = GridContainer.new()
layout.columns = 4
layout.add_theme_constant_override("h_separation", 14)
layout.add_theme_constant_override("v_separation", 2)
pad_tab.add_child(layout)
for pair: Array in PadInput.LAYOUT:
for index: int in 2:
var cell: Label = Label.new()
cell.text = String(pair[index])
cell.add_theme_font_size_override("font_size", FONT_SMALL)
if index == 1:
cell.add_theme_color_override("font_color", Palette.GILT_DEEP)
layout.add_child(cell)
var graphics: VBoxContainer = _tab("Graphics")
_quality = OptionButton.new()
for index: int in GameSettings.QUALITY_NAMES.size():
@@ -560,6 +605,34 @@ func _build_settings() -> void:
_max_fps.item_selected.connect(func(index: int) -> void: settings.max_fps = GameSettings.FRAME_CAPS[index])
_row(display, "Frame limit", _max_fps)
var access: VBoxContainer = _tab("Access")
_vision = OptionButton.new()
for index: int in Palette.VISION_NAMES.size():
_vision.add_item(Palette.VISION_NAMES[index], index)
_vision.item_selected.connect(func(index: int) -> void:
settings.vision = index
save_settings())
_row(access, "Colour vision", _vision)
_ui_scale = OptionButton.new()
for index: int in GameSettings.UI_SCALES.size():
_ui_scale.add_item("%d%%" % roundi(GameSettings.UI_SCALES[index] * 100.0), index)
_ui_scale.item_selected.connect(func(index: int) -> void:
settings.ui_scale = GameSettings.UI_SCALES[index]
save_settings())
_row(access, "Interface size", _ui_scale)
_captions = CheckButton.new()
_captions.toggled.connect(func(on: bool) -> void:
settings.captions = on
save_settings())
_row(access, "Captions for sounds", _captions)
_reduce_motion = CheckButton.new()
_reduce_motion.toggled.connect(func(on: bool) -> void:
settings.reduce_motion = on
save_settings())
_row(access, "Reduce motion", _reduce_motion)
var access_note: Label = _note(access)
access_note.text = "Colour vision changes the build preview, danger marks and your own marks to colours told apart with that kind of colour blindness. Captions name the sounds that matter (the tide, gunfire, footsteps, building) and which way they came from. Reduce motion makes the zoom when aiming smaller and slower and the flash when you're hurt gentler."
_binding_note = _note(column)
_binding_note.text = "Choose an action to change its key."
_tabs.tab_changed.connect(func(tab: int) -> void: _binding_note.visible = tab == 0)
@@ -626,7 +699,13 @@ func _refresh_controls() -> void:
_window_mode.selected = settings.window_mode
_vsync.set_pressed_no_signal(settings.vsync)
_max_fps.selected = maxi(GameSettings.FRAME_CAPS.find(settings.max_fps), 0)
for slider: HSlider in [_sensitivity, _aim_scale, _volumes["master"], _volumes["music"], _volumes["effects"]]:
_pad_speed.set_value_no_signal(settings.mouse.pad_sensitivity)
_aim_assist.set_pressed_no_signal(settings.mouse.aim_assist)
_vision.selected = settings.vision
_ui_scale.selected = maxi(GameSettings.UI_SCALES.find(settings.ui_scale), 0)
_captions.set_pressed_no_signal(settings.captions)
_reduce_motion.set_pressed_no_signal(settings.reduce_motion)
for slider: HSlider in [_sensitivity, _aim_scale, _pad_speed, _volumes["master"], _volumes["music"], _volumes["effects"]]:
(slider.get_meta("readout") as Callable).call(slider.value)
_refresh_bindings()
+9
View File
@@ -0,0 +1,9 @@
[gd_scene load_steps=2 format=3]
[ext_resource type="Script" path="res://test/capture/camera_scene.gd" id="1"]
[node name="CaptureCameraAim" type="Node3D"]
script = ExtResource("1")
yaw_degrees = 20.0
aiming = true
reduce_motion = true
+3
View File
@@ -6,6 +6,8 @@ extends "res://test/capture/smoke_scene.gd"
@export var yaw_degrees: float = 0.0
@export var pitch_degrees: float = -8.0
@export var aiming: bool = false
## A13: the calmer aim zoom of the reduce-motion setting.
@export var reduce_motion: bool = false
func _add_camera() -> void:
@@ -19,6 +21,7 @@ func _add_camera() -> void:
camera.yaw = deg_to_rad(yaw_degrees)
camera.pitch = deg_to_rad(pitch_degrees)
camera.aiming = aiming
camera.rig.reduce_motion = reduce_motion
if aiming:
camera.rig.aim_blend = 1.0
add_child(camera)
+8
View File
@@ -0,0 +1,8 @@
[gd_scene load_steps=2 format=3]
[ext_resource type="Script" path="res://test/capture/client_scene.gd" id="1"]
[node name="CaptureClient" type="Node3D"]
script = ExtResource("1")
stage = "build"
vision = 1
@@ -0,0 +1,8 @@
[gd_scene load_steps=2 format=3]
[ext_resource type="Script" path="res://test/capture/client_scene.gd" id="1"]
[node name="CaptureClient" type="Node3D"]
script = ExtResource("1")
stage = "build_refused"
vision = 1
+8
View File
@@ -0,0 +1,8 @@
[gd_scene load_steps=2 format=3]
[ext_resource type="Script" path="res://test/capture/client_scene.gd" id="1"]
[node name="CaptureClient" type="Node3D"]
script = ExtResource("1")
stage = "hud"
captions = true
+9
View File
@@ -0,0 +1,9 @@
[gd_scene load_steps=2 format=3]
[ext_resource type="Script" path="res://test/capture/client_scene.gd" id="1"]
[node name="CaptureClient" type="Node3D"]
script = ExtResource("1")
stage = "hud"
captions = true
ui_scale = 1.3
+23
View File
@@ -24,6 +24,11 @@ const LIMIT_ROUNDS: int = 200 * Tuning.TICK_RATE_HZ
@export var stage: String = "barge"
@export var match_seed: int = 2
@export var bots: int = 23
## A13: a colour-vision set (Palette.VISION_*), captions for the sounds of the last
## second before the picture, and the interface size.
@export var vision: int = 0
@export var captions: bool = false
@export var ui_scale: float = 1.0
var _loop: ServerLoop
var _net: NetServer
@@ -32,6 +37,8 @@ var _session: ClientSession
func _ready() -> void:
Palette.vision = vision
get_tree().root.content_scale_factor = ui_scale
var rules: MatchRules = MatchRules.new()
rules.max_players = bots + 1
rules.lobby_ticks = 6
@@ -104,6 +111,22 @@ func _ready() -> void:
return
basin_text += downed_text
_session.hud.fade_feed = false
if captions:
# A second of play with its sound, which is what the captions hear.
_session.settings.captions = true
# Play on until something worth a caption is heard (bots' gunfire carries far),
# for up to 20 seconds.
for _frame: int in 20 * Tuning.TICK_RATE_HZ:
if _session.captions.lines().size() >= 2:
break
_game.poll()
_loop.run_tick()
_game.after_tick()
_session.pump(DT)
_session.sound.update(_session.game, _session.mirror.own_id, _session.view.camera.global_position, DT)
_session._hear_captions(DT)
if _session.captions.lines().is_empty():
push_error("client capture: nothing was captioned")
_session.hud.show_state(_session.hud_state())
_session.view.settle()
var others: int = 0
+9
View File
@@ -0,0 +1,9 @@
[gd_scene load_steps=2 format=3]
[ext_resource type="Script" path="res://test/capture/menu_scene.gd" id="1"]
[node name="CaptureMenu" type="Control"]
script = ExtResource("1")
screen = "main"
over_match = false
ui_scale = 1.3
+3
View File
@@ -8,9 +8,12 @@ extends Control
@export var screen: String = "main"
@export var over_match: bool = false
@export var settings_tab: int = 0
## A13: the interface size (GameSettings.UI_SCALES).
@export var ui_scale: float = 1.0
func _ready() -> void:
get_tree().root.content_scale_factor = ui_scale
set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT)
if over_match:
var stand_in: MenuBackdrop = MenuBackdrop.new()
+9
View File
@@ -0,0 +1,9 @@
[gd_scene load_steps=2 format=3]
[ext_resource type="Script" path="res://test/capture/menu_scene.gd" id="1"]
[node name="CaptureMenu" type="Control"]
script = ExtResource("1")
screen = "settings"
over_match = false
settings_tab = 6
+9
View File
@@ -0,0 +1,9 @@
[gd_scene load_steps=2 format=3]
[ext_resource type="Script" path="res://test/capture/menu_scene.gd" id="1"]
[node name="CaptureMenu" type="Control"]
script = ExtResource("1")
screen = "settings"
over_match = false
settings_tab = 2
+10
View File
@@ -0,0 +1,10 @@
[gd_scene load_steps=2 format=3]
[ext_resource type="Script" path="res://test/capture/menu_scene.gd" id="1"]
[node name="CaptureMenu" type="Control"]
script = ExtResource("1")
screen = "settings"
over_match = false
settings_tab = 6
ui_scale = 1.3
+93
View File
@@ -0,0 +1,93 @@
extends TestCase
## A13: aim assist slows the stick across an opponent in sight and, while aiming,
## eases towards them; never through cover, never for the mouse, and only when on.
const EYE: Vector3 = Vector3(100.0, 10.0, 100.0)
## An opponent `metres` ahead (yaw 0 looks along +z), `degrees` to the left.
static func ahead(metres: float, degrees: float) -> Vector3:
var angle: float = deg_to_rad(degrees)
return EYE + Vector3(sin(angle), 0.0, cos(angle)) * metres
func test_only_opponents_near_the_look_and_in_range_count() -> void:
var targets: Array[Vector3] = [ahead(30.0, 20.0), ahead(30.0, 3.0), ahead(200.0, 0.5)]
var found: Dictionary = AimAssist.nearest(EYE, 0.0, 0.0, targets)
assert_false(found.is_empty())
assert_eq(found["point"], targets[1], "the one 3 degrees off, not the far or wide ones")
var none: Array[Vector3] = [ahead(30.0, 20.0)]
assert_true(AimAssist.nearest(EYE, 0.0, 0.0, none).is_empty())
func test_cover_hides_an_opponent() -> void:
var targets: Array[Vector3] = [ahead(30.0, 2.0)]
var walled: Callable = func(_from: Vector3, _to: Vector3) -> bool: return false
assert_true(AimAssist.nearest(EYE, 0.0, 0.0, targets, walled).is_empty())
func test_friction_is_strongest_at_the_centre() -> void:
assert_eq(AimAssist.friction({}), 1.0)
var centre: float = AimAssist.friction(AimAssist.nearest(EYE, 0.0, 0.0, [ahead(30.0, 0.0)] as Array[Vector3]))
var edge: float = AimAssist.friction(AimAssist.nearest(EYE, 0.0, 0.0, [ahead(30.0, 5.0)] as Array[Vector3]))
assert_near(centre, AimAssist.FRICTION, 0.01)
assert_true(edge > centre and edge < 1.0)
func test_pull_turns_towards_and_never_past() -> void:
var target: Vector3 = ahead(30.0, 2.0)
var found: Dictionary = AimAssist.nearest(EYE, 0.0, 0.0, [target] as Array[Vector3])
var step: Vector2 = AimAssist.pull(EYE, 0.0, 0.0, found, 0.1)
assert_true(step.x > 0.0, "turns left, towards it")
assert_true(step.x <= AimAssist.PULL_RADIANS_PER_SECOND * 0.1 + 0.0001, "no faster than the limit")
var yaw: float = 0.0
for _frame: int in 200:
found = AimAssist.nearest(EYE, yaw, 0.0, [target] as Array[Vector3])
yaw = AimAssist.pull(EYE, yaw, 0.0, found, 0.05).x
assert_true(yaw <= deg_to_rad(2.0) + 0.0001, "never past the opponent: %f" % rad_to_deg(yaw))
func test_through_client_input_only_for_the_pad_and_only_when_on() -> void:
var targets: Array[Vector3] = [ahead(30.0, 3.0)]
# The pad, aiming and moving the stick a little: the look is drawn left.
var input: ClientInput = _aiming_pad(targets)
input.handle(TestPad.axis(JOY_AXIS_RIGHT_Y, 0.4), false)
for _frame: int in 30:
input.poll(1.0 / 60.0)
var assisted: float = angle_difference(0.0, input.yaw)
assert_true(assisted > 0.002, "pulled towards the opponent: %f" % assisted)
# The same with assist off: no sideways pull at all.
input = _aiming_pad(targets)
input.settings.aim_assist = false
input.handle(TestPad.axis(JOY_AXIS_RIGHT_Y, 0.4), false)
for _frame: int in 30:
input.poll(1.0 / 60.0)
assert_near(angle_difference(0.0, input.yaw), 0.0, 0.00001, "off means off")
# The mouse with the pad set aside: no pull either.
input = _aiming_pad(targets)
var key: InputEventKey = InputEventKey.new()
key.physical_keycode = KEY_W
key.pressed = true
input.handle(key, true)
var motion: InputEventMouseMotion = InputEventMouseMotion.new()
motion.relative = Vector2(0.0, -4.0)
input.handle(motion, true)
input.poll(1.0 / 60.0)
assert_near(angle_difference(0.0, input.yaw), 0.0, 0.00001, "never for the mouse")
func _aiming_pad(targets: Array[Vector3]) -> ClientInput:
var input: ClientInput = ClientInput.new()
input.eye = EYE
input.targets = targets
input.handle(TestPad.axis(JOY_AXIS_TRIGGER_LEFT, 1.0), false)
return input
class TestPad:
static func axis(which: JoyAxis, value: float) -> InputEventJoypadMotion:
var event: InputEventJoypadMotion = InputEventJoypadMotion.new()
event.axis = which
event.axis_value = value
return event
+1
View File
@@ -0,0 +1 @@
uid://btsy5xwlv3q3e
+77
View File
@@ -0,0 +1,77 @@
extends TestCase
## A13: captions name the sounds that matter, say which way they came from, don't
## stack repeats, leave out the player's own sounds, and fade.
const EYE: Vector3 = Vector3(50.0, 5.0, 50.0)
static func cue(sound: String, at: Variant = null) -> Dictionary:
return {"sound": sound, "category": "x", "spatial": at != null, "at": at if at != null else Vector3.ZERO, "volume_db": 0.0, "pitch": 1.0}
func test_sides_follow_the_look() -> void:
# Yaw 0 looks along +z; growing yaw turns left, towards +x.
assert_eq(Captions.side_of(EYE, 0.0, EYE + Vector3(0.0, 0.0, 10.0)), "ahead")
assert_eq(Captions.side_of(EYE, 0.0, EYE + Vector3(0.0, 0.0, -10.0)), "behind")
assert_eq(Captions.side_of(EYE, 0.0, EYE + Vector3(10.0, 0.0, 0.0)), "left")
assert_eq(Captions.side_of(EYE, 0.0, EYE + Vector3(-10.0, 0.0, 0.0)), "right")
assert_eq(Captions.side_of(EYE, PI * 0.5, EYE + Vector3(10.0, 0.0, 0.0)), "ahead", "turned to face +x")
func test_key_sounds_have_words_and_the_rest_none() -> void:
for sound: String in ["foghorn", "bell", "surge", "lighthouse", "hurt", "keg_blast", "step_sand_1", "shot_dock_carbine", "break_stone", "build_driftwood"]:
assert_ne(Captions.words_for(sound), "", sound)
for sound: String in ["amb_surf", "ui_click", "music_drone", "land"]:
assert_eq(Captions.words_for(sound), "", sound)
func test_a_frame_of_cues_becomes_lines() -> void:
var captions: Captions = Captions.new()
var cues: Array[Dictionary] = [cue("foghorn"), cue("shot_harpoon_gun", EYE + Vector3(-30.0, 0.0, 0.0)), cue("amb_wind")]
captions.hear(cues, EYE, 0.0, EYE, 0.016)
assert_eq(captions.lines(), ["Foghorn: the sea is rising", "Gunfire, right"] as Array[String])
func test_repeats_refresh_and_the_newest_is_last() -> void:
var captions: Captions = Captions.new()
var behind: Vector3 = EYE + Vector3(0.0, 0.0, -8.0)
captions.hear([cue("step_grass_1", behind)] as Array[Dictionary], EYE, 0.0, EYE, 0.016)
captions.hear([cue("bell")] as Array[Dictionary], EYE, 0.0, EYE, 0.016)
captions.hear([cue("step_grass_2", behind)] as Array[Dictionary], EYE, 0.0, EYE, 0.016)
assert_eq(captions.lines(), ["Ship's bell", "Footsteps, behind"] as Array[String])
func test_the_players_own_and_far_steps_are_left_out() -> void:
var captions: Captions = Captions.new()
var cues: Array[Dictionary] = [
cue("step_rock_1", EYE + Vector3(0.5, 0.0, 0.0)),
cue("shot_dock_carbine", EYE + Vector3(0.0, 1.2, 0.3)),
cue("step_rock_2", EYE + Vector3(0.0, 0.0, 40.0)),
]
captions.hear(cues, EYE, 0.0, EYE, 0.016)
assert_eq(captions.lines().size(), 0, "%s" % [captions.lines()])
func test_lines_fade_and_never_pile_up() -> void:
var captions: Captions = Captions.new()
var cues: Array[Dictionary] = [cue("foghorn"), cue("bell"), cue("surge"), cue("hurt"), cue("keg_blast", EYE + Vector3(0.0, 0.0, 20.0))]
captions.hear(cues, EYE, 0.0, Vector3.INF, 0.016)
assert_eq(captions.lines().size(), Captions.MAX_LINES)
assert_eq(captions.lines()[Captions.MAX_LINES - 1], "Powder keg blast, ahead")
var none: Array[Dictionary] = []
captions.hear(none, EYE, 0.0, Vector3.INF, Captions.SECONDS + 0.1)
assert_eq(captions.lines().size(), 0)
func test_the_hud_shows_them() -> void:
var hud: Hud = Hud.new()
var state: HudState = HudState.new()
state.captions = ["Gunfire, left"] as Array[String]
hud.show_state(state)
var found: bool = false
for label: Node in hud.find_children("*", "Label", true, false):
if (label as Label).text == "[ Gunfire, left ]":
found = true
assert_true(found, "a caption line on the HUD")
hud.free()
+1
View File
@@ -0,0 +1 @@
uid://bakugnl3g23rk
+47
View File
@@ -269,3 +269,50 @@ func test_browse_options() -> void:
assert_eq(ClientConfig.parse(PackedStringArray(["--browse"])).lan_port, ServerConfig.DEFAULT_PORT)
assert_false(ClientConfig.parse(PackedStringArray(["--browse", "--lan-target=somewhere"])).is_valid())
assert_false(ClientConfig.parse(PackedStringArray(["--browse", "--connect=192.0.2.7"])).is_valid())
static func _pad_button(index: JoyButton, pressed: bool) -> InputEventJoypadButton:
var event: InputEventJoypadButton = InputEventJoypadButton.new()
event.button_index = index
event.pressed = pressed
return event
static func _pad_axis(which: JoyAxis, value: float) -> InputEventJoypadMotion:
var event: InputEventJoypadMotion = InputEventJoypadMotion.new()
event.axis = which
event.axis_value = value
return event
func test_a_gamepad_plays_through_the_session() -> void:
# A13: the script lands the player; then a simulated pad takes over.
session.play_offline(4, 3)
for frame: int in 60 * 150:
session.pump(FRAME)
if session.game.playing() and _own().drop_state == Drop.NONE and _own().on_ground:
break
assert_true(session.game.playing() and _own().drop_state == Drop.NONE, "landed")
session.input.autoplay = false
session.input.yaw = 0.0
var start: Vector3 = _own().position
session.input.handle(_pad_axis(JOY_AXIS_LEFT_Y, -1.0), false)
for frame: int in 60 * 2:
session.pump(FRAME)
var walked: float = Vector2(_own().position.x - start.x, _own().position.z - start.z).length()
assert_true(walked > 3.0, "the left stick walked the player %.1f m" % walked)
assert_false(session.input.targets.is_empty(), "aim assist sees the bots as opponents")
session.input.handle(_pad_axis(JOY_AXIS_LEFT_Y, 0.0), false)
session.input.handle(_pad_button(JOY_BUTTON_RIGHT_SHOULDER, true), false)
session.input.handle(_pad_button(JOY_BUTTON_RIGHT_SHOULDER, false), false)
for frame: int in 10:
session.pump(FRAME)
assert_eq(_own().selected, 1, "the right bumper picked the first slot")
# Start asks for the pause menu, as Escape does.
var asked: Array[bool] = [false]
session.pause_requested.connect(func() -> void: asked[0] = true)
var tree: SceneTree = Engine.get_main_loop() as SceneTree
tree.root.add_child(session)
session._unhandled_input(_pad_button(JOY_BUTTON_START, true))
assert_true(asked[0], "Start asked for the pause menu")
tree.root.remove_child(session)
+67
View File
@@ -209,3 +209,70 @@ func test_renderer_fallback_notice() -> void:
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()
+22
View File
@@ -214,3 +214,25 @@ func test_a_down_in_duos_travels_in_the_feed_and_reads_as_a_down() -> void:
assert_eq(lines[0]["text"], "You knocked Thole down")
assert_eq(lines[1]["text"], "Brine is down")
assert_eq(HudState.feed_lines(told["entries"], -3)[0]["text"], "Ada knocked you down")
func test_the_bottom_row_never_overlaps_at_any_interface_size() -> void:
# A13: the interface size makes the canvas narrower; the hotbar must stay clear of
# the vitals and the materials, and inside the screen.
for scale: float in GameSettings.UI_SCALES:
var hud: Hud = Hud.new()
var canvas: Vector2 = Vector2(1280.0, 720.0) / scale
hud.size = canvas
var state: HudState = HudState.new()
state.playing = true
for index: int in 6:
state.slots.append({"id": "", "name": "Slot", "count": 0, "rounds": 0, "reserve": 0, "magazine": 0, "tier": -1, "selected": index == 0, "empty": true})
hud.show_state(state)
var bar: Rect2 = hud.hotbar_rect()
assert_true(bar.position.x >= hud.vitals_rect().end.x + 1.0, "at %d%% the hotbar starts after the vitals: %s" % [roundi(scale * 100.0), bar])
var materials_left: float = canvas.x - Hud.MARGIN - hud.materials_rect().size.x
assert_true(bar.end.x <= materials_left - 1.0, "at %d%% the hotbar ends before the materials (%.0f, %.0f)" % [roundi(scale * 100.0), bar.end.x, materials_left])
assert_true(bar.size.x >= 6.0 * Hud.SLOT_MIN_WIDTH, "slots no narrower than the least")
if is_equal_approx(scale, 1.0):
assert_near(bar.get_center().x, canvas.x * 0.5, 1.0, "centred at 100%")
hud.free()
+183
View File
@@ -0,0 +1,183 @@
extends TestCase
## A13: every in-game action works from a gamepad, driven here by simulated pad
## events through ClientInput exactly as the session passes them on.
var input: ClientInput
func before_each() -> void:
super.before_each()
input = ClientInput.new()
static func button(index: JoyButton, pressed: bool = true) -> InputEventJoypadButton:
var event: InputEventJoypadButton = InputEventJoypadButton.new()
event.button_index = index
event.pressed = pressed
return event
static func axis(which: JoyAxis, value: float) -> InputEventJoypadMotion:
var event: InputEventJoypadMotion = InputEventJoypadMotion.new()
event.axis = which
event.axis_value = value
return event
func _tap(index: JoyButton) -> void:
input.handle(button(index, true), false)
input.handle(button(index, false), false)
func _command() -> PlayerCommand:
input.poll(1.0 / 60.0)
return input.command(1)
func test_the_left_stick_moves_with_a_dead_zone() -> void:
input.handle(axis(JOY_AXIS_LEFT_Y, -0.1), false)
input.poll(0.016)
assert_eq(input.move, Vector2.ZERO, "inside the dead zone")
input.handle(axis(JOY_AXIS_LEFT_Y, -1.0), false)
input.poll(0.016)
assert_near(input.move.y, 1.0, 0.001, "stick up walks forward")
input.handle(axis(JOY_AXIS_LEFT_Y, 0.0), false)
input.handle(axis(JOY_AXIS_LEFT_X, 0.6), false)
input.poll(0.016)
assert_true(input.move.x > 0.4 and input.move.x < 0.6, "part way right is part speed: %s" % input.move)
assert_near(input.move.y, 0.0, 0.001)
func test_every_held_action_has_a_button_or_trigger() -> void:
var cases: Array[Array] = [
[button(JOY_BUTTON_A), PlayerCommand.BUTTON_JUMP],
[button(JOY_BUTTON_B), PlayerCommand.BUTTON_CROUCH],
[button(JOY_BUTTON_X), PlayerCommand.BUTTON_RELOAD],
[button(JOY_BUTTON_Y), PlayerCommand.BUTTON_INTERACT],
[button(JOY_BUTTON_DPAD_DOWN), PlayerCommand.BUTTON_DROP],
[axis(JOY_AXIS_TRIGGER_RIGHT, 1.0), PlayerCommand.BUTTON_FIRE],
[axis(JOY_AXIS_TRIGGER_LEFT, 1.0), PlayerCommand.BUTTON_AIM],
]
for case: Array in cases:
input = ClientInput.new()
input.handle(case[0], false)
input.poll(0.016)
assert_eq(input.buttons, int(case[1]), "%s holds %d" % [(case[0] as InputEvent).as_text(), case[1]])
# A trigger only lightly touched isn't held.
input = ClientInput.new()
input.handle(axis(JOY_AXIS_TRIGGER_RIGHT, 0.2), false)
input.poll(0.016)
assert_eq(input.buttons, 0)
func test_clicking_the_left_stick_sprints_until_you_stop() -> void:
input.handle(axis(JOY_AXIS_LEFT_Y, -1.0), false)
_tap(JOY_BUTTON_LEFT_STICK)
assert_true(_command().buttons & PlayerCommand.BUTTON_SPRINT != 0, "sprinting")
assert_true(_command().buttons & PlayerCommand.BUTTON_SPRINT != 0, "still sprinting")
input.handle(axis(JOY_AXIS_LEFT_Y, 0.0), false)
assert_eq(_command().buttons & PlayerCommand.BUTTON_SPRINT, 0, "stopping ends the sprint")
input.handle(axis(JOY_AXIS_LEFT_Y, -1.0), false)
assert_eq(_command().buttons & PlayerCommand.BUTTON_SPRINT, 0, "walking again doesn't sprint")
func test_bumpers_pick_slots_and_pieces_and_the_dpad_the_material() -> void:
_tap(JOY_BUTTON_RIGHT_SHOULDER)
assert_eq(input.slot, 1)
_tap(JOY_BUTTON_LEFT_SHOULDER)
_tap(JOY_BUTTON_LEFT_SHOULDER)
assert_eq(input.slot, Inventory.slot_count(), "wraps round to the last slot")
_tap(JOY_BUTTON_RIGHT_STICK)
assert_true(input.build_mode, "clicking the right stick enters build mode")
_tap(JOY_BUTTON_RIGHT_SHOULDER)
assert_eq(input.build_kind, StructureSet.FLOOR)
_tap(JOY_BUTTON_LEFT_SHOULDER)
_tap(JOY_BUTTON_LEFT_SHOULDER)
assert_eq(input.build_kind, StructureSet.KINDS.size() - 1)
_tap(JOY_BUTTON_DPAD_RIGHT)
assert_eq(input.material, Materials.STONE)
_tap(JOY_BUTTON_DPAD_LEFT)
_tap(JOY_BUTTON_DPAD_LEFT)
assert_eq(input.material, Materials.NAMES.size() - 1)
var command: PlayerCommand = _command()
assert_true(command.buttons & PlayerCommand.BUTTON_BUILD != 0)
_tap(JOY_BUTTON_RIGHT_STICK)
assert_false(input.build_mode)
_tap(JOY_BUTTON_DPAD_UP)
assert_true(input.map_open, "D-pad up opens the chart")
_tap(JOY_BUTTON_DPAD_UP)
assert_false(input.map_open)
func test_a_held_button_acts_once() -> void:
input.handle(button(JOY_BUTTON_RIGHT_SHOULDER, true), false)
input.handle(button(JOY_BUTTON_RIGHT_SHOULDER, true), false)
assert_eq(input.slot, 1, "a repeat of a held button isn't a second press")
func test_the_right_stick_turns_by_time_and_settings() -> void:
input.handle(axis(JOY_AXIS_RIGHT_X, 1.0), false)
input.poll(0.5)
var turned: float = angle_difference(input.yaw, 0.0)
assert_near(turned, PadInput.LOOK_RADIANS_PER_SECOND * 0.5, 0.001, "full right turns right at the full rate")
input = ClientInput.new()
input.settings.pad_sensitivity = 2.0
input.handle(axis(JOY_AXIS_RIGHT_X, 1.0), false)
input.poll(0.25)
assert_near(angle_difference(input.yaw, 0.0), PadInput.LOOK_RADIANS_PER_SECOND * 0.5, 0.001, "twice the speed")
input = ClientInput.new()
input.handle(axis(JOY_AXIS_RIGHT_Y, -1.0), false)
input.poll(0.1)
assert_true(input.pitch > 0.0, "stick up looks up")
input.settings.invert_y = true
input.poll(0.1)
assert_near(input.pitch, 0.0, 0.0001, "inverted, it looks back down")
# A small push turns much less than in proportion (the response curve).
input = ClientInput.new()
input.handle(axis(JOY_AXIS_RIGHT_X, 0.5), false)
input.poll(1.0)
assert_true(angle_difference(input.yaw, 0.0) < PadInput.LOOK_RADIANS_PER_SECOND * 0.35)
func test_the_pad_is_active_until_the_keyboard_is_used() -> void:
assert_false(input.pad.active)
_tap(JOY_BUTTON_A)
assert_true(input.pad.active)
var key: InputEventKey = InputEventKey.new()
key.physical_keycode = KEY_W
key.pressed = true
input.handle(key, true)
assert_false(input.pad.active)
func test_release_forgets_what_was_held() -> void:
input.handle(axis(JOY_AXIS_TRIGGER_RIGHT, 1.0), false)
input.handle(button(JOY_BUTTON_A), false)
input.pad.release()
input.poll(0.016)
assert_eq(input.buttons, 0)
func test_every_layout_entry_names_a_real_input() -> void:
for action: String in ["jump", "crouch", "reload", "interact", "fire", "aim", "sprint", "build", "map", "drop", "material", "slot_next", "pause", "forward"]:
assert_ne(PadInput.describe(action), "?", action)
var named: Array[String] = []
for pair: Array in PadInput.LAYOUT:
named.append(String(pair[1]))
for which: String in PadInput.NAMES.values():
assert_true(named.has(which) or which == "D-pad right" or which == "D-pad left", "%s is in the listed layout" % which)
func test_menus_accept_and_go_back_on_the_pad() -> void:
PadInput.install_menu_actions()
PadInput.install_menu_actions()
var accept: int = 0
for event: InputEvent in InputMap.action_get_events("ui_accept"):
if event is InputEventJoypadButton and (event as InputEventJoypadButton).button_index == JOY_BUTTON_A:
accept += 1
assert_eq(accept, 1, "South chooses, added once")
assert_true(button(JOY_BUTTON_B).is_action_pressed("ui_cancel"), "East goes back")
assert_true(button(JOY_BUTTON_START).is_action_pressed("ui_cancel"), "Start goes back")
assert_true(button(JOY_BUTTON_DPAD_DOWN).is_action_pressed("ui_down"), "the D-pad moves the focus")
assert_true(axis(JOY_AXIS_LEFT_Y, 1.0).is_action_pressed("ui_down"), "so does the left stick")
+1
View File
@@ -0,0 +1 @@
uid://bf3khtxcj4xe8
+78
View File
@@ -60,3 +60,81 @@ func _scripts_under(dir_path: String) -> Array[String]:
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())
+96
View File
@@ -300,3 +300,99 @@ func test_main_menu_shows_the_version_and_commit() -> void:
assert_not_null(build, "the main menu has a build line")
if build != null:
assert_eq(build.text, "Version " + BuildInfo.describe())
static func _pad(index: JoyButton, pressed: bool = true) -> InputEventJoypadButton:
var event: InputEventJoypadButton = InputEventJoypadButton.new()
event.button_index = index
event.pressed = pressed
return event
## A press and release through Input, the way a real pad's events arrive (some
## controls, such as sliders and tab bars, follow the pad through Input's state).
func _pad_tap(index: JoyButton) -> void:
Input.parse_input_event(_pad(index, true))
Input.flush_buffered_events()
await tree.process_frame
Input.parse_input_event(_pad(index, false))
Input.flush_buffered_events()
await tree.process_frame
func test_the_menus_work_from_a_gamepad() -> void:
menus.show_screen("main", false)
await tree.process_frame
await _pad_tap(JOY_BUTTON_DPAD_DOWN)
var focused: Control = menus.get_viewport().gui_get_focus_owner()
assert_true(focused is Button and (focused as Button).text == "Tutorial", "the D-pad moved the focus down: %s" % focused)
var asked: Array[bool] = [false]
menus.tutorial_requested.connect(func() -> void: asked[0] = true)
await _pad_tap(JOY_BUTTON_A)
assert_true(asked[0], "South chose the focused button")
# Into settings and through its tabs, then back with East.
menus.show_screen("main", false)
await tree.process_frame
for _step: int in 3:
await _pad_tap(JOY_BUTTON_DPAD_DOWN)
assert_eq((menus.get_viewport().gui_get_focus_owner() as Button).text, "Settings")
await _pad_tap(JOY_BUTTON_A)
assert_eq(menus.current, "settings")
var tabs: TabContainer = menus._tabs
var first: int = tabs.current_tab
await _pad_tap(JOY_BUTTON_DPAD_RIGHT)
assert_eq(tabs.current_tab, first + 1, "the D-pad changes tab")
await _pad_tap(JOY_BUTTON_B)
assert_eq(menus.current, "main", "East went back")
func test_the_pause_menu_closes_with_start() -> void:
menus.show_screen("pause", false)
await tree.process_frame
var resumed: Array[bool] = [false]
menus.resume_requested.connect(func() -> void: resumed[0] = true)
await _pad_tap(JOY_BUTTON_START)
assert_true(resumed[0])
func test_a_slider_and_a_switch_change_from_the_pad() -> void:
menus.show_screen("settings", false)
await tree.process_frame
menus._tabs.current_tab = 2 # Gamepad
await tree.process_frame
menus._pad_speed.grab_focus()
var before: float = settings_speed()
await _pad_tap(JOY_BUTTON_DPAD_RIGHT)
assert_true(settings_speed() > before, "D-pad right turned the slider up")
menus._aim_assist.grab_focus()
await _pad_tap(JOY_BUTTON_A)
assert_false(menus.settings.mouse.aim_assist, "South switched aim assist off")
func settings_speed() -> float:
return menus.settings.mouse.pad_sensitivity
func test_rebinding_can_be_left_from_the_pad() -> void:
menus.show_screen("settings", false)
await tree.process_frame
menus.listen_for("jump")
await _pad_tap(JOY_BUTTON_B)
assert_eq(menus.listening_for, "", "East stopped listening")
assert_eq(menus.current, "settings", "and stayed on settings")
assert_eq(menus.settings.bindings.code_of("jump"), KEY_SPACE)
func test_the_access_tab_changes_the_settings() -> void:
menus.show_screen("settings", false)
await tree.process_frame
menus._vision.select(Palette.VISION_RED_GREEN)
menus._vision.item_selected.emit(Palette.VISION_RED_GREEN)
menus._ui_scale.item_selected.emit(2)
menus._captions.toggled.emit(true)
menus._reduce_motion.toggled.emit(true)
assert_eq(menus.settings.vision, Palette.VISION_RED_GREEN)
assert_eq(menus.settings.ui_scale, GameSettings.UI_SCALES[2])
assert_true(menus.settings.captions)
assert_true(menus.settings.reduce_motion)
assert_eq(GameSettings.load_from(PATH).vision, Palette.VISION_RED_GREEN, "saved at once")