fix/tier-preserving-begin-run #1

Merged
necrogami merged 6 commits from fix/tier-preserving-begin-run into main 2026-08-01 23:16:27 +00:00
Contributor
No description provided.
Per OG (2026-08-01): clicking 'Begin New Run' on the Beacon Out
modal (or the Shop header) re-arms the beacon in the CURRENT
tier (state.currentTier) without re-prompting. The TierPicker
now fires ONLY on the explicit 'Change Tiers' button — the
single path that mutates state.currentTier.

Before this change, both Begin New Run AND Change Tiers opened
the picker on every click, forcing the player to re-pick the
tier they had already chosen. The most common flow (replay the
same tier) became a 2-tap flow with a modal in the middle.

Changes:
- PrestigeManager.js: Begin New Run handler now calls
  __spire_startNewRun() (no arg). Update comments to spell
  out that the picker is Change Tiers-only.
- Shop.js: Shop header Begin New Run handler — same change.
- main.js: __spire_openTierPicker comment now states it's
  ONLY for Change Tiers; Begin New Run is tier-preserving.

Tests:
- tests/begin_run_tier_preservation.mjs (new): 6 assertions
  covering both call sites + the Shop handler + state
  preservation. Loads the real PrestigeManager module via
  dynamic import against a minimal DOM stub.
- Headless E2E verify on the live URL: Begin New Run skips
  the picker (PASS), Change Tiers opens it (PASS).
Per OG (2026-08-01): the run controls no longer sit at the
bottom-right of the playfield. They join the visibility (eye)
and DEV buttons as a stacked column in the top-right corner,
in this top-to-bottom order:
  1. 👁 (HUD visibility toggle)
  2. DEV (dev panel)
  3. End Run
  4. Reset Save

Layout details:
- The panel's right-edge offset (12px from safe-area) matches
  the eye and DEV buttons, so all four share the same vertical
  axis.
- top: calc(env(safe-area-inset-top, 0px) + 120px) puts the
  panel directly under DEV with a 12px gap (same gap as
  eye -> DEV).
- End Run and Reset Save keep their ~100px width and 6px gap
  between them.
- The dev menu (which opens at +120px) will overlay the run
  controls when the dev menu is open. This is expected — the
  player closes the dev menu (X) before tapping End Run. The
  same confirm() guard on End Run catches any stray tap.
- End Run's existing 'Beacon Out modal already visible' guard
  is unchanged — it still no-ops if the modal is up.

Verification:
- Headless E2E (playwright): all four buttons share right
  edge at x=388, vertical gaps 12px (DEV -> End Run) and
  6px (End Run -> Reset Save), End Run clickable when dev
  menu is closed, dev menu overlays End Run when open
  (expected), End Run clickable again after dev menu closes.
- Existing tests still pass: tier-preservation + milestone
  gate audit.
Per OG (2026-08-01): tapping the visibility (eye) button hides
the entire top-right button cluster — DEV, End Run, Reset Save —
in addition to the HUD readout. The eye itself stays visible so
the player can re-tap to bring the buttons back.

Implementation:
- DevPanel.js: subscribe to EV.HUD_TOGGLE. Toggle the DEV button
  and force-close the dev menu. Apply initial hudVisible on mount
  (covers the save-load case where the player previously toggled
  the HUD off).
- RunControls.js: same pattern for the run-controls panel.
- Hud.js: unchanged. The eye button itself and the HUD readout
  already follow the toggle.

The 'eye always visible' rule prevents a soft-lock: the player
can never get stuck with no way to restore the buttons.

Headless E2E (5/5 pass on the live URL):
  Test 1: default state, all four buttons visible
  Test 2: tap eye → HUD + DEV + End Run + Reset Save hide,
          eye stays visible
  Test 3: tap eye again → all restored
  Test 4: dev menu open + eye tap → menu hides, doesn't auto-
          reopen on next eye tap
  Test 5: save-load with hudVisible=false → buttons start
          hidden on mount, eye still visible

