diff --git a/CHANGELOG.md b/CHANGELOG.md index 1dcc2c1..589cf36 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,18 @@ All notable changes to this project will be documented in this file. +## [1.36.0] - 2026-11-15 + +### Added + +- Pause and gun-swap buttons are available with a mouse as well as touch. The swap button appears when special guns unlock in sector 3; its charge bar and first-use ring show when and where to switch. Q still works, and touch steering remains independent of the buttons. + +### Changed + +- Hull Armor now adds 1 HP per tier instead of 2, for 10 HP at the maximum tier instead of 15. The first tier still costs 500 credits after sector 1. +- Shield tiers open after sectors 3, 6 and 9 instead of 3, 5 and 7. High scores cannot skip these limits. Hull and shields still recover between sectors and on respawn; offensive upgrades and enemy patterns are unchanged. +- Older saves keep their purchased upgrade tiers; hull health is clamped to the new maximum when loaded. + ## [1.35.1] - 2026-11-14 ### Fixed diff --git a/CONTEXT.md b/CONTEXT.md index 9a639e2..2a3a9cb 100644 --- a/CONTEXT.md +++ b/CONTEXT.md @@ -26,6 +26,9 @@ _Avoid_: surprise, cheap shot ## Decisions +**Defensive progression stays bounded even with high scores (2026-11)**: +Score buys upgrades but never advances the campaign or grants level-ups. Chain multipliers and fast-kill bonuses made the defensive caps easy to buy, so Hull Armor now grants one HP per tier (5 base, 10 maximum), and shield tiers open after sectors 3, 6 and 9. The first hull purchase stays affordable at 500 credits. Sector recovery and respawn shields remain deliberate recovery beats; offense and encounter grammar are unchanged. Pointer buttons for pause and special-gun swap appear on all devices, while relative drag and touch autofire remain touch-only. + **Boss fights are authored rotations with a par time (2026-11)**: Bosses got harder by soaking up more hull, which made late fights long, easy and repetitive. Boss hull no longer scales with sector or with the player's upgrades; each boss has an authored hull and a par time (45-70 s) measured with `bun run balance:bosses`. Difficulty lives in what the boss does: phases at hull thresholds, an ordered (never random) attack rotation per phase, anchors that move the boss between attacks, and escalation of up to 25% faster volleys past par (never a shorter wind-up; the first boss is exempt). A kill under par pays a fixed bonus per second. Fight time is the boss's gameplay clock, so pause and hit-stop never count. Difficulty tiers still only scale accepted hull damage. diff --git a/README.md b/README.md index f08faf8..d08fab2 100644 --- a/README.md +++ b/README.md @@ -38,20 +38,21 @@ Open `http://localhost:5173` in your browser. |-------|--------| | Arrow keys / WASD | Move ship | | Space / Click | Fire weapons | -| Q | From sector 3: switch to a special gun while its charge lasts (Lance → Scatter → Seekers → Lance) | -| Esc | Pause (closes the settings sheet on the menu) | +| Q / Swap button | From sector 3: switch to a special gun while its charge lasts (Lance → Scatter → Seekers → Lance) | +| Esc / Pause button | Pause (closes the settings sheet on the menu) | The ship flies with inertia: it builds speed over about a second and slides after you let go. On touch devices, drag anywhere to fly: the ship follows your finger's movement and the main gun fires automatically. Pressing a key on a hardware keyboard hands steering and firing to the keyboard, and the next touch hands them back (tap-to-pause stays available). From sector 3, a swap -button under the pause button switches guns and shows the special-gun charge. +button under the pause button switches guns and shows the special-gun charge. Both buttons also +accept mouse clicks on desktop and hybrid devices; gun switching appears only when it unlocks. The refit bay after sector 2 opens with a short SPECIAL GUNS ONLINE card that explains Lance, the swap key and the charge. In sector 3 the swap is pointed out until you first use it: a -`Q SPECIAL GUN` label beside the HUD charge bar on a keyboard, a pulsing ring around the swap -button on touch. +`Q SPECIAL GUN` label beside the HUD charge bar on a keyboard, and a pulsing ring around the swap +button on every device. Autofire is set in SETTINGS (menu or pause panel). Touch flight autofires by default; turn it off to fire only while your finger is on the screen. Keyboard and mouse play can turn autofire on, so @@ -116,7 +117,7 @@ Menu → Game → Planet Intermission → Game → ... → Victory Bought during the planet intermission screen using score as currency: -- **Hull Armor** — raises max HP +- **Hull Armor** — adds 1 max HP per tier, up to 10 HP - **Weapons** — increases damage - **Fire Rate** — improves firing speed - **Shield** — increases hit absorption diff --git a/docs/level-design.md b/docs/level-design.md index 0ed1d24..9fff1fc 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. -- **Main guns** (`config/shipSystems.ts`): sectors 1–2 fly the standard bolt and have no gun input, so the opening stays a gentle introduction. From sector 3 the home gun is Lance; Scatter and Seekers are special guns borrowed on a charge, not picks. Each gun trades single-target damage for one strength and scored inside the standard gun's run-to-run spread in sector 5. Q or the touch swap key steps Lance → Scatter → Seekers → Lance. One meter, `SPECIAL_GUN_CHARGE`, counted on the gameplay clock, pays for the specials: it drains while one is selected (a full meter lasts 8 s) and returns the gun to Lance at empty; on Lance it refills over 40 s plus 0.005 per enemy destroyed; leaving Lance needs at least 0.2 of it, while moving between specials or back to Lance is always allowed. It starts full every sector and after every respawn or checkpoint load, and is never saved. Feedback is a name flash over the ship and a short swap sound on every change (including the automatic return), the quiet click when leaving Lance is refused, each gun's own shot look (the profile's `look`), and the HUD's gun row under the reserve ships: the gun's name and a charge bar that burns amber while a special drains and refills cyan on Lance, with a tick at the threshold. The touch swap key mirrors the bar along its foot. The guns are taught, never picked: the refit bay after sector 2 opens on a one-button SPECIAL GUNS ONLINE card (`planetIntermission/specialGunIntro.ts`, shown on every visit to that bay and no other), and sector 3 only points at the swap until the first one there (`ShipSystemsRuntime.isSwapHintPending`): a `Q SPECIAL GUN` label beside the charge bar on a keyboard, a pulsing ring around the touch swap key. +- **Main guns** (`config/shipSystems.ts`): sectors 1–2 fly the standard bolt and have no gun input, so the opening stays a gentle introduction. From sector 3 the home gun is Lance; Scatter and Seekers are special guns borrowed on a charge, not picks. Each gun trades single-target damage for one strength and scored inside the standard gun's run-to-run spread in sector 5. Q or the on-screen swap key steps Lance → Scatter → Seekers → Lance. One meter, `SPECIAL_GUN_CHARGE`, counted on the gameplay clock, pays for the specials: it drains while one is selected (a full meter lasts 8 s) and returns the gun to Lance at empty; on Lance it refills over 40 s plus 0.005 per enemy destroyed; leaving Lance needs at least 0.2 of it, while moving between specials or back to Lance is always allowed. It starts full every sector and after every respawn or checkpoint load, and is never saved. Feedback is a name flash over the ship and a short swap sound on every change (including the automatic return), the quiet click when leaving Lance is refused, each gun's own shot look (the profile's `look`), and the HUD's gun row under the reserve ships: the gun's name and a charge bar that burns amber while a special drains and refills cyan on Lance, with a tick at the threshold. The on-screen swap key mirrors the bar along its foot. The guns are taught, never picked: the refit bay after sector 2 opens on a one-button SPECIAL GUNS ONLINE card (`planetIntermission/specialGunIntro.ts`, shown on every visit to that bay and no other), and sector 3 only points at the swap until the first one there (`ShipSystemsRuntime.isSwapHintPending`): a `Q SPECIAL GUN` label beside the charge bar on a keyboard, a pulsing ring around the on-screen swap key on every device. - **Ship systems** are free one-of-three picks at the refit bay after sectors 5 and 8. They change how the ship plays rather than how hard it hits. A system works without input; the only 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) and mid-run from the pause panel's SYSTEMS tab. 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. @@ -243,3 +243,14 @@ Solar flares leave a visible bottom escape lane of at least 100px or 22% of view The campaign pass applies the same pickup travel check to the other six boss levels. Boss triggers are now 0.752 for Clockwork Causeway, 0.746 for Shatter Reef, 0.741 for Hollow Choir, 0.719 for Eclipse Narrows, 0.718 for Swarmfront, and 0.695 for Eventide Engine. Earlier sections and authored wave timestamps stay fixed. The existing finale approach health remains health. Tideglass introduces its first portal with familiar scouts before its dodger line, and keeps ambush combinations for the later section. These extensions add 43.88s across eight approaches. Each approach lasts about 8s and asks for a deliberate midfield pickup interception. The rejected 103.40s version relied on passive lower-screen collection and added too much waiting. Normal level transitions refill hull and purchased shields; sustained campaign attrition is principally reserves and credits, not carried hull damage. + +### Defensive upgrade pacing + +Score is also refit currency, and chains can multiply kill income by five. Defensive strength therefore +needs a ceiling even when a high-scoring run can afford every open tier. Hull Armor adds one HP per +tier (5 base, 10 at maximum); its first tier still costs 500 credits after sector 1. Shield tiers open +after sectors 3, 6, and 9. Full hull and purchased shields still return at sector transitions and +respawns. Entering sectors 6, 8, and 10 with every available defensive upgrade now gives 9, 11, and 13 +combined hull/shield points, previously 13, 16, and 18. Weapon damage, firing speed, score rewards, +and authored recovery pickups are unchanged. Existing saves keep their tiers; excess hull is bounded +to the new maximum when loaded, and already-owned shield tiers remain owned. diff --git a/package.json b/package.json index cac219b..22db3e2 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "space-explorer", - "version": "1.35.1", + "version": "1.36.0", "author": "Douwe de Vries", "license": "MIT", "private": true, diff --git a/src/config/UpgradesConfig.ts b/src/config/UpgradesConfig.ts index e78e2fc..50f9107 100644 --- a/src/config/UpgradesConfig.ts +++ b/src/config/UpgradesConfig.ts @@ -50,7 +50,7 @@ const UPGRADES: UpgradeDef[] = [ { key: 'hp', name: 'HULL ARMOR', - description: '+2 Max HP', + description: '+1 Max HP', maxLevel: 5, progressionCaps: [1, 2, 2, 3, 3, 4, 4, 5, 5, 5], baseCost: 500, @@ -85,8 +85,8 @@ const UPGRADES: UpgradeDef[] = [ name: 'SHIELD', description: '+1 Shield each life', maxLevel: 3, - progressionCaps: [0, 0, 1, 1, 2, 2, 3, 3, 3, 3], - // A shield tier is one absorbed hit per life, where a hull tier is two: priced a little above hull. + progressionCaps: [0, 0, 1, 1, 1, 2, 2, 2, 3, 3], + // Shields absorb a full hit at any difficulty; later tiers open gradually to limit defensive stacking. baseCost: 1000, costMultiplier: 2, unlock: { diff --git a/src/config/playerConfig.ts b/src/config/playerConfig.ts index 569dfbf..f7df5b1 100644 --- a/src/config/playerConfig.ts +++ b/src/config/playerConfig.ts @@ -3,7 +3,7 @@ export const PLAYER_CONFIG = { // The campaign has no reserve-life upgrades, so this is also the persisted-state maximum. startingLives: 3, baseFireRate: 150, - hpPerUpgrade: 2, + hpPerUpgrade: 1, fireRateReductionPerUpgrade: 15, minFireRate: 60, // Hard floor for any fire-rate reduction (rapidfire pickups, max-chain Overdrive). diff --git a/src/scenes/gameScene/gameplayFrameBehavior.ts b/src/scenes/gameScene/gameplayFrameBehavior.ts index ca6941f..9be4e54 100644 --- a/src/scenes/gameScene/gameplayFrameBehavior.ts +++ b/src/scenes/gameScene/gameplayFrameBehavior.ts @@ -166,10 +166,10 @@ export function createGameSceneGameplayFrameBehavior( else if (outcome === 'low-charge') delegate.gunSwapFeedback.denied(); } if (shipSystems.updateGunCharge(delta)) delegate.gunSwapFeedback.swapped('lance'); - // Until the first swap of sector 3 the swap is pointed out: a pulse on the touch key, else a Q label. + // Until the first swap of sector 3, pulse the on-screen key and also show Q for keyboard players. const hint = shipSystems.isSwapHintPending(); const touchHint = hint && (delegate.mobileControls?.showsTouchHints() ?? false); - delegate.mobileControls?.setGunChargeState(shipSystems.getGun(), shipSystems.getGunCharge(), touchHint); + delegate.mobileControls?.setGunChargeState(shipSystems.getGun(), shipSystems.getGunCharge(), hint); delegate.hud.setSwapHint(hint && !touchHint); }; diff --git a/src/scenes/gameScene/showControlsHint.ts b/src/scenes/gameScene/showControlsHint.ts index acd91a0..32579cb 100644 --- a/src/scenes/gameScene/showControlsHint.ts +++ b/src/scenes/gameScene/showControlsHint.ts @@ -9,7 +9,7 @@ const AUTO_FIRE_HINT = 'Guns fire automatically'; const MOBILE_FIRE_HINT = 'Guns fire while you touch'; const KEYBOARD_TITLE = 'WASD / Arrows to Move'; const KEYBOARD_FIRE_HINT = 'SPACE / Click to Fire'; -const KEYBOARD_SWAP_HINT = 'Q for a Special Gun'; +const KEYBOARD_SWAP_HINT = 'Q / swap button: Special Gun'; /** The fire line follows the autofire setting for the input in use. */ function fireHintFor(mobile: boolean): string { diff --git a/src/scenes/planetIntermission/specialGunIntro.ts b/src/scenes/planetIntermission/specialGunIntro.ts index 540ef1d..c803870 100644 --- a/src/scenes/planetIntermission/specialGunIntro.ts +++ b/src/scenes/planetIntermission/specialGunIntro.ts @@ -14,7 +14,7 @@ export function isSpecialGunIntroDue(clearedLevel: number): boolean { export function describeSpecialGunIntro(touch: boolean): readonly string[] { return [ 'Your main gun is now the LANCE: slower shots that pierce every ship in a line.', - `${touch ? 'Tap the swap key' : 'Press Q'} to switch to SCATTER or SEEKERS.`, + `${touch ? 'Tap the swap key' : 'Press Q or click the swap key'} to switch to SCATTER or SEEKERS.`, 'Special guns run on a charge. When it is empty you drop back to the Lance, which refills it.', ]; } diff --git a/src/systems/InputManager.ts b/src/systems/InputManager.ts index 38d6662..bfab3c8 100644 --- a/src/systems/InputManager.ts +++ b/src/systems/InputManager.ts @@ -63,7 +63,8 @@ export class InputManager { } // Keyboard and mouse play can opt in to autofire from settings. - return autoFire.keyboard || this.space.isDown || this.scene.input.activePointer.isDown; + const pointer = this.scene.input.activePointer; + return autoFire.keyboard || this.space.isDown || (pointer.isDown && !mobileControls?.isControlPointer(pointer)); } /** Touch drag steering velocity for the ship at (x, y), or null when no finger is steering. */ diff --git a/src/systems/MobileControls.ts b/src/systems/MobileControls.ts index 210102d..7e41aa0 100644 --- a/src/systems/MobileControls.ts +++ b/src/systems/MobileControls.ts @@ -28,7 +28,7 @@ interface ControlKey { } /** - * Touch controls for momentum flight: drag anywhere and the ship follows the finger's movement, + * Pointer buttons for every device, with touch controls for momentum flight: drag anywhere and the ship follows the finger's movement, * while the main gun autofires. A pause button stays available in the top-right corner, and from sector 3 * a swap button sits under it that borrows a special gun and shows the charge. */ @@ -68,7 +68,13 @@ export class MobileControls { private readonly handlePointerDown = (pointer: Phaser.Input.Pointer): void => { // Drag steering is a touch control: trackpad or mouse presses on hybrid devices never start it. // Suppression is not checked here because this listener runs before the bootstrap's touch restore. - if (!pointer.wasTouch || !this.isEnabled() || this.dragPointerId !== null || this.isOverControlKey(pointer)) { + if ( + !pointer.wasTouch || + !this.enabledForTouchDevice || + !this.isEnabled() || + this.dragPointerId !== null || + this.isOverControlKey(pointer) + ) { return; } @@ -108,10 +114,6 @@ export class MobileControls { this.enabledForTouchDevice = isTouchMobileDevice(); this.blocked = false; - if (!this.enabledForTouchDevice) { - return this; - } - const extraPointers = Math.max(0, 3 - scene.input.manager.pointersTotal); if (extraPointers > 0) { scene.input.addPointer(extraPointers); @@ -170,7 +172,7 @@ export class MobileControls { } relayout(): void { - if (!this.scene || !this.enabledForTouchDevice) { + if (!this.scene) { return; } @@ -201,12 +203,12 @@ export class MobileControls { } isEnabled(): boolean { - return this.enabledForTouchDevice && !this.blocked && this.scene !== null; + return !this.blocked && this.scene !== null; } /** True while touch is the active input; the gun then autofires unless touch autofire is off. */ isTouchSteeringActive(): boolean { - return this.isEnabled() && !this.touchSteeringSuppressed; + return this.enabledForTouchDevice && this.isEnabled() && !this.touchSteeringSuppressed; } /** True while the steering finger is on the screen, whatever other fingers tap meanwhile. */ @@ -216,7 +218,7 @@ export class MobileControls { isControlPointer(pointer: Phaser.Input.Pointer): boolean { return ( - this.enabledForTouchDevice && + this.scene !== null && (pointer.id === this.pauseButtonPointerId || pointer.id === this.swapButtonPointerId || pointer.id === this.dragPointerId) @@ -320,7 +322,7 @@ export class MobileControls { } private refreshVisibility(): void { - const pauseVisible = this.enabledForTouchDevice && this.scene !== null; + const pauseVisible = this.scene !== null; // The pause panel covers the field, so the swap key hides with it. const swapVisible = pauseVisible && this.swapAvailable && !this.blocked; setControlKeyVisible(this.pauseKey, pauseVisible, pauseVisible && !this.blocked); diff --git a/tests/InputManager.test.ts b/tests/InputManager.test.ts index 17b9e07..a865b58 100644 --- a/tests/InputManager.test.ts +++ b/tests/InputManager.test.ts @@ -236,3 +236,21 @@ test('Q and the touch swap button each request one gun swap per press', () => { expect(manager.consumeGunSwapRequest()).toBe(true); expect(manager.consumeGunSwapRequest()).toBe(false); }); + +test('clicking an on-screen control does not fire the main gun', () => { + autoFire = { touch: true, keyboard: false }; + const scene = createScene([]); + let overControl = true; + const inputManager = new InputManager(); + inputManager.create( + scene as never, + { + isTouchSteeringActive: () => false, + isControlPointer: () => overControl, + } as never + ); + scene.input.activePointer.isDown = true; + expect(inputManager.isFiring()).toBe(false); + overControl = false; + expect(inputManager.isFiring()).toBe(true); +}); diff --git a/tests/MobileControlsDrag.test.ts b/tests/MobileControlsDrag.test.ts index cae830a..b7ea2ce 100644 --- a/tests/MobileControlsDrag.test.ts +++ b/tests/MobileControlsDrag.test.ts @@ -2,7 +2,11 @@ import { describe, expect, mock, test } from 'bun:test'; import { mockPhaserModule } from './helpers/phaserMock'; mockPhaserModule(); -mock.module('../src/utils/device', () => ({ isTouchMobileDevice: () => true, prefersReducedMotion: () => false })); +let touchDevice = true; +mock.module('../src/utils/device', () => ({ + isTouchMobileDevice: () => touchDevice, + prefersReducedMotion: () => false, +})); const { MobileControls } = await import('../src/systems/MobileControls'); @@ -212,3 +216,37 @@ describe('MobileControls gun-swap key', () => { expect(tweens.size).toBe(0); }); }); + +test('desktop and hybrid pointer keys work without enabling touch steering or autofire', () => { + touchDevice = false; + try { + const { controls, tapKey, emit } = createControls(); + expect(controls.isEnabled()).toBe(true); + expect(controls.isTouchSteeringActive()).toBe(false); + expect(controls.showsTouchHints()).toBe(false); + tapKey(SWAP_KEY, { id: 0, ...SWAP }); + expect(controls.consumeGunSwapPress()).toBe(false); + controls.setGunChargeState('lance', 1, false); + tapKey(SWAP_KEY, { id: 0, ...SWAP }); + expect(controls.consumeGunSwapPress()).toBe(true); + expect(controls.consumeGunSwapPress()).toBe(false); + expect(controls.isControlPointer({ id: 0 } as never)).toBe(true); + emit('pointerup', { id: 0, ...SWAP }); + expect(controls.isControlPointer({ id: 0 } as never)).toBe(false); + controls.setBlocked(true); + tapKey(SWAP_KEY, { id: 0, ...SWAP }); + expect(controls.consumeGunSwapPress()).toBe(false); + controls.setBlocked(false); + let paused = false; + controls.setPauseButtonHandler(() => { + paused = true; + }); + tapKey(0, { id: 0, ...PAUSE }); + expect(paused).toBe(true); + emit('pointerdown', { id: 2, x: 100, y: 700, wasTouch: false }); + expect(controls.getDragDesiredVelocity(195, 760, 0, 480)).toBeNull(); + controls.destroy(); + } finally { + touchDevice = true; + } +}); diff --git a/tests/PlayerState.test.ts b/tests/PlayerState.test.ts index 27c53ff..3845761 100644 --- a/tests/PlayerState.test.ts +++ b/tests/PlayerState.test.ts @@ -183,14 +183,14 @@ describe('PlayerState schema behavior', () => { creditsSpent: 0, runSeed: 0, easiestDifficulty: null, - currentHp: 15, + currentHp: 10, currentShields: 8, remainingLives: 3, upgrades: { hp: 5, damage: 4, fireRate: 4, shield: 3, turrets: 2 }, systems: { support: null, late: null }, helperWing: { grantedSlots: 1, - slots: [{ remainingLives: 3, hp: 15 }], + slots: [{ remainingLives: 3, hp: 10 }], }, }); }); @@ -322,7 +322,7 @@ describe('PlayerState schema behavior', () => { const state = getPlayerState(registry); expect(state.level).toBe(3); - expect(state.currentHp).toBe(9); + expect(state.currentHp).toBe(7); expect(state.currentShields).toBe(3); }); diff --git a/tests/SaveSlotStorage.test.ts b/tests/SaveSlotStorage.test.ts index 94bd4a5..a215398 100644 --- a/tests/SaveSlotStorage.test.ts +++ b/tests/SaveSlotStorage.test.ts @@ -133,7 +133,7 @@ describe('SaveSlotStorage', () => { creditsSpent: 0, runSeed: 0, easiestDifficulty: null, - currentHp: 6.25, + currentHp: 5.25, currentShields: 1, remainingLives: 2, upgrades: { hp: 1, damage: 2, fireRate: 1, shield: 2, turrets: 1 }, @@ -190,7 +190,7 @@ describe('SaveSlotStorage', () => { creditsSpent: 0, runSeed: 0, easiestDifficulty: null, - currentHp: 6.25, + currentHp: 5.25, currentShields: 1, remainingLives: 2, upgrades: { hp: 1, damage: 2, fireRate: 1, shield: 2, turrets: 1 }, @@ -202,7 +202,7 @@ describe('SaveSlotStorage', () => { expect(writeSaveSlot(saved)).toEqual(saved); expect(readSaveSlot('slot-1')).toEqual(saved); - expect(readSaveSlot('slot-1')?.playerState.currentHp).toBe(6.25); + expect(readSaveSlot('slot-1')?.playerState.currentHp).toBe(5.25); }); test('gracefully falls back to empty state for corrupt JSON payloads', () => { @@ -374,12 +374,12 @@ describe('SaveSlotStorage', () => { creditsSpent: 0, runSeed: 0, easiestDifficulty: null, - currentHp: 15, + currentHp: 10, currentShields: 8, remainingLives: 3, upgrades: { hp: 5, damage: 4, fireRate: 4, shield: 3, turrets: 2 }, systems: { support: null, late: null }, - helperWing: { grantedSlots: 1, slots: [{ remainingLives: 3, hp: 15 }] }, + helperWing: { grantedSlots: 1, slots: [{ remainingLives: 3, hp: 10 }] }, }); expect(readSaveSlot('slot-1')?.runSummary.finalScore).toBe(Number.MAX_SAFE_INTEGER); }); diff --git a/tests/defensiveProgression.test.ts b/tests/defensiveProgression.test.ts new file mode 100644 index 0000000..61a9e69 --- /dev/null +++ b/tests/defensiveProgression.test.ts @@ -0,0 +1,55 @@ +import { describe, expect, mock, test } from 'bun:test'; +import { evaluateUpgrades, type PlayerUpgradeLevels } from '../src/config/UpgradesConfig'; + +mock.module('phaser', () => ({ default: {} })); +const { advanceToNextLevel, getPlayerState, setPlayerState } = await import('../src/systems/PlayerState'); + +const stock: PlayerUpgradeLevels = { hp: 0, damage: 0, fireRate: 0, shield: 0, turrets: 0 }; + +/** Buy every affordable tier, including prerequisites, as a high-scoring player can. */ +function buyAvailable(clearedSector: number): PlayerUpgradeLevels { + const upgrades = { ...stock }; + for (;;) { + const next = evaluateUpgrades(clearedSector, Number.MAX_SAFE_INTEGER, upgrades).find((entry) => entry.canPurchase); + if (!next) return upgrades; + upgrades[next.upgrade.key] += 1; + } +} + +describe('defensive campaign pacing', () => { + test('large scores cannot bypass defensive tier gates or inflate sector recovery', () => { + for (const [clearedSector, hp, shields] of [ + [1, 6, 0], + [3, 7, 1], + [5, 8, 1], + [7, 9, 2], + [9, 10, 3], + ]) { + const values = new Map(); + const registry = { + get: (key: string) => values.get(key), + set: (key: string, value: unknown) => values.set(key, value), + }; + setPlayerState(registry, { + ...getPlayerState(registry), + level: clearedSector, + score: 1_000_000, + currentHp: 1, + currentShields: 0, + upgrades: buyAvailable(clearedSector), + }); + advanceToNextLevel(registry); + expect(getPlayerState(registry)).toMatchObject({ + level: clearedSector + 1, + currentHp: hp, + currentShields: shields, + }); + } + }); + + test('the first hull upgrade remains affordable after the opening sector', () => { + const hull = evaluateUpgrades(1, 500, stock).find((entry) => entry.upgrade.key === 'hp'); + expect(hull?.canPurchase).toBe(true); + expect(hull?.cost).toBe(500); + }); +}); diff --git a/tests/e2e/shipSystems.spec.ts b/tests/e2e/shipSystems.spec.ts index c07be38..0619065 100644 --- a/tests/e2e/shipSystems.spec.ts +++ b/tests/e2e/shipSystems.spec.ts @@ -337,3 +337,45 @@ test('leaving the refit bay autosaves the run, picks included, until the run end await expect(page.getByRole('button', { name: /^Load AUTOSAVE/ })).toHaveCount(0); assertNoBrowserErrors(); }); + +test('on-screen pause and unlocked gun swap work without a keyboard', async ({ + page, + isMobile, + assertNoBrowserErrors, +}) => { + await pinQualityTier(page, 'low'); + await page.addInitScript(() => + window.localStorage.setItem('space-explorer.autoFire.v1', JSON.stringify({ touch: false, keyboard: false })) + ); + const viewport = page.viewportSize()!; + const x = viewport.width - 44; + const tap = async (y: number) => { + if (isMobile) await page.touchscreen.tap(x, y); + else await page.mouse.click(x, y); + }; + await page.goto('/?browserHarness=1&startLevel=2'); + await waitForScene(page, 'Game'); + await tap(TOUCH_SWAP_Y); + expect(await gunState(page)).toBeNull(); + await page.goto('/?browserHarness=1&startLevel=3'); + await waitForScene(page, 'Game'); + await expect.poll(async () => (await gunState(page))?.id).toBe('lance'); + await tap(TOUCH_SWAP_Y); + await expect.poll(async () => (await gunState(page))?.id).toBe('scatter'); + await page.screenshot({ path: test.info().outputPath('pointer-swap.png') }); + // A held mouse button over swap changes once and never doubles as a fire press. + if (!isMobile) { + await page.mouse.move(x, TOUCH_SWAP_Y); + await page.mouse.down(); + await expect.poll(async () => (await gunState(page))?.id).toBe('seekers'); + await page.waitForTimeout(300); + expect((await gunState(page))?.id).toBe('seekers'); + expect(await playerShots(page)).toHaveLength(0); + await page.mouse.up(); + } + await tap(TOUCH_PAUSE_Y); + await expect(page.getByRole('dialog', { name: 'Paused' })).toBeVisible(); + await page.getByRole('button', { name: 'RESUME', exact: true }).click(); + await expect(page.getByRole('dialog', { name: 'Paused' })).toBeHidden(); + assertNoBrowserErrors(); +}); diff --git a/tests/specialGunCharge.test.ts b/tests/specialGunCharge.test.ts index 00c80da..f279e94 100644 --- a/tests/specialGunCharge.test.ts +++ b/tests/specialGunCharge.test.ts @@ -388,10 +388,10 @@ describe('first-swap hint', () => { expect(other.isSwapHintPending()).toBe(true); }); - test('with a keyboard the HUD shows the hint until the first swap, then never again', () => { + test('with a keyboard both the HUD and pointer key hint until the first swap, then never again', () => { const harness = createFrameHarness(GUN_SECTOR); harness.run(32); - expect(harness.hints).toEqual({ hud: true, key: false }); + expect(harness.hints).toEqual({ hud: true, key: true }); harness.pressSwap(); harness.run(16); expect(harness.hints).toEqual({ hud: false, key: false }); diff --git a/tests/specialGunIntro.test.ts b/tests/specialGunIntro.test.ts index 043baa8..5cf2d15 100644 --- a/tests/specialGunIntro.test.ts +++ b/tests/specialGunIntro.test.ts @@ -14,7 +14,7 @@ describe('special gun intro card', () => { test('names Q on a keyboard and the swap key on touch, and nothing else changes', () => { const keyboard = describeSpecialGunIntro(false); const touch = describeSpecialGunIntro(true); - expect(keyboard[1]).toBe('Press Q to switch to SCATTER or SEEKERS.'); + expect(keyboard[1]).toBe('Press Q or click the swap key to switch to SCATTER or SEEKERS.'); expect(touch[1]).toBe('Tap the swap key to switch to SCATTER or SEEKERS.'); expect(touch.filter((line, index) => line !== keyboard[index])).toEqual([touch[1]]); expect(keyboard[0]).toContain('LANCE');