Files
transcience/src/core/game_opts.gd
T
claude 4765bbce28
ci / verify (push) Successful in 47s
Stage 2: accounts, characters, permadeath, levels and experience
Identity is shaped like Steamworks so swapping to it is one subclass and no
schema change: the client presents an opaque ticket, the server validates it
into a stable 64-bit account id, and nothing downstream sees anything else.
LocalAuthProvider takes any ticket at face value -- insecure on purpose, and
labelled as such everywhere, because the point is the shape rather than the
security. Do not ship it.

Characters persist as JSON keyed by account. Account ids are written as decimal
strings because they are 64-bit and JSON numbers are doubles, which would
silently round them. A corrupt store aborts the server rather than starting
empty: starting empty looks like it worked and then saves over every character
on the first level-up.

Levels 1-15, +10 max health each, level DERIVED from lifetime experience rather
than stored beside it, so a hand-edited save cannot produce a level 12 character
with a level 3's experience. Experience is shared undivided across everyone
alive in the instance -- splitting it would make bringing a friend cost you
progress. A level-up heals by what it added, so gaining one mid-fight is relief
rather than a bar that moved further from full.

Death is permanent and unbinds the character entirely: no "return to the hub as
the character who just died", because the run is over. The record is retired,
never deleted. The five-character cap counts LIVING characters only -- counting
the dead would lock a player out of their own account after five deaths.

Verified by tools/diag_progression.tscn, which drives the real server through
kill -> xp -> level -> health and death -> retire -> roster. The bot smoke test
cannot cover that: bots are poor shots and rarely kill anything. Writing it
caught two real ordering bugs -- the death event was dispatched before the
payload that tells the player they died, and the dead character stayed bound to
the peer.

Also added --account and --store so several clients and test runs can coexist
on one machine. The smoke test now uses a scratch store; without it a rerun
resumed the previous run's characters and "a character was created" quietly
stopped being true.

193 tests. check.sh, test.sh, smoke.sh, diag_progression and diag_prediction
all pass.
2026-09-04 00:44:34 +02:00

101 lines
3.4 KiB
GDScript

class_name GameOpts
extends RefCounted
## Process-wide options parsed from the command line.
##
## These are per-machine settings and must never affect the simulation -- if a
## value would change how the world evolves, it belongs in [SimConfig] so server
## and client cannot disagree about it.
static var is_server: bool = false
static var port: int = Protocol.DEFAULT_PORT
static var host_address: String = "127.0.0.1"
static var player_name: String = "player"
## Replaces keyboard input with a scripted loop so CI can play the game with no
## display. See `tools/smoke.sh`.
static var bot_client: bool = false
## Quit after this many physics ticks. 0 = run forever.
static var autoquit_ticks: int = 0
## Skip the menu and connect straight away. Implied by --bot.
static var autojoin: bool = false
## Bot harness only: gracefully disconnect after this many ticks inside a
## dungeon, the way the in-game menu's "Disconnect" button does. Lets the smoke
## test cover the clean-exit path as well as a hard kill -- both must be caught
## by the same server-side escape channel.
static var bot_leave_after: int = 0
## Skip the menu and start a listen server (host + local player).
static var listen: bool = false
## Server-side dev switch: new dungeons open straight onto the boss, skipping
## the trash waves. For iterating on a pattern without clearing two waves first.
static var boss_rush: bool = false
## Dev switch: depth of newly opened dungeons, which drives map size. Depth
## progression is a later-stage concern; this makes big maps testable now.
static var dungeon_depth: int = 1
## Override the local account id. Two clients on one machine would otherwise
## read the same user:// id file, land on the same account, and fight over one
## roster of characters -- which is exactly what the smoke test does. A real
## identity provider makes this unnecessary.
static var account_override: int = 0
## Where the server keeps characters. Overridable so a test run cannot read or
## write the characters someone is actually playing -- and so repeated runs
## start from a known state instead of resuming each other's progress.
static var store_path: String = CharacterStore.SAVE_PATH
static var parsed: bool = false
static func parse(argv: PackedStringArray = PackedStringArray()) -> void:
if argv.is_empty():
argv = OS.get_cmdline_user_args()
var i := 0
while i < argv.size():
match argv[i]:
"--server":
is_server = true
"--bot":
bot_client = true
autojoin = true
"--join":
autojoin = true
"--leave-after":
i += 1
if i < argv.size():
bot_leave_after = int(argv[i])
"--listen":
listen = true
"--boss-rush":
boss_rush = true
"--account":
i += 1
if i < argv.size():
account_override = int(argv[i])
"--store":
i += 1
if i < argv.size():
store_path = argv[i]
"--depth":
i += 1
if i < argv.size():
dungeon_depth = int(argv[i])
"--port":
i += 1
if i < argv.size():
port = int(argv[i])
"--host":
i += 1
if i < argv.size():
host_address = argv[i]
"--name":
i += 1
if i < argv.size():
player_name = argv[i]
"--autoquit":
i += 1
if i < argv.size():
autoquit_ticks = int(argv[i])
"--verbose":
GameLog.min_level = GameLog.Level.DEBUG
"--quiet":
GameLog.min_level = GameLog.Level.WARN
i += 1
GameLog.role_tag = "server" if is_server else "client"
parsed = true