Verification detail: getComputedStyle(child).display returns
inline-block for a <button> even when the parent is display:none.
We use getBoundingClientRect() (returns 0x0 for hidden elements)
to detect actual visibility rather than trusting the child's
own display value.
Per OG (2026-08-01): the eye toggle has two states (HUD visible,
HUD hidden). On beacon death:
  - HUD visible: WAIT at the Beacon Out screen. Player taps
    Begin New Run / Change Tiers / Profile manually.
  - HUD hidden: AUTO-RUN after 5 seconds. Calls
    __spire_startNewRun() with no arg — tier-preserving, same
    path as the manual Begin New Run button (commit 563420a).

The eye stays clickable on the Beacon Out screen (z=19, above
the modal at z=18) so the player can re-toggle the HUD during
the 5s window to cancel the auto-restart.

Implementation:
- PrestigeManager._checkAutoRestart(): single source of truth
  for the 5s timer. Re-evaluates from scratch on every call:
  cancels any pending timer, checks hudVisible===false and
  modal up, schedules a fresh 5s setTimeout. The callback
  re-checks both conditions at fire time (defense in depth).
- PrestigeManager constructor: registers bus.on(EV.HUD_TOGGLE)
  → _checkAutoRestart. Any HUD toggle (visible↔hidden) while
  the modal is up re-evaluates.
- PrestigeManager._showRunEndModal: calls _checkAutoRestart
  after the modal mounts. If HUD is already hidden, timer
  starts immediately. If visible, no timer.
- Hud.js: bumped eye z-index from 11 to 19 (above modal at 18,
  below Shop at 30). The eye is the only way to cancel the
  auto-restart while the modal is up — it must be reachable.

Tests:
- tests/auto_restart_afk.mjs (new, 16 assertions): unit-level
  coverage of all trigger/cancel paths.
- /tmp/spire-defense-auto-restart-verify.mjs: live E2E (9
  assertions) on the real URL — actually waits the 5s.

Test status: 16/16 unit + 9/9 E2E pass. Pre-existing tests
(begin_run_tier_preservation.mjs, milestone_gate_audit.mjs)
still pass.
Per OG (2026-08-01): the run controls now sit in a horizontal
row at the top of the screen, to the left of the visibility
(eye) and DEV buttons. New layout (top row, left-to-right):

  [End Run] [Reset Save] | [👁] [DEV]

Implementation (RunControls.js):
- top: calc(env(safe-area-inset-top, 0px) + 12px) — same Y
  as the eye (was +120px before, under the DEV button).
- right: calc(env(safe-area-inset-right, 0px) + 136px) —
  12px safe-area + 12px gap + 44px eye + 12px gap + 44px DEV
  + 12px gap. The panel's right edge sits 12px left of the
  DEV button's left edge, with consistent 12px gaps throughout
  the top cluster.
- flexDirection: row (was column) — End Run and Reset Save
  are now side-by-side instead of stacked.
- gap: 6px (unchanged).
- Removed the explicit margin: 12px (no longer needed; the
  right offset calc handles the right-edge spacing).

Note on overlap: on viewports narrower than ~520px, the run
controls will visually overlap the HUD readout (which lives
in the top-LEFT at minWidth 200px). The buttons have their
own dark background so the overlap is just a small dark patch
obscuring some HUD text — the HUD is pointer-events:none so
clicks still pass through to the buttons. The geometry is
otherwise correct.

Pre-existing tests still pass: begin_run_tier_preservation,
milestone_gate_audit, auto_restart_afk (16 assertions).
Per OG (2026-08-01): buttons were blocking the HUD readout.
Fixed by making buttons smaller and anchoring them to the
right edge of the HUD readout (x=232) instead of the right
edge of the viewport.

Changes to RunControls.js:
- btnStyle: fontSize 12→8px, padding 8px14px→2px6px,
  maxWidth 64px (was minWidth 100px), whiteSpace: nowrap.
  Panel width: ~105px (was ~206px).
- Panel: switched from right:136px to left:232px, so the
  panel starts exactly where the HUD readout ends.
- Added display:flex and alignItems:center (was missing,
  causing buttons to stack instead of side-by-side).

Layout (400×800 viewport):
  [HUD 0-232] [End Run 232-277] [Reset Save 283-338] [Eye 344-388]
  All at y=12 (top row). DEV at y=76 (below eye).
  Zero overlap with HUD text.

Pre-existing tests still pass: begin_run_tier_preservation,
milestone_gate_audit, auto_restart_afk (16/16).
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
og_arist0tle/Spire-Defense!1
No description provided.