Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 82 additions & 4 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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}`);
Expand Down Expand Up @@ -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 <html data-nav>; Reduce motion turns it off.
const lastScreen = useRef(screen);
Expand Down Expand Up @@ -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<ComebackState>(() => {
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;
Expand Down Expand Up @@ -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;
}),
[],
Expand Down Expand Up @@ -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',
);
Expand All @@ -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}
Expand Down Expand Up @@ -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}
Expand Down Expand Up @@ -507,6 +560,31 @@ export default function App() {
</>
);
}
if (screen === 'warmup' && warmFloor) {
const { date, level: warm } = warmFloor;
return (
<>
<FloorScreen
key={warm.id}
level={localFloor(warm)}
floorNumber={0}
floorCount={levels.length}
progress={progress}
setProgress={setProgress}
onGo={go}
onTower={() => 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 (
Expand Down
30 changes: 30 additions & 0 deletions src/ReminderRows.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -38,6 +39,35 @@ export function ReminderRows() {
</label>
)}
<p className={`set-caption${note ? ' fb-error' : ''}`}>{note || t("When the day's puzzle is ready, unless you've played.")}</p>
<NudgeRow />
</div>
);
}

/** 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 (
<>
<label className="set-row">
<span className="set-label">{t('Come-back reminder')}</span>
<input
type="checkbox"
role="switch"
className="set-switch"
checked
onChange={() => {
fx.tap();
setWaiting(false);
void cancelNudge();
}}
/>
</label>
<p className="set-caption">{t("One reminder, only on a day you don't play. It won't repeat.")}</p>
</>
);
}
6 changes: 4 additions & 2 deletions src/TitleScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -151,7 +153,7 @@ export function TitleScreen({ levels, towerLabel, progress, booted, onBooted, on
{t('Tower map')} <span className="title-stats">★ {stars} · {t('{n} / {total} floors', { n: cleared, total: ids.length })}</span>
</button>
)}
{!fresh && !DEMO && <DailyButton className="title-daily" progress={progress} daily={daily} onOpen={onDaily} />}
{!fresh && !DEMO && <DailyButton className="title-daily" progress={progress} daily={daily} onOpen={onDaily} warmup={warmup} />}
{!fresh && !DEMO && onMaker && (
<button type="button" className="pill title-maker" onClick={() => (fx.tap(), onMaker())}>
<Icon name="maker" size={18} /> {t('Floor maker')}
Expand Down
6 changes: 4 additions & 2 deletions src/TowerMap.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ interface Props {
onHome(): 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 };
/** Opens the daily archive (LoopBot Plus). */
onArchive(): void;
onLocker(): void;
Expand Down Expand Up @@ -356,7 +358,7 @@ export function MiniBot() {
);
}

export function TowerMap({ levels, tower, towers, onTowerPick, progress, current, onPick, onSettings, onHome, daily, onDaily, onArchive, onLocker, lockerNew, overflow }: Props) {
export function TowerMap({ levels, tower, towers, onTowerPick, progress, current, onPick, onSettings, onHome, daily, onDaily, warmup, onArchive, onLocker, lockerNew, overflow }: Props) {
const ids = levels.map((l) => l.id);
const totalStars = ids.reduce((n, id) => n + (progress.stars[id] ?? 0), 0);
const cleared = ids.filter((id) => (progress.stars[id] ?? 0) > 0).length;
Expand Down Expand Up @@ -458,7 +460,7 @@ export function TowerMap({ levels, tower, towers, onTowerPick, progress, current
</span>
</div>
<TowerSwitch tower={tower} towers={towers} progress={progress} onPick={onTowerPick} onLocked={lockedTower} overflow={overflow} onSkyline={skylineOnSale() ? () => setSkySheet(true) : undefined} />
{!DEMO && <DailyButton className="tower-daily" progress={progress} daily={daily} onOpen={onDaily} />}
{!DEMO && <DailyButton className="tower-daily" progress={progress} daily={daily} onOpen={onDaily} warmup={warmup} />}
{!DEMO && dailyUnlocked(progress) && (PLUS_VISIBLE || plusUnlocked()) && (
<button type="button" className="link-btn daily-archive-link" onClick={() => (fx.tap(), onArchive())}>
<Icon name="calendar" size={16} /> {t('Daily archive')}
Expand Down
81 changes: 81 additions & 0 deletions src/comeback.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import { describe, expect, it } from 'vitest';
import { noteFirstDay, nudgeHour, planNudge, recordWarmupClear, warmupOpen, warmupTierFor } from './comeback';
import type { ComebackState } from './comeback';
import type { Progress } from './progress';

const base: ComebackState = { first: null, warm: {}, asked: false, nudge: false, hour: 18, at: null, done: false };
const progress = (stars: Record<string, number>, extra: Partial<Progress> = {}): Progress => ({ stars, hints: 5, hintsAwarded: 0, revealed: {}, fails: {}, tutorial: true, ...extra });
const newbie = progress({});
const floor1 = progress({ 't1-f01': 3 });

describe('first day', () => {
it('is today for a new player, and yesterday for someone who already played', () => {
expect(noteFirstDay(base, newbie, '2026-11-24').first).toBe('2026-11-24');
expect(noteFirstDay(base, floor1, '2026-11-24').first).toBe('2026-11-23');
});
it('never moves once set', () => {
const s = { ...base, first: '2026-11-01' };
expect(noteFirstDay(s, floor1, '2026-11-24')).toBe(s);
});
});

describe('warm-up', () => {
it('opens from the second day, once Floor 1 is cleared, until the daily opens', () => {
const s = { ...base, first: '2026-11-24' };
expect(warmupOpen(s, floor1, '2026-11-24')).toBe(false); // day one
expect(warmupOpen(s, floor1, '2026-11-25')).toBe(true);
expect(warmupOpen(s, newbie, '2026-11-25')).toBe(false); // Floor 1 not cleared
expect(warmupOpen(s, progress({ 't1-f01': 3, 't1-f11': 1 }), '2026-11-25')).toBe(false); // the daily took over
});

it('pays one hint for the first clear of a day only', () => {
const one = recordWarmupClear(base, '2026-11-25', 2);
expect(one.hints).toBe(1);
const again = recordWarmupClear(one.state, '2026-11-25', 3);
expect(again.hints).toBe(0);
expect(again.state.warm['2026-11-25']).toBe(3);
expect(recordWarmupClear(again.state, '2026-11-26', 1).hints).toBe(1);
});

it('forgets old days', () => {
const s = recordWarmupClear({ ...base, warm: { '2026-10-01': 3 } }, '2026-11-25', 2).state;
expect(Object.keys(s.warm)).toEqual(['2026-11-25']);
});

it('gets harder only as the tower teaches more', () => {
expect(warmupTierFor(floor1)).toBe('turn');
expect(warmupTierFor(progress({ 't1-f01': 1, 't1-f02': 1 }))).toBe('turns');
expect(warmupTierFor(progress({ 't1-f01': 1, 't1-f02': 1, 't1-f03': 1, 't1-f04': 1 }))).toBe('jumps');
});
});

describe('the one nudge', () => {
const on = { ...base, first: '2026-11-24', asked: true, nudge: true, hour: 15 };
const now = new Date(2026, 10, 24, 15, 30);

it('waits for tomorrow at about the time they played', () => {
expect(planNudge(on, floor1, false, now)?.at).toEqual(new Date(2026, 10, 25, 15, 0));
});

it('says where they left off, and offers help if they were stuck', () => {
expect(planNudge(on, floor1, false, now)?.body).toContain('Floor 2 is right where you left it');
const stuck = progress({ 't1-f01': 3 }, { fails: { 't1-f02': 4 } });
expect(planNudge(on, stuck, false, now)?.body).toContain('Floor 2 giving you trouble');
});

it('is never planned unless they said yes, and never again once used', () => {
expect(planNudge({ ...on, nudge: false }, floor1, false, now)).toBeNull();
expect(planNudge({ ...on, done: true }, floor1, false, now)).toBeNull();
});

it('steps aside for the daily reminder and the daily challenge', () => {
expect(planNudge(on, floor1, true, now)).toBeNull();
expect(planNudge(on, progress({ 't1-f01': 3, 't1-f11': 2 }), false, now)).toBeNull();
});

it('keeps to friendly hours', () => {
expect(nudgeHour(new Date(2026, 10, 24, 7))).toBe(10);
expect(nudgeHour(new Date(2026, 10, 24, 14))).toBe(14);
expect(nudgeHour(new Date(2026, 10, 24, 23))).toBe(20);
});
});
Loading
Loading