mirror of
https://github.com/kuhyx/testsAndMisc.git
synced 2026-11-19 04:14:23 +01:00
The 82-line ENEMY_SPECS table and its kind unions are data, not vocabulary -- that is the block you edit to balance the game. Moved to enemies.ts (143). statusKinds.ts (25) is not cosmetic: enemy specs name the status they inflict and the survivor carries seconds-remaining per status, so leaving StatusKind in types.ts would have made types.ts and enemies.ts mutually dependent. It imports nothing, so the graph is statusKinds <- enemies <- types. 14 files repointed by script rather than by hand, splitting each types import across the three owning modules by symbol. The tests cannot catch a mistyped stat -- they assert behaviour, not the balance table, so a wrong enemy hp passes 160 tests at 100% coverage. Checked separately: 191 numeric pairs before, 191 after, compared as sorted multisets, identical. check and build both pass; bundle 210.11 kB, same as baseline. No reverse_survivors file is over the 250-line cap now. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011w2Pj4Ek3ZNMQVYcFHgXDY
36 lines
1.4 KiB
TypeScript
36 lines
1.4 KiB
TypeScript
import type { Survivor } from './types'
|
|
import type { StatusKind } from './statusKinds'
|
|
import { STATUS_ORDER } from './statusKinds'
|
|
|
|
/**
|
|
* 1 while the timer is live, 0 once it has expired.
|
|
*
|
|
* Deliberately arithmetic rather than `timer > 0`: every consumer of this value
|
|
* multiplies by it, so an `if` here would add a branch pair per status per
|
|
* consumer — the coverage gate is 100 % and those branches buy nothing.
|
|
* Timers only reach 0 via `Math.max(0, t - dt)`, so the domain is [0, inf).
|
|
*/
|
|
export const isOn = (timer: number): number => Math.min(1, Math.ceil(timer))
|
|
|
|
/** `active` while the timer runs, 1 when idle. Branch-free blend. */
|
|
export const factor = (timer: number, active: number): number =>
|
|
1 - isOn(timer) * (1 - active)
|
|
|
|
export const tickStatuses = (sv: Survivor, dt: number): void => {
|
|
for (const kind of STATUS_ORDER) {
|
|
sv.statuses[kind] = Math.max(0, sv.statuses[kind] - dt)
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Refresh-not-stack: re-applying extends the timer, never compounds it.
|
|
* This is what caps a horde's total lockdown at one status duration — the
|
|
* guarantee is structural, not a tuned number.
|
|
*
|
|
* A 0-second duration is a no-op, which is how non-debuffing enemies call this
|
|
* unconditionally without needing a guard branch.
|
|
*/
|
|
export const applyStatus = (sv: Survivor, kind: StatusKind, seconds: number): void => {
|
|
sv.statuses[kind] = Math.max(sv.statuses[kind], seconds)
|
|
}
|