Skip to content

game.ts: 1,742 lines against a target of ~300 #3

Description

@cgreening

src/game/game.ts is 1,742 lines against a stated target of ~300. It is down
from 3,244 and is now the last named size debt in tools/sizes.mjs alongside
npc.ts.

It is no longer the urgent problem it was — the browser shell came out
(engine/shell.ts), so the file is portable and testable, and
test/game.test.ts flies it. This is decomposition for readability now, not to
unblock anything.

Measured by section:

section lines
header + fields + constructor 690
input 259
mode transitions 161
per-frame 155
combat 115
contracts 104
autopilots 87
HUD 84
world lifecycle 81

Two cuts look real:

  1. the input section (259) — key handling and the command dispatch table.
    controls.ts already owns the bindings; this owns execution.
  2. the HUD driver (84)renderHud, updateSight, aimBeams. Pure
    presentation, and hud-binding.ts already owns the frame it paints.

That lands it near 1,300. Getting to ~300 would mean moving the five host
tables and the mode transitions too, and it is worth checking at that point
whether the target is still the right one — the apply* methods ARE the
orchestrator's job, and moving them would scatter the step order.

Caution: the file is 34% prose. The comments carry the step order and the
reasons for it; they should move with the code they explain, not be dropped.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions