diff --git a/CHANGELOG.md b/CHANGELOG.md index cb925fd..ee9972f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,12 @@ All notable changes to this project will be documented in this file. - Save slots in the main menu and the pause panel name the ship systems the saved run has picked. - Fast-kill bonus: beat a boss under its par time and you score 200 points for every second left on the clock, shown as FAST KILL next to the kill. Pausing never costs you any of it. + + +- The refit bay lists your ship systems next to the upgrades once you have one. Select one to see its three options again, with the current one marked, and pick another: changing here is free, as often as you like, with no wait. Escape, or picking the current one again, keeps it. The next sector flies with your choice, and the autosave and your checkpoints store it. + + + ### Changed - The pause panel's `SYSTEMS:` line is replaced by the SYSTEMS tab. diff --git a/README.md b/README.md index 412b6c9..23b6106 100644 --- a/README.md +++ b/README.md @@ -106,7 +106,7 @@ Bought during the planet intermission screen using score as currency: - **Fire Rate** — improves firing speed - **Shield** — increases hit absorption - **AEGIS Picket** — installs and overclocks automatic flank-defense turrets -- **Ship systems** — free picks after sectors 2, 5 and 8 that change how the ship plays: a main gun (Lance, Scatter, Seekers), a support system (Magnet, Surge Core, Wingman) and a doctrine (Overdrive, Bulwark, Salvager). Picks can be changed mid-run: the main gun on Q or the touch swap button, the others from the pause panel +- **Ship systems** — free picks after sectors 2, 5 and 8 that change how the ship plays: a main gun (Lance, Scatter, Seekers), a support system (Magnet, Surge Core, Wingman) and a doctrine (Overdrive, Bulwark, Salvager). Picks can be changed freely at any later refit bay, and mid-run: the main gun on Q or the touch swap button, the others from the pause panel - **A different run every time** — each run has its own sky and may fly sectors mirrored; RETRY replays the same run, NEW RUN starts a fresh one Some upgrades unlock later in the campaign and use progression caps so the run scales in a controlled way. diff --git a/docs/level-design.md b/docs/level-design.md index 71c7622..389b1ea 100644 --- a/docs/level-design.md +++ b/docs/level-design.md @@ -24,7 +24,7 @@ shields recharge on every respawn. Levels 5–10 add payoff without adding player inputs: - **AEGIS Picket** becomes purchasable after Level 4. Its fixed flank turrets trim chaff with flat-damage bolts while the main gun remains the dominant damage source. Pickets never target bosses. -- **Ship systems** are free one-of-three picks at the refit bay after sectors 2, 5 and 8 (`config/shipSystems.ts`). They change how the ship plays rather than how hard it hits, and are balanced by measurement: each main gun trades single-target damage for one strength and scored inside the standard gun's run-to-run spread in sector 5. Nothing is offered in sectors 1–2, which stay a gentle introduction. A system works without input; the only new input is changing one. Once a slot has a pick the player may cycle it to another option of that slot: the main gun mid-flight on Q or the touch swap key, support and doctrine from the pause panel's SYSTEMS tab. A gun change costs `GUN_SWAP` (0.5 s of silence, 2 s before the next change, both on the gameplay clock), so swapping is a decision and never a free best-of-all-guns. Feedback is a brief name flash over the ship; there is no persistent panel. The current pick is saved with the run. +- **Ship systems** are free one-of-three picks at the refit bay after sectors 2, 5 and 8 (`config/shipSystems.ts`). They change how the ship plays rather than how hard it hits, and are balanced by measurement: each main gun trades single-target damage for one strength and scored inside the standard gun's run-to-run spread in sector 5. Nothing is offered in sectors 1–2, which stay a gentle introduction. A system works without input; the only new input is changing one. Once a slot has a pick the player may change it to another option of that slot: freely at every later refit bay (the picks sit beside the upgrade cards and reopen the pick dialog, which Escape dismisses), the main gun mid-flight on Q or the touch swap key, and support and doctrine from the pause panel's SYSTEMS tab. A gun change in flight costs `GUN_SWAP` (0.5 s of silence, 2 s before the next change, both on the gameplay clock), so swapping mid-fight is a decision and never a free best-of-all-guns; between sectors, at the refit bay, a change is free and has no cooldown. In flight, feedback is a brief name flash over the ship; there is no persistent panel. The current pick is saved with the run. - **Run variation** comes from one seed per run (`systems/runVariation.ts`, `systems/gameplayRandom.ts`). It decides the wave choices, whether each sector is mirrored left to right, and the sky. Two rules keep scores comparable: the sky is looks only, and the only layout change is the mirror, which is as hard by symmetry. Never vary wave order, enemy counts or timing by seed. RETRY keeps the seed; NEW RUN draws a new one. Enemies, asteroids and wormholes each draw from their own seeded stream, so one cannot shift another's choices; how far a run gets through a stream still depends on play. Enemy jitter and pickup drops stay unseeded because they depend on how the fight goes. - **Marked Aces** are sparse authored variants of existing enemies. Their gilded treatment signals 2× durability, 4× score, and exactly one guaranteed power-up. - **Boss volleys are telegraphed.** For the last 400 ms before every volley the boss's core swells and its hardpoints flash white. Bosses have no stun or bonus-damage window; fights are paced by the wind-up and each attack's cooldown. diff --git a/src/config/shipSystems.ts b/src/config/shipSystems.ts index 6cad8b1..261da0d 100644 --- a/src/config/shipSystems.ts +++ b/src/config/shipSystems.ts @@ -1,7 +1,7 @@ /** * Ship systems: free picks that change how the ship plays, offered at the refit bay. Once picked, a slot - * can be changed to another of its options mid-run: the main gun on the swap key or touch button - * (`GUN_SWAP` keeps it a decision), support and doctrine from the pause panel. Nothing else needs input, + * can be changed to another of its options: freely at any later refit bay, and mid-run the main gun on + * the swap key or touch button (`GUN_SWAP` keeps it a decision), support and doctrine from the pause panel. Nothing else needs input, * so touch and keyboard stay equal. Stat upgrades are bought separately. */ export type MainGunId = 'lance' | 'scatter' | 'seekers'; @@ -26,6 +26,8 @@ interface ShipSystemOption { export interface ShipSystemSlotDef { slot: ShipSystemSlot; title: string; + /** For narrow spaces, e.g. three systems side by side at the refit bay. */ + shortTitle: string; /** Offered at the refit bay after clearing this sector (and later, until a pick is made). */ offeredAfterLevel: number; options: readonly [ShipSystemOption, ShipSystemOption, ShipSystemOption]; @@ -35,6 +37,7 @@ const SHIP_SYSTEM_SLOTS: readonly ShipSystemSlotDef[] = [ { slot: 'gun', title: 'MAIN GUN', + shortTitle: 'GUN', offeredAfterLevel: 2, options: [ { id: 'lance', name: 'LANCE', description: 'Slower shots that pierce every ship in a line.' }, @@ -45,6 +48,7 @@ const SHIP_SYSTEM_SLOTS: readonly ShipSystemSlotDef[] = [ { slot: 'support', title: 'SUPPORT SYSTEM', + shortTitle: 'SUPPORT', offeredAfterLevel: 5, options: [ { id: 'magnet', name: 'MAGNET', description: 'Pickups drift toward your ship.' }, @@ -59,6 +63,7 @@ const SHIP_SYSTEM_SLOTS: readonly ShipSystemSlotDef[] = [ { slot: 'late', title: 'COMBAT DOCTRINE', + shortTitle: 'DOCTRINE', offeredAfterLevel: 8, options: [ { id: 'overdrive', name: 'OVERDRIVE', description: 'Every step of your score chain speeds up the gun.' }, @@ -70,8 +75,14 @@ const SHIP_SYSTEM_SLOTS: readonly ShipSystemSlotDef[] = [ export const NO_SHIP_SYSTEMS: ShipSystems = { gun: null, support: null, late: null }; +/** A slot's title and options, e.g. to offer them again at the refit bay. */ +export function getShipSystemSlot(slot: ShipSystemSlot): ShipSystemSlotDef { + // Every slot is authored above, so the lookup cannot miss. + return SHIP_SYSTEM_SLOTS.find((def) => def.slot === slot)!; +} + function optionIds(slot: ShipSystemSlot): readonly ShipSystemId[] { - return SHIP_SYSTEM_SLOTS.find((def) => def.slot === slot)?.options.map((option) => option.id) ?? []; + return getShipSystemSlot(slot).options.map((option) => option.id); } /** Clamps untrusted persisted picks to the authored options. */ @@ -104,14 +115,15 @@ interface PickedShipSystem { slot: ShipSystemSlot; /** The slot's title, e.g. `MAIN GUN`. */ title: string; + shortTitle: string; option: ShipSystemOption; } -/** The run's picks in slot order, for the pause panel; empty slots are left out. */ +/** The run's picks in slot order, for the pause panel and the refit bay; empty slots are left out. */ export function describePickedShipSystems(systems: ShipSystems): PickedShipSystem[] { return SHIP_SYSTEM_SLOTS.flatMap((def) => { const option = def.options.find((candidate) => candidate.id === systems[def.slot]); - return option ? [{ slot: def.slot, title: def.title, option }] : []; + return option ? [{ slot: def.slot, title: def.title, shortTitle: def.shortTitle, option }] : []; }); } diff --git a/src/scenes/PlanetIntermissionScene.ts b/src/scenes/PlanetIntermissionScene.ts index c3b30a3..d816096 100644 --- a/src/scenes/PlanetIntermissionScene.ts +++ b/src/scenes/PlanetIntermissionScene.ts @@ -1,4 +1,9 @@ -import { getPendingShipSystemSlot, setShipSystem } from '../config/shipSystems'; +import { + getPendingShipSystemSlot, + getShipSystemSlot, + setShipSystem, + type ShipSystemSlotDef, +} from '../config/shipSystems'; import { createSystemPickDialog, type SystemPickDialog } from './planetIntermission/systemPickDialog'; import Phaser from 'phaser'; @@ -92,6 +97,7 @@ export class PlanetIntermissionScene extends Phaser.Scene { : `Campaign complete. Final score ${score}.`, evaluations: this.evaluate(), onBuy: (key) => this.tryBuyUpgrade(key), + onSwapSystem: (slot) => this.openSystemPick(getShipSystemSlot(slot)), onContinue: () => this.continueToNextLevel(), }); @@ -109,17 +115,32 @@ export class PlanetIntermissionScene extends Phaser.Scene { this.offerShipSystemPick(); } - /** A free ship-system pick is offered before the shop whenever one is due; the run waits for it. */ + /** + * A free ship-system pick is offered before the shop whenever one is due; the run waits for it. Once + * none is due, the bay lists the run's picks so the player can swap them. + */ private offerShipSystemPick(): void { const slot = this.isFinalMissionComplete ? null : getPendingShipSystemSlot(this.state.level, this.state.systems); - this.view?.setInert(slot !== null); - if (!slot) return; - this.pickDialog = createSystemPickDialog(slot, (id) => { - this.state.systems = setShipSystem(this.state.systems, slot.slot, id); - setPlayerState(this.registry, this.state); - audioManager.playUi('uiConfirm'); + if (slot) { + this.openSystemPick(slot); + return; + } + if (!this.isFinalMissionComplete) this.view?.showSystems(this.state.systems); + this.view?.setInert(false); + } + + /** The pick dialog for `slot`: its first pick, or a free swap when the slot already has one. */ + private openSystemPick(slot: ShipSystemSlotDef): void { + const current = this.state.systems[slot.slot]; + this.view?.setInert(true); + this.pickDialog = createSystemPickDialog(slot, current, (id) => { this.pickDialog?.destroy(); this.pickDialog = undefined; + if (id !== current) { + this.state.systems = setShipSystem(this.state.systems, slot.slot, id); + setPlayerState(this.registry, this.state); + audioManager.playUi('uiConfirm'); + } else audioManager.playUi(); // A late start can owe more than one pick: offer the next before the shop opens. this.offerShipSystemPick(); }); diff --git a/src/scenes/planetIntermission/refitView.ts b/src/scenes/planetIntermission/refitView.ts index e3c63c6..f581b9e 100644 --- a/src/scenes/planetIntermission/refitView.ts +++ b/src/scenes/planetIntermission/refitView.ts @@ -1,5 +1,6 @@ import type { LevelConfig } from '../../config/LevelsConfig'; import type { UpgradeEvaluation, UpgradeKey } from '../../config/UpgradesConfig'; +import { describePickedShipSystems, type ShipSystems, type ShipSystemSlot } from '../../config/shipSystems'; import { colorToHexString, mixColor } from '../../utils/colorUtils'; import { h, liveRegion, mountUiLayer, releaseFocus } from '../../ui/dom'; import { findArrowFocusIndex, findLinearFocusIndex, findNextPurchasableAfter } from './navigation'; @@ -111,6 +112,48 @@ function createUpgradeCard(evaluation: UpgradeEvaluation, onBuy: (key: UpgradeKe }; } +const SYSTEM_SLOTS: readonly ShipSystemSlot[] = ['gun', 'support', 'late']; + +interface SystemKey { + slot: ShipSystemSlot; + button: HTMLButtonElement; + refresh: (systems: ShipSystems) => void; +} + +/** + * One picked system: its slot over its name, and what it does where there is room. Narrow keys swap in + * the slot's short title. Opens the swap dialog. + */ +function createSystemKey(slot: ShipSystemSlot, onSwap: (slot: ShipSystemSlot) => void): SystemKey { + const title = h('span', { className: 'refit-system__slot ui-ellipsis' }); + const shortTitle = h('span', { className: 'refit-system__slot refit-system__slot--short ui-ellipsis' }); + const name = h('span', { className: 'refit-system__name ui-ellipsis' }); + const description = h('span', { className: 'refit-system__detail ui-ellipsis', id: `refit-system-${slot}` }); + const button = h( + 'button', + { type: 'button', className: 'ui-btn refit-system', 'aria-describedby': description.id }, + title, + shortTitle, + name, + description + ); + button.addEventListener('click', () => onSwap(slot)); + return { + slot, + button, + refresh(systems) { + const picked = describePickedShipSystems(systems).find((system) => system.slot === slot); + button.hidden = !picked; + if (!picked) return; + title.textContent = picked.title; + shortTitle.textContent = picked.shortTitle; + name.textContent = picked.option.name; + description.textContent = picked.option.description; + button.setAttribute('aria-label', `Swap ${picked.title.toLowerCase()}, now ${picked.option.name}`); + }, + }; +} + interface RefitViewConfig { levelConfig: LevelConfig; profile: PlanetIntermissionProfile; @@ -123,6 +166,7 @@ interface RefitViewConfig { summary: string; evaluations: UpgradeEvaluation[]; onBuy: (key: UpgradeKey) => void; + onSwapSystem: (slot: ShipSystemSlot) => void; onContinue: () => void; } @@ -131,9 +175,14 @@ export interface RefitView { planetSlot: HTMLElement; /** New balance and evaluations after a purchase: refreshes every card and announces the result. */ refresh: (credits: number, evaluations: UpgradeEvaluation[], purchased: UpgradeKey, message: string) => void; + /** Lists the run's picked systems beside the cards, each a key that swaps it; nothing before the first pick. */ + showSystems: (systems: ShipSystems) => void; /** Arrow keys and Enter / Space while no card holds focus; returns whether the key was used. */ handleUnfocusedKey: (code: string) => boolean; - /** Puts the whole bay out of reach of pointer and keyboard while a dialog is open over it. */ + /** + * Puts the whole bay out of reach of pointer and keyboard while a dialog is open over it; when it + * comes back, focus returns to the system key that opened the dialog. + */ setInert: (inert: boolean) => void; /** Fades the UI out under the warp. */ leave: () => void; @@ -151,6 +200,19 @@ export function createRefitView(config: RefitViewConfig): RefitView { const cards = config.evaluations.map((evaluation) => createUpgradeCard(evaluation, config.onBuy)); cards.forEach((card, index) => card.refresh(config.evaluations[index])); const grid = h('div', { className: 'refit__cards' }, ...cards.map((card) => card.button)); + let swapOpener: HTMLButtonElement | null = null; + const systemKeys = SYSTEM_SLOTS.map((slot) => + createSystemKey(slot, (picked) => { + swapOpener = systemKeys.find((key) => key.slot === picked)?.button ?? null; + config.onSwapSystem(picked); + }) + ); + // The systems fill the grid's last cell: beside the odd last card on two columns, a row of their own on one. + const systemsCell = h( + 'div', + { className: 'refit__systems', role: 'group', 'aria-label': 'Ship systems' }, + ...systemKeys.map((key) => key.button) + ); const status = liveRegion(config.summary); const continueButton = h( 'button', @@ -252,6 +314,12 @@ export function createRefitView(config: RefitViewConfig): RefitView { // A card that just capped drops out of the focus order: hand focus to the next one that can buy. if (hadFocus && !next[index].canPurchase) focusCard(findNextPurchasableAfter(purchasable(), index)); }, + showSystems(systems) { + systemKeys.forEach((key) => key.refresh(systems)); + // Appended once there is a pick, so the odd last card keeps spanning the row until then. Only once: + // moving the cell would drop the focus a closed dialog hands back. + if (!systemsCell.isConnected && describePickedShipSystems(systems).length > 0) grid.append(systemsCell); + }, handleUnfocusedKey(code) { if (code !== 'Enter' && code !== 'Space') return moveFocus(code); const first = findLinearFocusIndex(purchasable(), -1, 1); @@ -262,6 +330,9 @@ export function createRefitView(config: RefitViewConfig): RefitView { setInert(inert) { if (inert) releaseFocus(layer); layer.inert = inert; + if (inert) return; + swapOpener?.focus({ preventScroll: true }); + swapOpener = null; }, leave() { releaseFocus(layer); diff --git a/src/scenes/planetIntermission/systemPickDialog.ts b/src/scenes/planetIntermission/systemPickDialog.ts index 494118f..bba87f1 100644 --- a/src/scenes/planetIntermission/systemPickDialog.ts +++ b/src/scenes/planetIntermission/systemPickDialog.ts @@ -6,16 +6,32 @@ export interface SystemPickDialog { } /** - * A free pick of one ship system out of three, shown over the refit bay before any shopping. It is - * modal: the run carries on only once a system is chosen, so nobody skips it by accident. + * A free pick of one ship system out of three, shown over the refit bay. With `current` null it is the + * slot's first pick, offered before any shopping, and modal: the run carries on only once a system is + * chosen, so nobody skips it by accident. With `current` set it is a free swap the player opened: the + * current option is marked and focused, and Escape keeps it (reported as picking it again). */ -export function createSystemPickDialog(slot: ShipSystemSlotDef, onPick: (id: ShipSystemId) => void): SystemPickDialog { +export function createSystemPickDialog( + slot: ShipSystemSlotDef, + current: ShipSystemId | null, + onPick: (id: ShipSystemId) => void +): SystemPickDialog { const options = slot.options.map((option) => { const description = h('span', { className: 'pick__detail', id: `pick-${option.id}-detail` }, option.description); const button = h( 'button', - { type: 'button', className: 'ui-btn pick__option', 'aria-describedby': description.id }, - h('span', { className: 'pick__name' }, option.name), + { + type: 'button', + className: 'ui-btn pick__option', + 'aria-describedby': description.id, + 'aria-pressed': current ? String(option.id === current) : undefined, + }, + h( + 'span', + { className: 'pick__name' }, + option.name, + option.id === current && h('span', { className: 'pick__current', 'aria-hidden': 'true' }, 'CURRENT') + ), description ); button.addEventListener('click', () => onPick(option.id)); @@ -31,21 +47,28 @@ export function createSystemPickDialog(slot: ShipSystemSlotDef, onPick: (id: Shi tabIndex: -1, }, h('div', { className: 'ui-frame', 'aria-hidden': 'true' }), - h('p', { className: 'ui-caption' }, 'NEW SHIP SYSTEM · FREE'), - h('h2', { className: 'ui-heading', id: 'pick-title' }, `CHOOSE YOUR ${slot.title}`), + h('p', { className: 'ui-caption' }, current ? 'SWAP SHIP SYSTEM · FREE' : 'NEW SHIP SYSTEM · FREE'), + h('h2', { className: 'ui-heading', id: 'pick-title' }, `${current ? 'SWAP' : 'CHOOSE'} YOUR ${slot.title}`), h('div', { className: 'pick__options' }, ...options) ); const modal = h('div', { className: 'ui-modal' }, sheet); // Arrow keys and Tab cycle through the three options and never leave the dialog; Enter and Space // pick the focused one natively. modal.addEventListener('keydown', (event) => { + if (event.code === 'Escape' && current) { + // Handled here: the bay behind must not also read Escape as "carry on". + event.preventDefault(); + event.stopPropagation(); + onPick(current); + return; + } const forward = event.code === 'ArrowDown' || event.code === 'ArrowRight' || (event.code === 'Tab' && !event.shiftKey); const backward = event.code === 'ArrowUp' || event.code === 'ArrowLeft' || (event.code === 'Tab' && event.shiftKey); if (!forward && !backward) return; event.preventDefault(); - const current = options.indexOf(document.activeElement as HTMLButtonElement); - const next = options[(current + (forward ? 1 : -1) + options.length) % options.length]; + const focused = options.indexOf(document.activeElement as HTMLButtonElement); + const next = options[(focused + (forward ? 1 : -1) + options.length) % options.length]; next.focus({ preventScroll: true }); // On a short screen the list scrolls: bring the focused option, ring and all, into view. next.scrollIntoView({ block: 'nearest' }); @@ -54,6 +77,10 @@ export function createSystemPickDialog(slot: ShipSystemSlotDef, onPick: (id: Shi // The dialog lives in its own layer above the refit bay; the scene makes the bay inert meanwhile. const layer = mountUiLayer(); layer.append(modal); - options[0].focus({ preventScroll: true }); + // A first pick starts on the first option; a swap starts on the current one. + const currentIndex = slot.options.findIndex((option) => option.id === current); + const initial = options[Math.max(0, currentIndex)]; + initial.focus({ preventScroll: true }); + initial.scrollIntoView({ block: 'nearest' }); return { destroy: () => layer.remove() }; } diff --git a/src/ui/ui.css b/src/ui/ui.css index 977299b..a955e1a 100644 --- a/src/ui/ui.css +++ b/src/ui/ui.css @@ -1781,6 +1781,88 @@ background: rgb(var(--accent-rgb)); } +/* ---------- ship system keys: the run's picks in the grid's last cell, each opening the swap dialog ---------- */ + +.refit__systems { + display: flex; + gap: var(--card-gap); + min-width: 0; +} + +.refit-system.ui-btn { + --cut: var(--card-cut); + --edge: rgb(var(--c-cyan-rgb) / 0.8); + --fill: rgb(10 28 54 / 0.92); + --glow: drop-shadow(0 0 2.5px rgb(var(--c-cyan-rgb) / calc(0.4 * var(--ui-glow)))); + container-type: inline-size; + flex: 1 1 0; + flex-direction: column; + align-items: stretch; + gap: calc(var(--card-rows) - 4px); + height: var(--card-h); + padding: 0 6px 0 12px; + color: #f4fbff; + text-align: left; + text-transform: none; + letter-spacing: 0; +} + +/* The upgrade cards' lit rail and top tint, in the systems' cyan. */ +.refit-system.ui-btn::after { + background: + linear-gradient(rgb(var(--c-cyan-rgb) / 0.95), rgb(var(--c-cyan-rgb) / 0.95)) 0 var(--cut) / 3px 100% no-repeat, + linear-gradient(rgb(var(--c-cyan-rgb) / 0.1) 0 46%, transparent 46%), + var(--fill); +} + +.refit-system.ui-btn:focus-visible { + outline: none; + --edge: var(--c-cyan-bright); + --glow: drop-shadow(0 0 1.5px var(--c-cyan-bright)) drop-shadow(0 0 5px rgb(var(--c-cyan-rgb) / 0.7)); +} + +.refit-system__slot { + font: calc(var(--card-cost) - 1px) / 1 var(--f-mono); + color: var(--c-cyan); +} + +.refit-system__name { + font: 700 var(--card-title) / 1 var(--f-display); +} + +.refit-system__detail { + font-size: calc(var(--card-detail) - 1px); + line-height: 1; + letter-spacing: 0.03em; + color: #b4cbdb; +} + +/* Two or three keys share the cell: no description, the dialog has it. */ +@container (max-width: 239px) { + .refit-system__detail { + display: none; + } +} + +.refit-system__slot--short { + display: none; +} + +/* Three across on a phone or a small window: the short slot title, and the names in the condensed label font. */ +@container (max-width: 139px) { + .refit-system__slot { + display: none; + } + + .refit-system__slot--short { + display: block; + } + + .refit-system__name { + font-family: var(--f-label); + } +} + @keyframes ui-flash { from { filter: brightness(2.2); @@ -1924,6 +2006,20 @@ --frame-fill: 0.78; } + /* A short phone has no spare row for the ship systems: drop the two lines the CONTINUE key repeats... */ + @container layer (max-height: 759px) { + .refit:has(.refit__systems) :is(.refit__caption, .refit__next) { + display: none; + } + } + + /* ...and on the smallest phones the destination line under the planet's name too. */ + @container layer (max-height: 659px) { + .refit:has(.refit__systems) .refit__destination { + display: none; + } + } + @container layer (min-height: 760px) { .refit { --d: min(56cqw, 204px); @@ -1934,6 +2030,10 @@ --m-caption: 10px; --m-cards: 9px; --show-note: block; + } + + /* Once the run has ship systems they take a row of their own: the cards keep the compact size to make room. */ + .refit:not(:has(.refit__systems)) { --card-h: 60px; --card-gap: 7px; --icon: 38px; @@ -2287,3 +2387,21 @@ text-transform: none; color: var(--t-secondary); } + +/* A swap marks the current option with the pressed key's fill and a tag at the end of its name line. */ +.pick__option[aria-pressed='true'] :is(.pick__name, .pick__detail) { + color: inherit; +} + +.pick__option[aria-pressed='true'] .pick__name { + display: flex; + justify-content: space-between; + align-items: center; + align-self: stretch; + gap: 12px; +} + +.pick__current { + font: 12px / 1 var(--f-mono); + letter-spacing: 1.5px; +} diff --git a/tests/e2e/shipSystems.spec.ts b/tests/e2e/shipSystems.spec.ts index 62f5a36..4804d83 100644 --- a/tests/e2e/shipSystems.spec.ts +++ b/tests/e2e/shipSystems.spec.ts @@ -59,6 +59,7 @@ test('a free main-gun pick is offered after sector 2, must be made, and changes await page.evaluate(() => window.__SPACE_EXPLORER_BROWSER_HARNESS__!.showPlanetIntermission(1)); await waitForScene(page, 'PlanetIntermission'); await expect(page.getByRole('dialog')).toHaveCount(0); + await expect(page.getByRole('group', { name: 'Ship systems' })).toHaveCount(0); await page.evaluate(() => window.__SPACE_EXPLORER_BROWSER_HARNESS__!.showPlanetIntermission(2)); const dialog = page.getByRole('dialog', { name: 'CHOOSE YOUR MAIN GUN' }); @@ -77,9 +78,13 @@ test('a free main-gun pick is offered after sector 2, must be made, and changes true ); - // The run waits for the pick: a plain key does not carry on to the next sector. - await page.keyboard.press('KeyX'); + // The run waits for the pick: neither a plain key nor Escape carries on or closes the dialog. Both are + // held across game frames so Phaser would see them. + await page.keyboard.down('KeyX'); + await page.keyboard.down('Escape'); await page.waitForTimeout(600); + await page.keyboard.up('Escape'); + await page.keyboard.up('KeyX'); expect((await snapshot(page)).activeScenes).toContain('PlanetIntermission'); await expect(dialog).toBeVisible(); @@ -112,6 +117,54 @@ test('a free main-gun pick is offered after sector 2, must be made, and changes assertNoBrowserErrors(); }); +test('a picked system can be kept or swapped for free at a later refit bay, and the next sector flies the swap', async ({ + page, + isMobile, + assertNoBrowserErrors, +}) => { + test.setTimeout(120_000); + await startSector(page, 3, 'lance'); + await page.evaluate(() => window.__SPACE_EXPLORER_BROWSER_HARNESS__!.showPlanetIntermission(3)); + await waitForScene(page, 'PlanetIntermission'); + const gun = page.getByRole('group', { name: 'Ship systems' }).getByRole('button', { name: /^Swap main gun/ }); + await expect(gun).toHaveAccessibleName('Swap main gun, now LANCE'); + await expect(gun).toBeInViewport({ ratio: 1 }); + await page.screenshot({ path: test.info().outputPath('refit-systems.png') }); + + // Reopening shows the same three options with the current one marked and focused. Dismissing keeps it: + // Escape on a keyboard, the current option on touch. + const dialog = page.getByRole('dialog', { name: 'SWAP YOUR MAIN GUN' }); + const current = dialog.getByRole('button', { name: /^LANCE/ }); + await gun.click(); + await expect(current).toHaveAttribute('aria-pressed', 'true'); + await expect(current).toBeFocused(); + await expect(dialog.getByRole('button', { name: /^SCATTER/ })).toHaveAttribute('aria-pressed', 'false'); + expect(await page.locator('.refit').evaluate((element) => (element.closest('.ui-layer') as HTMLElement).inert)).toBe( + true + ); + await page.screenshot({ path: test.info().outputPath('refit-swap-dialog.png') }); + if (isMobile) await current.tap(); + else await page.keyboard.press('Escape'); + await expect(dialog).toHaveCount(0); + await expect(gun).toHaveAccessibleName('Swap main gun, now LANCE'); + await expect(gun).toBeFocused(); + // Neither opening nor closing the dialog carried on to the next sector. + await page.waitForTimeout(600); + expect((await snapshot(page)).activeScenes).toContain('PlanetIntermission'); + + await gun.click(); + await dialog.getByRole('button', { name: /^SCATTER/ }).click(); + await expect(gun).toHaveAccessibleName('Swap main gun, now SCATTER'); + await page.getByRole('button', { name: /Continue to/ }).click(); + await waitForScene(page, 'Game'); + if (isMobile) await page.touchscreen.tap(195, 700); + await expect.poll(async () => (await playerShots(page)).some((shot) => Math.abs(shot.rotation) > 0.1)).toBe(true); + await openPause(page, isMobile); + await page.getByRole('tab', { name: 'SYSTEMS' }).click(); + await expect(systemRow(page, 'MAIN GUN')).toContainText('SCATTER'); + assertNoBrowserErrors(); +}); + test('every ship system runs in a real sector without errors', async ({ page, isMobile, assertNoBrowserErrors }) => { test.skip(isMobile, 'covered once on desktop; systems do not depend on the input device'); test.setTimeout(180_000); diff --git a/tests/shipSystems.test.ts b/tests/shipSystems.test.ts index 276895b..68fd346 100644 --- a/tests/shipSystems.test.ts +++ b/tests/shipSystems.test.ts @@ -2,6 +2,7 @@ import { describe, expect, test } from 'bun:test'; import { describePickedShipSystems, getPendingShipSystemSlot, + getShipSystemSlot, NO_SHIP_SYSTEMS, normalizeShipSystems, selectNextShipSystem, @@ -59,6 +60,13 @@ describe('ship systems', () => { expect(setShipSystem(NO_SHIP_SYSTEMS, 'support', 'lance').support).toBeNull(); }); + test('a picked slot can be offered again at the refit bay with its own three options', () => { + const gun = getShipSystemSlot('gun'); + expect(gun.title).toBe('MAIN GUN'); + expect(gun.options.map((option) => option.id)).toEqual(['lance', 'scatter', 'seekers']); + expect(getShipSystemSlot('late').options.map((option) => option.id)).toEqual(['overdrive', 'bulwark', 'salvager']); + }); + test('the pause panel lists only picked slots, in slot order', () => { const picked = describePickedShipSystems({ gun: 'scatter', support: null, late: 'bulwark' }); expect(picked.map((system) => [system.title, system.option.name])).toEqual([