mirror of
https://github.com/kuhyx/testsAndMisc.git
synced 2026-11-20 01:54:30 +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
162 lines
4.3 KiB
TypeScript
162 lines
4.3 KiB
TypeScript
import { waveCost } from './director'
|
|
import type { EdgeId, GameState, PowerKind, Status, UpgradeId } from './types'
|
|
import type { BossKind, UnitKind } from './enemies'
|
|
import type { StatusKind } from './statusKinds'
|
|
import { EDGE_NAMES, EDGE_ORDER, ENERGY_CAP, POWER_COST, POWER_NAMES, POWER_ORDER } from './types'
|
|
import { BOSS_ORDER, BOSS_UNLOCK_AT, ENEMY_SPECS, UNIT_ORDER } from './enemies'
|
|
import { STATUS_LABELS, STATUS_ORDER } from './statusKinds'
|
|
|
|
export type BossPhase = 'locked' | 'cooling' | 'ready'
|
|
|
|
/** Ambush summons a fixed cheap unit, so the bar needs no unit-selection mode. */
|
|
export const AMBUSH_UNIT: UnitKind = 'rusher'
|
|
|
|
export interface UnitButton {
|
|
kind: UnitKind
|
|
name: string
|
|
cost: number
|
|
affordable: boolean
|
|
}
|
|
|
|
export interface BossButton {
|
|
kind: BossKind
|
|
name: string
|
|
cost: number
|
|
phase: BossPhase
|
|
unlockIn: number
|
|
cooldown: number
|
|
affordable: boolean
|
|
}
|
|
|
|
export interface UpgradeEntry {
|
|
n: number
|
|
id: UpgradeId
|
|
}
|
|
|
|
export interface PowerButton {
|
|
kind: PowerKind
|
|
name: string
|
|
cost: number
|
|
cooldown: number
|
|
ready: boolean
|
|
affordable: boolean
|
|
}
|
|
|
|
export interface EdgeButton {
|
|
edge: EdgeId
|
|
name: string
|
|
active: boolean
|
|
}
|
|
|
|
export interface StatusChip {
|
|
kind: StatusKind
|
|
label: string
|
|
seconds: number
|
|
}
|
|
|
|
export interface HudSnapshot {
|
|
status: Status
|
|
t: number
|
|
duration: number
|
|
energy: number
|
|
energyCap: number
|
|
waveIndex: number
|
|
waveCost: number
|
|
waveAffordable: boolean
|
|
survivorHp: number
|
|
survivorMaxHp: number
|
|
survivorLevel: number
|
|
kills: number
|
|
upgrades: UpgradeEntry[]
|
|
units: UnitButton[]
|
|
bosses: BossButton[]
|
|
statuses: StatusChip[]
|
|
powers: Record<PowerKind, PowerButton>
|
|
edges: EdgeButton[]
|
|
frenzyActive: boolean
|
|
riftSeconds: number
|
|
ambushKind: UnitKind
|
|
outcomeTime: number
|
|
}
|
|
|
|
const bossPhase = (state: GameState, kind: BossKind): BossPhase => {
|
|
if (state.t < BOSS_UNLOCK_AT[kind]) {
|
|
return 'locked'
|
|
}
|
|
if (state.director.bossCooldowns[kind] > 0) {
|
|
return 'cooling'
|
|
}
|
|
return 'ready'
|
|
}
|
|
|
|
/** Ambush also pays for the unit it summons; the others carry no surcharge. */
|
|
const POWER_SURCHARGE: Record<PowerKind, number> = {
|
|
ambush: ENEMY_SPECS[AMBUSH_UNIT].cost,
|
|
frenzy: 0,
|
|
rift: 0,
|
|
}
|
|
|
|
const powerButtons = (state: GameState): Record<PowerKind, PowerButton> => {
|
|
const out = {} as Record<PowerKind, PowerButton>
|
|
for (const kind of POWER_ORDER) {
|
|
const cost = POWER_COST[kind] + POWER_SURCHARGE[kind]
|
|
out[kind] = {
|
|
kind,
|
|
name: POWER_NAMES[kind],
|
|
cost,
|
|
cooldown: Math.ceil(state.director.powerCooldowns[kind]),
|
|
ready: state.director.powerCooldowns[kind] === 0,
|
|
affordable: state.director.energy >= cost,
|
|
}
|
|
}
|
|
return out
|
|
}
|
|
|
|
export const snapshotOf = (state: GameState): HudSnapshot => ({
|
|
status: state.status,
|
|
t: state.t,
|
|
duration: state.duration,
|
|
energy: state.director.energy,
|
|
energyCap: ENERGY_CAP,
|
|
waveIndex: state.director.waveIndex,
|
|
waveCost: waveCost(state.director.waveIndex),
|
|
waveAffordable: state.director.energy >= waveCost(state.director.waveIndex),
|
|
survivorHp: Math.max(0, state.survivor.hp),
|
|
survivorMaxHp: state.survivor.maxHp,
|
|
survivorLevel: state.survivor.level,
|
|
kills: state.survivor.kills,
|
|
upgrades: state.upgrades.map((id, i) => ({ n: i + 1, id })).slice(-3),
|
|
statuses: STATUS_ORDER
|
|
.map((kind) => ({
|
|
kind,
|
|
label: STATUS_LABELS[kind],
|
|
seconds: Math.ceil(state.survivor.statuses[kind]),
|
|
}))
|
|
.filter((chip) => chip.seconds > 0),
|
|
units: UNIT_ORDER.map((kind) => ({
|
|
kind,
|
|
name: ENEMY_SPECS[kind].name,
|
|
cost: ENEMY_SPECS[kind].cost,
|
|
affordable: state.director.energy >= ENEMY_SPECS[kind].cost,
|
|
})),
|
|
bosses: BOSS_ORDER.map((kind) => ({
|
|
kind,
|
|
name: ENEMY_SPECS[kind].name,
|
|
cost: ENEMY_SPECS[kind].cost,
|
|
phase: bossPhase(state, kind),
|
|
unlockIn: Math.max(0, Math.ceil(BOSS_UNLOCK_AT[kind] - state.t)),
|
|
cooldown: Math.ceil(state.director.bossCooldowns[kind]),
|
|
affordable: state.director.energy >= ENEMY_SPECS[kind].cost,
|
|
})),
|
|
powers: powerButtons(state),
|
|
edges: EDGE_ORDER.map((edge) => ({
|
|
edge,
|
|
name: EDGE_NAMES[edge],
|
|
active: state.director.riftTimer > 0 && state.director.riftEdge === edge,
|
|
})),
|
|
frenzyActive: state.director.frenzyTimer > 0,
|
|
riftSeconds: Math.ceil(state.director.riftTimer),
|
|
ambushKind: AMBUSH_UNIT,
|
|
outcomeTime: state.outcomeTime,
|
|
})
|