From d1be538bd4adadd46acb0a7737cc1fa863774b97 Mon Sep 17 00:00:00 2001 From: coyotte508 Date: Sun, 1 Nov 2026 00:30:27 +0100 Subject: [PATCH] Preserve final-shot effects through tutorial frame resizing --- preview/resolution-effects.js | 29 ++++++++++++++++------------- preview/style.css | 7 ++++--- 2 files changed, 20 insertions(+), 16 deletions(-) diff --git a/preview/resolution-effects.js b/preview/resolution-effects.js index 6347da1..6750b23 100644 --- a/preview/resolution-effects.js +++ b/preview/resolution-effects.js @@ -65,8 +65,8 @@ export function createResolutionEffects(root, cue) { const layer = doc.createElement("div"); layer.className = "resolution-effects"; layer.setAttribute("aria-hidden", "true"); - root.append(layer); - let previous = null, previousIndex = -1, busyUntil = 0, jumping = false, pendingFrame = null; + root.querySelector(".flight-layout").append(layer); + let previous = null, previousIndex = -1, busyUntil = 0, pendingFrame = null; let oldPawns = new Map(); let oldShip = null; const animations = new Set(), timers = new Set(), restores = []; @@ -101,7 +101,6 @@ export function createResolutionEffects(root, cue) { for (const restore of restores.splice(0)) restore(); layer.replaceChildren(); busyUntil = 0; - jumping = false; } function node(name, p, color, parent = layer) { const element = doc.createElement("span"); @@ -160,7 +159,7 @@ export function createResolutionEffects(root, cue) { const vessel = q(".ship-vessel"), position = point(vessel); if (!position) return; // Keep the jump attached to the ship even if completion text changes the - // page's scroll position. Combat projectiles use viewport coordinates. + // page's scroll position. const stage = doc.createElement("div"); stage.className = "ship-jump-effects"; stage.setAttribute("aria-hidden", "true"); @@ -170,7 +169,6 @@ export function createResolutionEffects(root, cue) { const p = { x: bounds.left - base.left + bounds.width / 2, y: bounds.top - base.top + bounds.height / 2, width: bounds.width, height: bounds.height }; const jumpSound = kind => sound(kind, position); - jumping = true; const duration = reduced.matches ? 900 : 2800; const departure = reduced.matches ? 0 : 1100; const arrival = reduced.matches ? 0 : 1500; @@ -220,7 +218,7 @@ export function createResolutionEffects(root, cue) { { transform: "translate(-50%,-50%) scale(1)", opacity: 1, offset: .7 }, { transform: "translate(-50%,-50%) scale(1)", opacity: 0 }, ], duration - arrival); - later(() => { stage.remove(); jumping = false; }, duration - arrival); + later(() => stage.remove(), duration - arrival); }, arrival); busyUntil = Math.max(busyUntil, performance.now() + duration); } @@ -230,7 +228,8 @@ export function createResolutionEffects(root, cue) { const sound = (kind, p) => { if (spoken.has(kind)) return; spoken.add(kind); - cue(kind, p ? Math.max(-.7, Math.min(.7, p.x / Math.max(1, win.innerWidth) * 2 - 1)) : 0); + cue(kind, p ? Math.max(-.7, Math.min(.7, + (p.x + layer.getBoundingClientRect().left) / Math.max(1, win.innerWidth) * 2 - 1)) : 0); }; const moved = new Set(); for (const e of events) { @@ -345,10 +344,15 @@ export function createResolutionEffects(root, cue) { previous = current; previousIndex = index; } - // Moving/resizing the viewport invalidates projectile coordinates. - win.addEventListener("resize", clear); - const scroll = () => { if (!jumping && pendingFrame === null) clear(); }; - doc.addEventListener("scroll", scroll, true); + // Effects are attached to the board, so scrolling and BGS changing the + // iframe's height on completion cannot cancel a killing shot. A width + // change can reflow the ship/target columns and invalidate their positions. + let viewportWidth = win.innerWidth; + const resize = () => { + if (win.innerWidth !== viewportWidth) clear(); + viewportWidth = win.innerWidth; + }; + win.addEventListener("resize", resize); const visibility = () => { if (doc.hidden) clear(); }; doc.addEventListener("visibilitychange", visibility); return { @@ -357,8 +361,7 @@ export function createResolutionEffects(root, cue) { reset() { clear(); previous = null; previousIndex = -1; }, destroy() { clear(); layer.remove(); - win.removeEventListener("resize", clear); - doc.removeEventListener("scroll", scroll, true); + win.removeEventListener("resize", resize); doc.removeEventListener("visibilitychange", visibility); }, }; diff --git a/preview/style.css b/preview/style.css index 288fc68..2a6953b 100644 --- a/preview/style.css +++ b/preview/style.css @@ -1264,7 +1264,7 @@ input:not([type="checkbox"]):not([type="range"]) { .illustrated-systems { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); - gap: 2px; + gap: 12px 2px; margin: 4px 0; } .system-card { @@ -2672,8 +2672,9 @@ input:not([type="checkbox"]):not([type="range"]) { .planned-pawn b, .planned-pawn small { font-size: 10px; } .planned-pawn small { padding: 2px 3px; border: 1px dashed currentColor; border-radius: 3px; } -/* Resolution effects sit above the board without taking layout space or input. */ -.resolution-effects { position: fixed; inset: 0; z-index: 80; pointer-events: none; overflow: hidden; } +/* Keep effects in board coordinates, including while its scroller moves. */ +.flight-layout { position: relative; } +.resolution-effects { position: absolute; inset: 0; z-index: 80; pointer-events: none; overflow: clip; } .resolution-effects > span { position: absolute; pointer-events: none; } .resolution-effects .fx-pawn { z-index: 2; margin: 0; filter: drop-shadow(0 0 8px #91e7ed90); } .fx-beam { width: 0; height: 0; transform-origin: 0 0; }