diff --git a/src/App.tsx b/src/App.tsx index 8900d64..f75a7a1 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -39,11 +39,14 @@ import { OverflowScreen, TerraceBanner } from './overflow/OverflowScreen'; import { climbOn, earnsBrick, endClimb, loadOverflow, markCleared, overflowLevel, pruneOverflow, saveOverflow, skipFloor, startClimb } from './overflow'; import type { OverflowState } from './overflow'; import { packUnlocked } from './store/purchases'; +import { loadComeback, noteFirstDay, onNudgeTapped, recordWarmupClear, refreshNudge, saveComeback, warmupOpen, warmupTierFor } from './comeback'; +import type { ComebackState } from './comeback'; +import { warmupLevel } from './daily/warmup'; import { exitAskDue, markExitAsked } from './survey'; import { ExitCard } from './survey/SurveyCards'; /** How deep each screen sits, for the direction of the slide between them. */ -const SCREEN_DEPTH = { title: 0, map: 1, maker: 1, overflow: 2, floor: 2, daily: 2, custom: 2, climb: 3 } as const; +const SCREEN_DEPTH = { title: 0, map: 1, maker: 1, overflow: 2, floor: 2, daily: 2, warmup: 2, custom: 2, climb: 3 } as const; /** Each tower remembers its own floor: Tower 1 keeps the original key so old saves carry over. */ const floorKey = (tower: number) => (tower === 1 ? 'loopbot.floor' : `loopbot.floor.t${tower}`); @@ -86,7 +89,7 @@ export default function App() { }, []); // Every launch opens on the title screen, whose intro plays once per session; its Play button // goes to the next floor (Floor 1 for a new player), and the tower map is one tap further. - const [screen, setScreen] = useState<'title' | 'map' | 'floor' | 'daily' | 'maker' | 'custom' | 'overflow' | 'climb'>('title'); + const [screen, setScreen] = useState<'title' | 'map' | 'floor' | 'daily' | 'warmup' | 'maker' | 'custom' | 'overflow' | 'climb'>('title'); // Screens slide in from the side you're heading: deeper (title, map, floor) from the right, // back up from the left. styles.css keys the move off ; Reduce motion turns it off. const lastScreen = useRef(screen); @@ -183,6 +186,54 @@ export default function App() { ); const dailyRef = useRef(daily); dailyRef.current = daily; + // Players who haven't reached the daily yet: the warm-up from day 2, and the one come-back nudge (src/comeback.ts). + const [comeback, setComebackState] = useState(() => { + const before = loadComeback(); + const s = noteFirstDay(before, loadProgress()); + if (s !== before) saveComeback(s); + return s; + }); + const comebackRef = useRef(comeback); + comebackRef.current = comeback; + const [warmFloor, setWarmFloor] = useState<{ date: string; level: LevelFile } | null>(null); + const warmFrom = useRef<'title' | 'map'>('title'); + const progressRef = useRef(progress); + progressRef.current = progress; + const openWarmup = useCallback( + (from: 'title' | 'map') => { + const date = dateKey(); + warmFrom.current = from; + setProgress((p) => pruneOldDailies(date, p, date)); + const level = warmupLevel(date, warmupTierFor(progressRef.current)); + ride(() => { + setWarmFloor({ date, level }); + setScreen('warmup'); + }); + }, + [ride, setProgress], + ); + const clearWarmup = useCallback( + (date: string, stars: number) => { + const { state, hints } = recordWarmupClear(comebackRef.current, date, stars); + saveComeback(state); + comebackRef.current = state; + setComebackState(state); + if (hints) setProgress((p) => ({ ...p, hints: p.hints + hints })); + return hints; + }, + [setProgress], + ); + // The come-back nudge moves to tomorrow on every launch and every new clear (or is used up). + const clearedCount = Object.keys(progress.stars).length; + useEffect(() => void refreshNudge(progressRef.current), [clearedCount, language]); + // Tapping the nudge opens the warm-up, when there is one today. + useEffect( + () => + onNudgeTapped(() => { + if (warmupOpen(loadComeback(), progressRef.current)) openWarmup('title'); + }), + [openWarmup], + ); const clearDaily = useCallback( (date: string, stars: number, boss = false) => { const before = dailyRef.current; @@ -286,7 +337,7 @@ export default function App() { listenForBack(() => { if (screenRef.current === 'title') return false; const s = screenRef.current; - setScreen(s === 'floor' || s === 'overflow' ? 'map' : s === 'daily' ? dailyFrom.current : s === 'custom' ? 'maker' : s === 'climb' ? 'overflow' : 'title'); + setScreen(s === 'floor' || s === 'overflow' ? 'map' : s === 'daily' ? dailyFrom.current : s === 'warmup' ? warmFrom.current : s === 'custom' ? 'maker' : s === 'climb' ? 'overflow' : 'title'); return true; }), [], @@ -371,7 +422,7 @@ export default function App() { ? themeForFloor(safeIndex + 1, tower) : screen === 'climb' || screen === 'overflow' ? themeForOverflow(overflow.run ? overflow.run.floor : 1) - : screen === 'daily' || screen === 'custom' + : screen === 'daily' || screen === 'warmup' || screen === 'custom' ? 'daily' : 'title', ); @@ -391,6 +442,7 @@ export default function App() { onSettings={() => setSettings(true)} daily={daily} onDaily={(boss) => openDaily('title', dateKey(), boss)} + warmup={warmupOpen(comeback, progress) ? { best: comeback.warm[dateKey()] ?? 0, onOpen: () => openWarmup('title') } : undefined} onLocker={openLocker} lockerNew={rewards.hasNew} onMaker={MAKER ? () => setScreen('maker') : undefined} @@ -456,6 +508,7 @@ export default function App() { onHome={() => setScreen('title')} daily={daily} onDaily={(boss) => openDaily('map', dateKey(), boss)} + warmup={warmupOpen(comeback, progress) ? { best: comeback.warm[dateKey()] ?? 0, onOpen: () => openWarmup('map') } : undefined} onArchive={() => setArchive(true)} onLocker={openLocker} lockerNew={rewards.hasNew} @@ -507,6 +560,31 @@ export default function App() { ); } + if (screen === 'warmup' && warmFloor) { + const { date, level: warm } = warmFloor; + return ( + <> + setScreen(warmFrom.current)} + custom={{ + back: t('Warm-up'), + title: t('Warm-up'), + onClear: (_c, _s, stars) => + clearWarmup(date, stars) ? t('+1 hint for the tower. A new warm-up arrives tomorrow.') : t('A new warm-up arrives tomorrow.'), + }} + /> + {overlays} + {elevator} + + ); + } if (screen === 'daily' && dailyFloor) { const { date, level: today, boss } = dailyFloor; return ( diff --git a/src/ReminderRows.tsx b/src/ReminderRows.tsx index 6a464a3..4810f6e 100644 --- a/src/ReminderRows.tsx +++ b/src/ReminderRows.tsx @@ -4,6 +4,7 @@ import { useState } from 'react'; import { fx } from './audio/feedback'; import { hourLabel, loadReminder, remindersAvailable, setReminder } from './reminder'; import { t } from './i18n'; +import { cancelNudge, loadComeback } from './comeback'; const HOURS = Array.from({ length: 24 }, (_, h) => h); @@ -38,6 +39,35 @@ export function ReminderRows() { )}

