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

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

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

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

Closes #53

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

95 lines
4.1 KiB
GDScript

## Player-adjustable look settings, saved in the user's config file.
class_name InputSettings
extends RefCounted
const DEFAULT_PATH: String = "user://settings.cfg"
const SECTION: String = "input"
## Radians of turn per pixel of mouse motion at sensitivity 1.0.
const RADIANS_PER_PIXEL: float = 0.0025
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):
mouse_sensitivity = clampf(value, MIN_SENSITIVITY, MAX_SENSITIVITY)
## Multiplies the sensitivity while aiming down sights.
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.
## Moving the mouse right turns right; moving it up looks up, unless invert_y is set.
func apply_mouse(relative: Vector2, yaw: float, pitch: float, aiming: bool) -> Vector2:
var scale: float = RADIANS_PER_PIXEL * mouse_sensitivity
if aiming:
scale *= aim_sensitivity_scale
var vertical: float = relative.y if invert_y else -relative.y
var new_yaw: float = fposmod(yaw - relative.x * scale, TAU)
var new_pitch: float = clampf(pitch + vertical * scale, -PITCH_LIMIT, PITCH_LIMIT)
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)
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.
static func load_from(path: String = DEFAULT_PATH) -> InputSettings:
var settings: InputSettings = InputSettings.new()
var config: ConfigFile = ConfigFile.new()
if config.load(path) != OK:
return settings
var sensitivity: Variant = config.get_value(SECTION, "mouse_sensitivity", 1.0)
if (sensitivity is float and is_finite(sensitivity)) or sensitivity is int:
settings.mouse_sensitivity = float(sensitivity)
var aim_scale: Variant = config.get_value(SECTION, "aim_sensitivity_scale", 0.6)
if (aim_scale is float and is_finite(aim_scale)) or aim_scale is int:
settings.aim_sensitivity_scale = float(aim_scale)
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