Files
tidewall/src/client/input_settings.gd
T
claudeandClaude Opus 5.5 c504551b28 A10: Menus and settings
The game now opens on a main menu when it has a window: practice
against bots (count and skill), join a server (by address, or from a
LAN search list), settings, and quit. In a match, Escape brings up a
pause menu (the match goes on) with settings and leave; when a match
the player was in ends, a results screen shows their place,
eliminations and the last of the feed.

- KeyBindings: every action rebindable to a key or mouse button.
  bind() refuses an input another action uses and names it; Escape is
  reserved. ClientInput reads keys through the bindings.
- GameSettings: bindings, mouse, graphics (quality preset and the
  print pass), audio (master, music and effects buses), display
  (window mode, vsync, frame cap), name, last server and practice
  choices, saved in user://settings.cfg. Missing, unreadable or
  corrupt files and bad values fall back to defaults, value by value;
  hand-edited key clashes are repaired on load.
- Menus (src/ui): paper-and-ink panels, brass focus edge, keyboard
  navigable; a drawn sea-and-tide-post backdrop, or an ink wash over
  a match. AppShell runs menus and the session.
- LocalServer takes a bot difficulty.
- make menu-captures renders every screen.

Closes #50

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

61 lines
2.6 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)
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
## 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)
func save(path: String = DEFAULT_PATH) -> Error:
var config: ConfigFile = ConfigFile.new()
config.load(path) # Keep other sections; a missing file is fine.
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)
## 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
return settings