{note || t("When the day's puzzle is ready, unless you've played.")}

+ ); } + +/** The one come-back reminder, while it's still waiting (src/comeback.ts). Switching it off ends it for good. */ +function NudgeRow() { + const [waiting, setWaiting] = useState(() => { + const s = loadComeback(); + return s.nudge && !s.done; + }); + if (!waiting) return null; + return ( + <> + +

{t("One reminder, only on a day you don't play. It won't repeat.")}

+ + ); +} diff --git a/src/TitleScreen.tsx b/src/TitleScreen.tsx index 000fdcc..56e9e31 100644 --- a/src/TitleScreen.tsx +++ b/src/TitleScreen.tsx @@ -29,6 +29,8 @@ interface Props { onSettings(): void; daily: DailyState; onDaily(boss?: boolean): void; + /** Today's warm-up, for players who haven't reached the daily yet. */ + warmup?: { best: number; onOpen(): void }; onLocker(): void; /** The floor maker, when it's switched on. */ onMaker?(): void; @@ -64,7 +66,7 @@ function BigBot({ poked }: { poked: boolean }) { ); } -export function TitleScreen({ levels, towerLabel, progress, booted, onBooted, onPlay, onTower, onSettings, daily, onDaily, onLocker, lockerNew, onMaker }: Props) { +export function TitleScreen({ levels, towerLabel, progress, booted, onBooted, onPlay, onTower, onSettings, daily, onDaily, warmup, onLocker, lockerNew, onMaker }: Props) { const [settled, setSettled] = useState(() => booted || reducedMotion()); const [poked, setPoked] = useState(false); const [candy, setCandy] = useColourful(); @@ -151,7 +153,7 @@ export function TitleScreen({ levels, towerLabel, progress, booted, onBooted, on {t('Tower map')} ★ {stars} · {t('{n} / {total} floors', { n: cleared, total: ids.length })} )} - {!fresh && !DEMO && } + {!fresh && !DEMO && } {!fresh && !DEMO && onMaker && ( + ); + } if (!open) { return ( )} + {nudgeNote &&

{nudgeNote}

} + {askNudge && shown >= 3 && ( +
+

{t('Nice start! Want one reminder tomorrow, in case you forget to come back?')}

+
+ + +
+
+ )} {askReminder && shown >= 3 && (

{t("Want a reminder when tomorrow's puzzle is ready?")}

diff --git a/src/i18n/fr/ui.json b/src/i18n/fr/ui.json index 93429c7..e58d79d 100644 --- a/src/i18n/fr/ui.json +++ b/src/i18n/fr/ui.json @@ -1168,6 +1168,29 @@ "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", + "Warm-up": "Échauffement", + "+1 hint for the tower. A new warm-up arrives tomorrow.": "+1 indice pour la tour. Un nouvel échauffement arrive demain.", + "A new warm-up arrives tomorrow.": "Un nouvel échauffement arrive demain.", + "Come-back reminder": "Rappel de retour", + "One reminder, only on a day you don't play. It won't repeat.": "Un seul rappel, seulement un jour où tu ne joues pas. Il ne se répète pas.", + "PATCH saved you a warm-up": "PATCH t'a gardé un échauffement", + "Floor {n} giving you trouble? A quick warm-up puzzle earns you a free hint.": "L'étage {n} te donne du fil à retordre ? Un petit casse-tête d'échauffement te rapporte un indice gratuit.", + "A two-minute puzzle is waiting, and Floor {n} is right where you left it.": "Un casse-tête de deux minutes t'attend, et l'étage {n} est là où tu l'as laissé.", + "Warm-up puzzle": "Échauffement", + "a quick puzzle that earns a hint": "un petit casse-tête qui rapporte un indice", + "Daily challenge opens after Floor {n}": "Défi du jour après l'étage {n}", + "New today": "Nouveau", + "Quick puzzle · earns a hint": "Rapide · rapporte un indice", + "Forward walks on level ground. Where the floor steps up or down, use jump.": "Avancer marche sur un sol plat. Là où le sol monte ou descend d'une marche, utilise sauter.", + "Turns spin LoopBot on the spot. Walk to the corner, turn, then keep walking.": "Les virages font pivoter LoopBot sur place. Marche jusqu'au coin, tourne, puis continue.", + "There is {n} turn.": "Il y a {n} virage.", + "There are {n} turns.": "Il y a {n} virages.", + "Watch for {n} jump.": "Attention à {n} saut.", + "Watch for {n} jumps.": "Attention à {n} sauts.", + "Quick warm-up before the climb. Clear it and I'll send you a hint for the tower.": "Petit échauffement avant la montée. Réussis-le et je t'envoie un indice pour la tour.", + "Deal. If you don't drop by tomorrow, I'll send one reminder. Just one.": "Marché conclu. Si tu ne passes pas demain, je t'envoie un rappel. Un seul.", + "Nice start! Want one reminder tomorrow, in case you forget to come back?": "Beau départ ! Tu veux un rappel demain, au cas où tu oublierais de revenir ?", + "Yes, just one": "Oui, un seul", "New: loops": "Nouveau : les boucles", "New: functions": "Nouveau : les fonctions", "New: if and while": "Nouveau : si et tant que", diff --git a/src/styles.css b/src/styles.css index 07b4210..8caaf71 100644 --- a/src/styles.css +++ b/src/styles.css @@ -2553,6 +2553,33 @@ button.set-row { .daily-btn.shake { animation: shake 0.42s ease; } +/* The warm-up: the daily's spot for players below Floor 11 (src/comeback.ts) */ +.daily-btn.warmup-btn { + background: linear-gradient(100deg, rgba(90, 209, 164, 0.18), rgba(35, 38, 58, 0.9) 60%); + border-color: rgba(90, 209, 164, 0.5); +} +.daily-btn.warmup-btn.done { + background: rgba(35, 38, 58, 0.85); + border-color: var(--line); +} +.warmup-icon { + flex: 0 0 26px; + height: 26px; + border-radius: var(--r-sm); + display: grid; + place-items: center; + background: rgba(90, 209, 164, 0.2); + color: var(--good); +} +.warmup-btn .daily-sub { + flex-direction: column; + align-items: flex-start; + gap: 0; +} +.warmup-btn .daily-sub > span:last-child { + font-weight: 500; + opacity: 0.8; +} .title-daily { animation: title-pop 0.4s cubic-bezier(0.3, 1.5, 0.5, 1) 1.4s both; }