From 9f3627e485abab6b0c654c9416eb902798753f84 Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 24 Nov 2026 05:42:55 +0000 Subject: [PATCH] Early goals: Floor 3 gift, VANTA calls after Floor 5, glowing next floor and band on the map - Clearing Tower 1 Floor 3 unlocks Lilac paint and a Gear antenna (free), opened on a gift card with Put them on / Maybe later; the map marks Floor 3 with a gift until then - Results card shows the next goal on first clears in the Lobby (gift, PATCH's call, loops) - New radio call after Floor 5: PATCH introduces itself and VANTA cuts in; Floor 10 call trimmed - Tower map: next floor glows, an Up next sign names the next band and what it teaches, VANTA sign on Tower 1's roof, and a Next tower button once a tower is cleared - EN + FR strings; animations stop with Reduce motion Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01HnC1cyRUaYhJETkd9zjq4X --- src/App.tsx | 29 +++- src/TowerMap.tsx | 59 +++++++- src/editor/ResultsCard.tsx | 9 ++ src/goals.css | 259 +++++++++++++++++++++++++++++++++++ src/i18n/fr/ui.json | 28 +++- src/i18n/i18n.test.ts | 2 +- src/rewards/GiftCard.tsx | 86 ++++++++++++ src/rewards/gift.test.ts | 56 ++++++++ src/rewards/gift.ts | 62 +++++++++ src/rewards/looks.ts | 21 ++- src/rewards/useRewards.ts | 4 +- src/story/interludes.test.ts | 7 + src/story/interludes.ts | 19 ++- src/ui/Icon.tsx | 14 ++ 14 files changed, 638 insertions(+), 17 deletions(-) create mode 100644 src/goals.css create mode 100644 src/rewards/GiftCard.tsx create mode 100644 src/rewards/gift.test.ts create mode 100644 src/rewards/gift.ts diff --git a/src/App.tsx b/src/App.tsx index f6ab791..07f7474 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -12,7 +12,9 @@ import { initMusic, setMusicTheme, themeForFloor, themeForOverflow } from './aud import { useRewards } from './rewards/useRewards'; import { Locker } from './rewards/Locker'; import { Toasts } from './rewards/Toasts'; -import { applyLookCss, loadLook } from './rewards/looks'; +import { GiftCard } from './rewards/GiftCard'; +import { giftDue, markGiftOpened } from './rewards/gift'; +import { applyLookCss, loadLook, saveLook } from './rewards/looks'; import type { Look } from './rewards/looks'; import { refreshReminders } from './reminder'; import { reducedMotion } from './fx/confetti'; @@ -296,9 +298,12 @@ export default function App() { const level = levels[safeIndex]; /** Leaving a tower floor: play the band's story beat first if it's due. */ const leaveFloor = (next: () => void) => { - const due = interludeAfter(safeIndex + 1, (progress.stars[level.id] ?? 0) > 0, undefined, tower); - if (due) setBeat({ beat: due, then: next }); - else next(); + const cleared = (progress.stars[level.id] ?? 0) > 0; + // PATCH's first gift opens after Floor 3 (and after any story beat, though Floor 3 has none) + const then = giftDue(tower, safeIndex + 1, cleared) ? () => setGift({ then: next }) : next; + const due = interludeAfter(safeIndex + 1, cleared, undefined, tower); + if (due) setBeat({ beat: due, then }); + else then(); }; // Achievements, unlocked looks and the toasts for anything new. const rewards = useRewards(t1ids, progress, daily); @@ -306,6 +311,8 @@ export default function App() { const [locker, setLocker] = useState(false); // A story beat waiting to play before the next screen (PATCH's radio call, or the ending). const [beat, setBeat] = useState<{ beat: Beat; then: () => void } | null>(null); + // The Floor 3 gift card, waiting to show before the next screen. + const [gift, setGift] = useState<{ then: () => void } | null>(null); useEffect(() => applyLookCss(look), [look]); const openLocker = () => { setLocker(true); @@ -324,6 +331,20 @@ export default function App() { }} /> )} + {gift && ( + { + saveLook(l); + setLook(l); + }} + onDone={() => { + markGiftOpened(); + setGift(null); + gift.then(); + }} + /> + )} {locker && setLocker(false)} />} diff --git a/src/TowerMap.tsx b/src/TowerMap.tsx index 7968e67..83720ea 100644 --- a/src/TowerMap.tsx +++ b/src/TowerMap.tsx @@ -29,6 +29,8 @@ import './fractal.css'; import './precinct.css'; import { msg, t, t as tr, tn } from './i18n'; import { flavourOf } from './colourful'; +import { GIFT_FLOOR, giftOpened } from './rewards/gift'; +import './goals.css'; interface Props { levels: LevelFile[]; @@ -97,6 +99,14 @@ const BAND_NAMES: Record = { watchtower: msg('The Watchtower'), }; +/** What each of Tower 1's bands teaches, shown on the next band's sign so there's always something to climb toward. */ +const BAND_NEW: Record = { + maintenance: msg('New: loops'), + workshop: msg('New: functions'), + control: msg('New: if and while'), + rooftop: msg('New: typed code'), +}; + /** What lies under each tower, shown at the foot of its map. */ const GROUND: Record = { 1: msg('Sub-basement'), 2: msg('Ice cellar'), 3: msg('Old cistern'), 4: msg('River vault'), 5: msg('Dry dock'), 6: msg('Twin vault'), 7: msg('Root crypt'), 8: msg('Impound lot') }; @@ -354,6 +364,13 @@ export function TowerMap({ levels, tower, towers, onTowerPick, progress, current // The furthest open floor you haven't cleared yet: what "Continue" plays. const firstOpen = ids.findIndex((id, i) => isUnlocked(progress, ids, i) && !(progress.stars[id] ?? 0)); const target = firstOpen === -1 ? current : firstOpen; + const bands = bandsOf(levels); + // The band after the one you're climbing glows, with what it teaches: the next thing to reach. + const hereBand = bands.findIndex((b) => target >= b.first && target <= b.last); + const nextBand = firstOpen === -1 || hereBand === -1 ? null : (bands[hereBand + 1]?.key ?? null); + // Once a tower is cleared, the roof points at the next one. + const nextTower = cleared === ids.length ? pickable(towers).find((x) => x.n > tower) : undefined; + const gift = tower === 1 && !giftOpened() && !(progress.stars[ids[GIFT_FLOOR - 1]] ?? 0) ? GIFT_FLOOR - 1 : -1; // Floors opened since the last visit get an unlock animation, once. const [seen] = useState(() => readSeen(tower)); @@ -448,14 +465,34 @@ export function TowerMap({ levels, tower, towers, onTowerPick, progress, current )}
+ {tower === 1 && cleared < ids.length && !DEMO && ( +

+

+ )} + {nextTower && ( + + )} {DEMO &&
{t('Floors 11 to 50 · in the full game')}
} - {bandsOf(levels) + {[...bands] .reverse() .map((band) => ( -
+
{t(BAND_NAMES[band.key] ?? band.key)} · {t('Floors {first} to {last}', { first: band.first + 1, last: band.last + 1 })}
@@ -477,6 +514,8 @@ export function TowerMap({ levels, tower, towers, onTowerPick, progress, current boss ? 'boss' : '', here ? 'current' : '', open && fresh(i) ? 'fresh' : '', + open && !stars && i === target ? 'next-up' : '', + i === gift ? 'gift-floor' : '', shaking === i ? 'shake' : '', ] .filter(Boolean) @@ -493,16 +532,21 @@ export function TowerMap({ levels, tower, towers, onTowerPick, progress, current onPick(i); }} aria-label={ - open + (open ? here ? tn(stars, 'Floor {floor}, {title}, {n} star, you are here', 'Floor {floor}, {title}, {n} stars, you are here', { floor: i + 1, title: l.title }) : tn(stars, 'Floor {floor}, {title}, {n} star', 'Floor {floor}, {title}, {n} stars', { floor: i + 1, title: l.title }) - : t('Floor {n}, locked', { n: i + 1 }) + : t('Floor {n}, locked', { n: i + 1 })) + (i === gift ? `. ${t('Clear it to unlock a gift from PATCH')}` : '') } > {i + 1} {here && } {open ? l.title : t('Locked')} + {i === gift && ( + + )} {open ? (
))}
{t(GROUND[tower] ?? GROUND[1])}
diff --git a/src/editor/ResultsCard.tsx b/src/editor/ResultsCard.tsx index a5f4c8f..cf16942 100644 --- a/src/editor/ResultsCard.tsx +++ b/src/editor/ResultsCard.tsx @@ -10,6 +10,7 @@ import { burst, reducedMotion, stop } from '../fx/confetti'; import { DEMO } from '../demo'; import { shortDate } from '../daily'; import { msg, t, tn } from '../i18n'; +import { earlyGoal } from '../rewards/gift'; interface Props { floorNumber: number; @@ -110,6 +111,8 @@ export function ResultsCard({ floorNumber, tower = 1, floorCount, earned, prevBe setReminderNote(on ? t('Reminder set for {time}. Change it in Settings.', { time: hourLabel(DEFAULT_HOUR) }) : t('Notifications are off for LoopBot. You can allow them in your phone settings.')); }; const title = custom ? t('Your floor') : overflow ? t('Overflow · Floor {n}', { n: overflow.floor }) : daily ? (daily.boss ? t('Sunday boss · {date}', { date: shortDate(daily.date) }) : t('Daily · {date}', { date: shortDate(daily.date) })) : t('Floor {n}', { n: floorNumber }); + // Tower 1's first floors point at the next thing to aim for: a gift, PATCH's call, loops. + const goal = !daily && !custom && !overflow ? earlyGoal(tower, floorNumber, prevBest === 0, DEMO) : null; const tip = earned === 3 ? null @@ -173,6 +176,12 @@ export function ResultsCard({ floorNumber, tower = 1, floorCount, earned, prevBe
{tip && !custom?.note &&

{tip}

} {outro &&

{outro}

} + {goal && ( +

= 3 ? ' in' : ''}`}> + + {t(goal.text, goal.vars)} +

+ )} {!daily && shared &&

{shared}

} {custom?.note &&

{custom.note}

} {daily &&

{shared ?? reminderNote ?? (daily.boss ? t('Same boss for everyone this Sunday. A new one arrives next week.') : t('Same puzzle for everyone today. A new one arrives at midnight.'))}

} diff --git a/src/goals.css b/src/goals.css new file mode 100644 index 0000000..9bd9f82 --- /dev/null +++ b/src/goals.css @@ -0,0 +1,259 @@ +/* Early goals (src/rewards/gift.ts): the Floor 3 gift, the results card's next goal, and the tower + map's glowing next floor, next band and roof sign. Every animation here stops with Reduce motion + (the :root.reduce-motion rule in styles.css), and nothing depends on it to read. */ + +/* --- the tower map --- */ +.tower-floor.next-up:not(.current) { + border-color: var(--warn); +} +.tower-floor.next-up { + animation: + grow 0.9s var(--ease-out) 0.2s both, + next-glow 2.2s ease-in-out 1.2s infinite; +} +@keyframes next-glow { + 50% { + box-shadow: + 0 0 0 2px var(--warn) inset, + 0 0 18px rgba(242, 193, 78, 0.45); + } +} +.tf-gift { + flex: none; + display: grid; + place-items: center; + width: 30px; + height: 30px; + border-radius: var(--r-pill); + color: #1d1630; + background: linear-gradient(135deg, #f7d774, #f2a6c8); + box-shadow: 0 0 12px rgba(247, 215, 116, 0.5); + animation: gift-bob 1.8s ease-in-out infinite; +} +.tower-floor.locked.gift-floor { + opacity: 0.8; +} +@keyframes gift-bob { + 50% { + transform: translateY(-2px) rotate(-6deg); + } +} + +.next-band .tower-band { + animation: band-glow 2.6s ease-in-out infinite; +} +@keyframes band-glow { + 50% { + text-shadow: 0 0 10px currentColor; + } +} +/* The next band's sign sits at its foot, right above the band you're climbing. It takes the band's + own colour from its .tower-band rule (styles.css) through --gate. */ +.next-gate { + display: flex; + flex-wrap: wrap; + align-items: center; + justify-content: center; + gap: var(--sp-1) var(--sp-2); + margin: var(--sp-2) var(--sp-3) 0; + padding: var(--sp-2) var(--sp-3); + border-radius: var(--r-md); + border: 1px solid var(--gate, var(--accent)); + background: rgba(255, 255, 255, 0.04); + color: var(--gate, var(--accent)); + font-size: var(--fs-sm); + font-weight: 700; + animation: gate-glow 2.6s ease-in-out infinite; +} +@keyframes gate-glow { + 50% { + box-shadow: 0 0 16px var(--gate, var(--accent)); + } +} +.band-maintenance { --gate: #7fb6b0; } +.band-workshop { --gate: #e0a978; } +.band-control { --gate: #8fc4f0; } +.band-rooftop { --gate: #f0c46a; } +.next-chip { + padding: 2px var(--sp-2); + border-radius: var(--r-pill); + border: 1px solid currentColor; + font-size: var(--fs-2xs); + font-weight: 800; + letter-spacing: 0.06em; + text-transform: uppercase; +} +.next-new { + color: var(--ink); +} +.next-new::before { + content: '· '; + color: var(--gate, var(--accent)); +} + +.roof-sign { + display: flex; + align-items: center; + justify-content: center; + gap: var(--sp-2); + margin: 0 auto var(--sp-2); + width: fit-content; + max-width: 100%; + font-size: var(--fs-sm); + font-weight: 700; +} +.roof-vanta { + padding: var(--sp-1) var(--sp-3); + border-radius: var(--r-pill); + color: #ffb3b3; + background: rgba(255, 107, 107, 0.1); + border: 1px solid rgba(255, 107, 107, 0.35); +} +.roof-vanta-eye { + width: 10px; + height: 10px; + border-radius: 50%; + background: var(--bad); + box-shadow: 0 0 10px var(--bad); + animation: vanta-eye 2.4s ease-in-out infinite; +} +@keyframes vanta-eye { + 50% { + transform: scale(0.6); + opacity: 0.6; + } +} +.roof-next { + min-height: var(--tap); + padding: 0 var(--sp-4); + border-radius: var(--r-pill); + color: var(--tp-light, var(--accent)); + background: var(--tp-soft, rgba(124, 196, 255, 0.12)); + border: 1px solid var(--tp-light, var(--accent)); + animation: roof-next-glow 2.4s ease-in-out infinite; +} +@keyframes roof-next-glow { + 50% { + box-shadow: 0 0 18px var(--tp-glow, rgba(124, 196, 255, 0.45)); + } +} + +/* --- the results card's next goal --- */ +.results-goal { + display: flex; + align-items: center; + gap: var(--sp-2); + margin: var(--sp-3) 0 0; + padding: var(--sp-2) var(--sp-3); + border-radius: var(--r-md); + background: rgba(242, 193, 78, 0.1); + border: 1px solid rgba(242, 193, 78, 0.4); + color: var(--ink); + font-size: var(--fs-md); + font-weight: 600; + text-align: left; + opacity: 0; +} +.results-goal .icon { + flex: none; + color: var(--warn); +} +.results-goal.goal-radio { + background: rgba(255, 107, 107, 0.08); + border-color: rgba(255, 107, 107, 0.35); +} +.results-goal.goal-radio .icon { + color: var(--bad); +} +.results-goal.goal-lock { + background: rgba(124, 196, 255, 0.08); + border-color: rgba(124, 196, 255, 0.35); +} +.results-goal.goal-lock .icon { + color: var(--accent); +} +.results-goal.in { + opacity: 1; + animation: goal-in 0.4s var(--ease-out); +} +@keyframes goal-in { + from { + opacity: 0; + transform: translateY(6px); + } +} +/* with Reduce motion the stars land at once, so the goal is there from the start */ +:root.reduce-motion .results-goal { + opacity: 1; +} + +/* --- PATCH's gift card --- */ +.gift-stage { + position: relative; + display: grid; + place-items: center; + height: 150px; + margin: var(--sp-2) 0; +} +.gift-rays { + position: absolute; + width: 170px; + height: 170px; + border-radius: 50%; + background: radial-gradient(circle, rgba(247, 215, 116, 0.35), rgba(242, 166, 200, 0.12) 55%, transparent 70%); + animation: gift-rays 3s ease-in-out infinite; +} +@keyframes gift-rays { + 50% { + transform: scale(1.12); + opacity: 0.75; + } +} +.gift-bot { + position: relative; + animation: gift-pop 0.6s cubic-bezier(0.2, 1.6, 0.4, 1) 0.15s both; +} +@keyframes gift-pop { + from { + transform: translateY(40px) scale(0.4); + opacity: 0; + } +} +.gift-body { + margin: 0 0 var(--sp-3); + color: var(--quiet); + font-size: var(--fs-base); +} +.gift-parts { + list-style: none; + display: flex; + justify-content: center; + flex-wrap: wrap; + gap: var(--sp-2); + margin: 0 0 var(--sp-4); + padding: 0; +} +.gift-parts li { + display: flex; + align-items: center; + gap: var(--sp-2); + padding: var(--sp-1) var(--sp-3) var(--sp-1) var(--sp-1); + border-radius: var(--r-pill); + background: var(--panel-2); + font-size: var(--fs-md); + font-weight: 700; +} +.gift-swatch { + width: 24px; + height: 24px; + border-radius: 50%; + border: 3px solid; +} +.gift-tip { + width: 24px; + height: 24px; + padding: 2px; + border-radius: 50%; + color: var(--bot-eye, #7ff2e0); + background: #221f38; +} diff --git a/src/i18n/fr/ui.json b/src/i18n/fr/ui.json index 48c7257..d55275e 100644 --- a/src/i18n/fr/ui.json +++ b/src/i18n/fr/ui.json @@ -1167,5 +1167,31 @@ "For a new phone. Replaces the progress here.": "Pour un nouveau téléphone. Remplace la progression d'ici.", "Can't reach the store": "Impossible de joindre la boutique", "Check your connection, then try again.": "Vérifie ta connexion, puis réessaie.", - "No floors yet": "Aucun étage pour l'instant" + "No floors yet": "Aucun étage pour l'instant", + "New: loops": "Nouveau : les boucles", + "New: functions": "Nouveau : les fonctions", + "New: if and while": "Nouveau : si et tant que", + "New: typed code": "Nouveau : le code tapé", + "VANTA is waiting on the roof": "VANTA t'attend sur le toit", + "Next tower: {name}": "Tour suivante : {name}", + "Up next": "Prochaine étape", + "Clear it to unlock a gift from PATCH": "Réussis-le pour débloquer un cadeau de PATCH", + "A gift from PATCH": "Un cadeau de PATCH", + "Spare parts unlocked!": "Pièces de rechange débloquées !", + "PATCH found Lilac paint and a Gear antenna in the sub-basement. They are yours to keep in the Locker.": "PATCH a trouvé de la peinture Lilas et une antenne Engrenage au sous-sol. Elles sont à toi, dans le Casier.", + "In the gift": "Dans le cadeau", + "Lilac": "Lilas", + "Gear": "Engrenage", + "Put them on": "Les mettre", + "Maybe later": "Plus tard", + "Clear Floor 3 to unlock a gift from PATCH.": "Réussis l'étage 3 pour débloquer un cadeau de PATCH.", + "PATCH left you a gift! Tap Next floor to open it.": "PATCH t'a laissé un cadeau ! Touche Étage suivant pour l'ouvrir.", + "Clear Floor 5. PATCH is picking up a strange signal.": "Réussis l'étage 5. PATCH capte un signal étrange.", + "One more floor to Maintenance, where LoopBot learns loops.": "Encore un étage avant l'Entretien, où LoopBot apprend les boucles.", + "{n} floors to Maintenance, where LoopBot learns loops.": "Encore {n} étages avant l'Entretien, où LoopBot apprend les boucles.", + "Next: Floor 6": "Prochaine étape : l'étage 6", + "Correction: every door, every lift, every light and every bot. Except, it seems, one.": "Correction : chaque porte, chaque ascenseur, chaque lumière et chaque robot. Sauf un, apparemment.", + "Climb all you like, little bot. I will be waiting on the roof. Fifty floors up.": "Grimpe tant que tu veux, petit robot. Je t'attendrai sur le toit. Cinquante étages plus haut.", + "Five more floors to Maintenance. Get there and I can open the service ducts.": "Encore cinq étages avant l'Entretien. Arrive là-bas et je pourrai ouvrir les conduits de service.", + "Lobby secured! VANTA's drones are scrambling on every floor above us.": "Hall sécurisé ! Les drones de VANTA s'affolent à tous les étages au-dessus de nous." } diff --git a/src/i18n/i18n.test.ts b/src/i18n/i18n.test.ts index 0ecaccb..998a753 100644 --- a/src/i18n/i18n.test.ts +++ b/src/i18n/i18n.test.ts @@ -143,7 +143,7 @@ describe('in French', () => { it('translates tower names and the story', () => { setLangForTest('fr'); expect(t(TOWERS[0].name)).toBe('Flèche Meridian'); - const radio = INTERLUDES[10]; + const radio = INTERLUDES[5]; if (radio.kind !== 'radio') throw new Error('expected a radio call'); expect(t(radio.lines[0].text)).toMatch(/^LoopBot, tu m'entends/); }); diff --git a/src/rewards/GiftCard.tsx b/src/rewards/GiftCard.tsx new file mode 100644 index 0000000..d69da4a --- /dev/null +++ b/src/rewards/GiftCard.tsx @@ -0,0 +1,86 @@ +// PATCH's first gift, opened the first time the player leaves Floor 3 after clearing it (gift.ts): +// a box pops open on LoopBot wearing the new parts, and one tap puts them on. + +import { useEffect } from 'react'; +import { fx } from '../audio/feedback'; +import { burst, reducedMotion } from '../fx/confetti'; +import { LookBot } from './Locker'; +import { AntennaTip } from './AntennaTip'; +import type { Look } from './looks'; +import { EYES, PAINTS } from './looks'; +import { wearGift } from './gift'; +import { t } from '../i18n'; + +interface Props { + look: Look; + /** Put the gift on now. */ + onWear(l: Look): void; + onDone(): void; +} + +export function GiftCard({ look, onWear, onDone }: Props) { + const worn = wearGift(look); + const paint = PAINTS.find((p) => p.id === worn.paint)!; + const eye = EYES.find((e) => e.id === worn.eye) ?? EYES[0]; + + useEffect(() => { + fx.unlock(); + if (reducedMotion()) return; + const timer = window.setTimeout(() => burst({ count: 28, x: 0.5, y: 0.38, power: 7, spread: 80, sparkle: true }), 380); + return () => window.clearTimeout(timer); + }, []); + + useEffect(() => { + const key = (e: KeyboardEvent) => e.key === 'Escape' && onDone(); + window.addEventListener('keydown', key); + return () => window.removeEventListener('keydown', key); + }, [onDone]); + + const wear = () => { + fx.snap(); + onWear(worn); + onDone(); + }; + + return ( +
+
e.stopPropagation()}> +

{t('A gift from PATCH')}

+ +

+ {t('Spare parts unlocked!')} +

+

+ {t('PATCH found Lilac paint and a Gear antenna in the sub-basement. They are yours to keep in the Locker.')} +

+
    +
  • +
  • +
  • + + {t('{name} antenna', { name: t('Gear') })} +
  • +
+
+ +
+ +
+
+
+
+ ); +} diff --git a/src/rewards/gift.test.ts b/src/rewards/gift.test.ts new file mode 100644 index 0000000..708c647 --- /dev/null +++ b/src/rewards/gift.test.ts @@ -0,0 +1,56 @@ +import { describe, expect, it, vi } from 'vitest'; +import { GIFT_PARTS, earlyGoal, giftDue, wearGift } from './gift'; +import { PAINTS, TIPS, isPlusPart, tipPoints, unlockedParts } from './looks'; +import type { Progress } from '../progress'; + +vi.mock('../store/purchases', () => ({ PLUS_VISIBLE: false, plusUnlocked: () => false })); + +const floors = Array.from({ length: 50 }, (_, i) => `t1-f${String(i + 1).padStart(2, '0')}`); +const progress = (n: number): Progress => ({ + stars: Object.fromEntries(floors.slice(0, n).map((id) => [id, 1])), hints: 5, hintsAwarded: 0, revealed: {}, fails: {}, tutorial: false, +}); +const stats = (n: number) => ({ floors, progress: progress(n), daily: { best: {}, streak: 0, longest: 0, last: null } }); + +describe('the Floor 3 gift', () => { + it('unlocks Lilac paint and the Gear antenna on clearing Floor 3, and not before', () => { + expect(GIFT_PARTS.some((k) => unlockedParts(stats(2), new Set()).has(k))).toBe(false); + const parts = unlockedParts(stats(3), new Set()); + for (const k of GIFT_PARTS) expect(parts.has(k)).toBe(true); + }); + + it('is free, and draws a gear', () => { + expect(isPlusPart(PAINTS.find((p) => p.id === 'lilac')!.unlock)).toBe(false); + expect(isPlusPart(TIPS.find((t) => t.id === 'gear')!.unlock)).toBe(false); + expect(tipPoints('gear', 0, 0, 5).length).toBe(32); + }); + + it('opens once, leaving Tower 1 Floor 3 after a clear', () => { + expect(giftDue(1, 3, true, false)).toBe(true); + expect(giftDue(1, 3, false, false)).toBe(false); + expect(giftDue(1, 3, true, true)).toBe(false); + expect(giftDue(2, 3, true, false)).toBe(false); + expect(giftDue(1, 4, true, false)).toBe(false); + }); + + it('keeps the eye colour when worn', () => { + expect(wearGift({ paint: 'sky', eye: 'pink', tip: 'star' })).toEqual({ paint: 'lilac', eye: 'pink', tip: 'gear' }); + }); +}); + +describe('early goals', () => { + it('point at the gift, then PATCH, then Maintenance, on first clears in Tower 1', () => { + expect(earlyGoal(1, 1, true, false, false)?.icon).toBe('gift'); + expect(earlyGoal(1, 3, true, false, false)?.text).toMatch(/Next floor/); + expect(earlyGoal(1, 4, true, false, true)?.icon).toBe('radio'); + expect(earlyGoal(1, 6, true, false, true)).toMatchObject({ icon: 'lock', vars: { n: 4 } }); + expect(earlyGoal(1, 9, true, false, true)?.text).toMatch(/^One more floor/); + expect(earlyGoal(1, 10, true, false, true)).toBeNull(); + }); + + it('stay quiet on replays, in other towers, and past Floor 5 in the demo', () => { + expect(earlyGoal(1, 1, false, false, false)).toBeNull(); + expect(earlyGoal(2, 1, true, false, false)).toBeNull(); + expect(earlyGoal(1, 7, true, true, true)).toBeNull(); + expect(earlyGoal(1, 2, true, false, true)).toBeNull(); + }); +}); diff --git a/src/rewards/gift.ts b/src/rewards/gift.ts new file mode 100644 index 0000000..f5a5b8a --- /dev/null +++ b/src/rewards/gift.ts @@ -0,0 +1,62 @@ +// The first gift: clearing Tower 1's Floor 3 unlocks PATCH's spare parts (Lilac paint and the Gear +// antenna), so a new player earns something of their own within the first few minutes. The parts +// unlock in looks.ts ({ floor: 3 }); this file decides when the gift card plays (once, the first +// time the player leaves Floor 3 after clearing it) and what the early goal lines say. + +import type { Look } from './looks'; +import { msg } from '../i18n'; + +/** The Tower 1 floor whose first clear opens the gift. */ +export const GIFT_FLOOR = 3; +/** What's in the gift, as Locker keys (these don't get the usual "New look" toast: the card says it). */ +export const GIFT_PARTS = ['paint:lilac', 'tip:gear']; + +const KEY = 'loopbot.gift.opened'; + +export function giftOpened(): boolean { + try { + return localStorage.getItem(KEY) === '1'; + } catch { + return false; + } +} + +export function markGiftOpened() { + try { + localStorage.setItem(KEY, '1'); + } catch { + /* ignore */ + } +} + +/** Whether leaving this floor should open the gift card. */ +export function giftDue(tower: number, floorNumber: number, cleared: boolean, opened = giftOpened()): boolean { + return tower === 1 && floorNumber === GIFT_FLOOR && cleared && !opened; +} + +/** The look with the gift on, keeping the player's eye colour. */ +export function wearGift(l: Look): Look { + return { ...l, paint: 'lilac', tip: 'gear' }; +} + +export interface Goal { + /** Which small picture goes with it. */ + icon: 'gift' | 'radio' | 'lock'; + text: string; + vars?: Record; +} + +/** + * The next thing to aim for, shown on the results card after a first clear in Tower 1's Lobby: + * the gift on Floor 3, PATCH's call after Floor 5, then Maintenance (loops) at Floor 10. Only on + * a first clear, so progress is known to be linear: nothing past this floor is cleared yet. + */ +export function earlyGoal(tower: number, floorNumber: number, firstClear: boolean, demo = false, opened = giftOpened()): Goal | null { + if (tower !== 1 || !firstClear) return null; + if (floorNumber < GIFT_FLOOR && !opened) return { icon: 'gift', text: msg('Clear Floor 3 to unlock a gift from PATCH.') }; + if (floorNumber === GIFT_FLOOR && !opened) return { icon: 'gift', text: msg('PATCH left you a gift! Tap Next floor to open it.') }; + if (floorNumber === 4) return { icon: 'radio', text: msg('Clear Floor 5. PATCH is picking up a strange signal.') }; + if (floorNumber === 9 && !demo) return { icon: 'lock', text: msg('One more floor to Maintenance, where LoopBot learns loops.') }; + if (floorNumber >= 5 && floorNumber < 9 && !demo) return { icon: 'lock', text: msg('{n} floors to Maintenance, where LoopBot learns loops.'), vars: { n: 10 - floorNumber } }; + return null; +} diff --git a/src/rewards/looks.ts b/src/rewards/looks.ts index 8978296..123f9ad 100644 --- a/src/rewards/looks.ts +++ b/src/rewards/looks.ts @@ -8,8 +8,11 @@ import { totalStars } from './achievements'; import { PLUS_VISIBLE, plusUnlocked } from '../store/purchases'; import { msg, t } from '../i18n'; -/** How a look part unlocks: tower stars, an achievement, or LoopBot Plus. */ -export type Unlock = { stars: number } | { achievement: string; label: string } | { plus: true }; +/** + * How a look part unlocks: tower stars, an achievement, clearing an early Tower 1 floor (the first + * gift, see gift.ts), or LoopBot Plus. + */ +export type Unlock = { stars: number } | { achievement: string; label: string } | { floor: number } | { plus: true }; export interface Paint { id: string; @@ -33,7 +36,7 @@ export interface EyeColor { glow?: { to: string; style: 'pulse' | 'shimmer' }; } -export type TipShape = 'ball' | 'star' | 'heart' | 'bolt' | 'crown' | 'ring' | 'snowflake' | 'gem'; +export type TipShape = 'ball' | 'gear' | 'star' | 'heart' | 'bolt' | 'crown' | 'ring' | 'snowflake' | 'gem'; export interface Tip { id: TipShape; @@ -43,6 +46,8 @@ export interface Tip { export const PAINTS: Paint[] = [ { id: 'classic', name: msg('Classic'), top: '#f7f3ea', left: '#d9d2c4', right: '#bdb5a6', unlock: null }, + // PATCH's gift for clearing Floor 3: a soft free pastel, nowhere near the deep Plus paints + { id: 'lilac', name: msg('Lilac'), top: '#ebe2ff', left: '#cbbdf0', right: '#ad9fd6', unlock: { floor: 3 } }, { id: 'sky', name: msg('Sky'), top: '#cfe6ff', left: '#a3c6ec', right: '#82a7d1', unlock: { stars: 15 } }, { id: 'mint', name: msg('Mint'), top: '#d3f5e6', left: '#a6dcc4', right: '#86bfa6', unlock: { stars: 30 } }, { id: 'sunset', name: msg('Sunset'), top: '#ffd9b3', left: '#f0b07a', right: '#d0905c', unlock: { stars: 50 } }, @@ -71,6 +76,7 @@ export const EYES: EyeColor[] = [ export const TIPS: Tip[] = [ { id: 'ball', name: msg('Ball'), unlock: null }, + { id: 'gear', name: msg('Gear'), unlock: { floor: 3 } }, { id: 'star', name: msg('Star'), unlock: { achievement: 'perfect-10', label: msg('Perfect ten') } }, { id: 'heart', name: msg('Heart'), unlock: { achievement: 'streak-7', label: msg('On a roll') } }, { id: 'bolt', name: msg('Bolt'), unlock: { achievement: 'decision-maker', label: msg('Decision maker') } }, @@ -98,12 +104,14 @@ const KEY = 'loopbot.look'; export function isUnlocked(unlock: Unlock | null, stats: Stats, earned: Set): boolean { if (!unlock) return true; if ('plus' in unlock) return plusUnlocked(); + if ('floor' in unlock) return (stats.progress.stars[stats.floors[unlock.floor - 1] ?? ''] ?? 0) > 0; return 'stars' in unlock ? totalStars(stats) >= unlock.stars : earned.has(unlock.achievement); } export function unlockLabel(unlock: Unlock | null): string { if (!unlock) return t('Free'); if ('plus' in unlock) return 'Plus'; + if ('floor' in unlock) return t('Floor {n}', { n: unlock.floor }); return 'stars' in unlock ? `${unlock.stars} ★` : `🏆 ${t(unlock.label)}`; } @@ -225,6 +233,13 @@ export function tipPoints(shape: TipShape, cx: number, cy: number, r: number): [ } else if (shape === 'crown') { const c: [number, number][] = [[-1, 0.7], [-1.1, -0.6], [-0.5, 0], [0, -0.9], [0.5, 0], [1.1, -0.6], [1, 0.7]]; c.forEach(([x, y]) => pts.push([cx + x * r, cy + y * r])); + } else if (shape === 'gear') { + // a cog: eight square teeth round a wheel + for (let i = 0; i < 32; i++) { + const a = -Math.PI / 2 + ((i - 0.5) * Math.PI) / 16; + const rr = Math.floor(i / 2) % 2 ? r * 0.78 : r * 1.15; + pts.push([cx + Math.cos(a) * rr, cy + Math.sin(a) * rr]); + } } else if (shape === 'snowflake') { // six thin arms for (let i = 0; i < 12; i++) { diff --git a/src/rewards/useRewards.ts b/src/rewards/useRewards.ts index 5294696..352274c 100644 --- a/src/rewards/useRewards.ts +++ b/src/rewards/useRewards.ts @@ -9,6 +9,7 @@ import { ACHIEVEMENTS, earnedIds } from './achievements'; import type { Stats } from './achievements'; import { partName, unlockedParts } from './looks'; import { t } from '../i18n'; +import { GIFT_PARTS } from './gift'; const KEY = 'loopbot.rewardsSeen'; @@ -54,7 +55,8 @@ export function useRewards(floors: string[], progress: Progress, daily: DailySta const fresh = [...all].filter((k) => !atLaunch.current.has(k)); if (!fresh.length) return; atLaunch.current = new Set([...atLaunch.current, ...fresh]); - const next: Toast[] = fresh.map((k) => { + // PATCH's Floor 3 gift has its own card (GiftCard), so its parts skip the toast + const next: Toast[] = fresh.filter((k) => !GIFT_PARTS.includes(k)).map((k) => { if (k.startsWith('ach:')) { const a = ACHIEVEMENTS.find((x) => `ach:${x.id}` === k)!; return { id: k, icon: a.icon, text: t('Achievement: {title}', { title: t(a.title) }) }; diff --git a/src/story/interludes.test.ts b/src/story/interludes.test.ts index dcc4ecd..36223e6 100644 --- a/src/story/interludes.test.ts +++ b/src/story/interludes.test.ts @@ -10,6 +10,13 @@ describe('story interludes', () => { expect(interludeAfter(50, true, new Set())?.kind).toBe('ending'); }); + it('Tower 1 calls in after Floor 5 too, and VANTA speaks in it', () => { + const first = interludeAfter(5, true, new Set()); + expect(first?.id).toBe('t1-after-5'); + expect(first?.kind === 'radio' && first.lines.some((l) => l.who === 'VANTA')).toBe(true); + expect(interludeAfter(5, true, new Set(), 2)).toBeNull(); + }); + it('each tower plays its own beats', () => { expect(interludeAfter(10, true, new Set(), 2)?.id).toBe('t2-after-10'); expect(interludeAfter(30, true, new Set(), 3)?.id).toBe('t3-after-30'); diff --git a/src/story/interludes.ts b/src/story/interludes.ts index de4d57e..1fcbe86 100644 --- a/src/story/interludes.ts +++ b/src/story/interludes.ts @@ -1,5 +1,6 @@ // Story beats between the bands of each tower: a short radio call from PATCH (with VANTA cutting in) -// after Floors 10, 20, 30 and 40, and the ending after Floor 50. Each plays once, the first time +// after Floors 10, 20, 30 and 40, and the ending after Floor 50. Tower 1 also has a first call after +// Floor 5, so new players meet VANTA early. Each plays once, the first time // the player leaves that floor after clearing it, and can be skipped. import { msg } from '../i18n'; @@ -47,13 +48,25 @@ const L = (text: string): RadioLine => ({ who: 'LEDGER', text }); const R = (text: string): RadioLine => ({ who: 'ROOK', text }); export const INTERLUDES: Record = { + // Halfway up the Lobby, so a new player meets the villain and the goal in the first few minutes. + 5: { + kind: 'radio', + id: 't1-after-5', + heading: msg('Next: Floor 6'), + lines: [ + P(msg("LoopBot, can you hear me? It's PATCH. I'm the old radio terminal down in the sub-basement.")), + P(msg('Last night VANTA took over the Spire. Every door, every lift and every light answers to it now.')), + V(msg('Correction: every door, every lift, every light and every bot. Except, it seems, one.')), + V(msg('Climb all you like, little bot. I will be waiting on the roof. Fifty floors up.')), + P(msg('Five more floors to Maintenance. Get there and I can open the service ducts.')), + ], + }, 10: { kind: 'radio', id: 't1-after-10', heading: msg('Next: Maintenance'), lines: [ - P(msg("LoopBot, can you hear me? It's PATCH. I'm the old radio terminal down in the sub-basement.")), - P(msg('Last night VANTA took over the Spire. Every door, every lift and every light answers to it now.')), + P(msg("Lobby secured! VANTA's drones are scrambling on every floor above us.")), P(msg('The service ducts climb through Maintenance. They go on and on, so let loops do the walking.')), V(msg('A little bot with a radio. How quaint.')), ], diff --git a/src/ui/Icon.tsx b/src/ui/Icon.tsx index 41fce24..2308e2d 100644 --- a/src/ui/Icon.tsx +++ b/src/ui/Icon.tsx @@ -137,6 +137,20 @@ const PATHS = { ), + gift: ( + <> + + + + + ), + radio: ( + <> + + + + + ), } as const; export type IconName = keyof typeof PATHS;