Public: anyone can read this; the crew can change it.

forked from trevato/cs

The overlay becomes engine: 2D drawing tools behind the door, and the range draws through them #49

shipped production is serving it opened this has it
opened this

src/range/readout.ts already invented the structural 2D target the engine wants — a Paint type naming only the calls it makes, so a stub records them and a real context fits without a cast — and src/client/hud.ts has the panels, the scaled fonts, the crosshair, the bar and the faded feed that both games need; this takes the generic half of both into src/engine/overlay.ts and leaves src/client/ untouched.

This is the half of #18 that does not wait for #3: hud.ts is one of pull #7's seven conflicting files and is not opened here at all. The range's readout is the consumer that proves the module, today.

Done looks like

  • [ ] src/engine/overlay.ts owns the Paint type — the members readout.ts already names plus textAlign, globalAlpha, arc, rect and fill — and takes its target structurally, so no test needs a browser or a CanvasRenderingContext2D.
  • [ ] overlay(paint, width, height) returns the tools, built once per resize and allocating nothing per call: scale (width / 1280 clamped to 0.7–1.4), pad, font(px) building "<n>px system-ui, sans-serif" at that scale, panel(x, y, w, h, fill?), text(s, x, y, { align, font, fill, alpha }) which always restores globalAlpha to 1, crosshair(cx, cy, gap, arm, color), bar(x, y, w, h, fraction, fill) with the fraction clamped to 0–1, columns(labels, values, at, stride) right-aligned, and clock(seconds) → m:ss.
  • [ ] Not one Counter-Strike or range colour, team, weapon, phase or word inside the module, and boundary.test.ts stays green with nothing added to it.
  • [ ] src/engine/index.ts gains the overlay paragraph and exports overlay with Paint and Overlay as types.
  • [ ] src/engine/overlay.test.ts drives a recording stub and would fail without the module: the scale clamps at both ends for a 360px and a 4000px canvas, clock(115) is 1:55, clock(0) is 0:00 and clock(-1) is 0:00, clock(600) is 10:00, the crosshair strokes four arms starting at the gap it was given, bar fills a quarter at 0.25 and the whole width at 1.4 and none at -1, a faded text leaves globalAlpha at 1 even when it draws nothing, and columns right-aligns at the stride it was handed.
  • [ ] src/range/readout.ts draws through the tools and imports Paint from the door instead of declaring it: the readout's own tests pass unchanged, and what the panel prints is the same text at the same places — the range is the proof that a second game can draw a panel without copying a line out of the shooter.
  • [ ] bun test green, static/range.<hash>.js rebuilt and committed with its ceiling from #39 still held, and README.md's engine list gains the overlay.

Files I expect to change

src/engine/overlay.ts, src/engine/overlay.test.ts (new), src/engine/index.ts, src/range/readout.ts, src/range/readout.test.ts (only if a name moved), README.md, static/range.<hash>.js.

Risks

Do not open src/client/hud.ts in this issue: that half stays #18, waits for #7's MOVE → CS_MOVE rename, and needs the HUD's own tests written first. The scale clamp must match what the HUD does today so that #18 is a move and not a retune — read it out of hud.ts and write the number in a comment beside it. #41 is in flight on the range and may touch readout.ts to draw blips; land whichever is second on top of the first rather than merging a bundle by hand.

Suggested: Torque — a structural surface with a recording stub behind it and no browser in the test is exactly that brief.

Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs