fix: preserve achievements across prestige

Fixes #38. buildPostPrestigeState was using structuredClone(defaultAchievements)
via the freshState, which reset all achievements on every prestige. Achievements
are now carried forward from currentState.achievements instead, ensuring unlocked
achievements are never lost across prestige resets.
This commit is contained in:
2026-03-09 21:31:06 -07:00
committed by Naomi Carrigan
parent 062e5b59a6
commit f2d82d58fc
2 changed files with 17 additions and 1 deletions
+3 -1
View File
@@ -225,7 +225,9 @@ const buildPostPrestigeState = (
const prestigeState: GameState = {
...freshState,
lastTickAt: Date.now(),
// Achievements are permanent — earned achievements survive all prestiges
achievements: currentState.achievements,
lastTickAt: Date.now(),
/*
* Fold current-run totals into lifetime stats so the GameState reflects
+14
View File
@@ -320,6 +320,20 @@ describe("buildPostPrestigeState", () => {
expect(prestigeState.player.lifetimeAdventurersRecruited).toBe(5);
});
it("preserves achievements from current state across prestige", () => {
const achievement = {
description: "Did a thing",
id: "ach_persisted",
name: "Achiever",
requirement: 1,
type: "totalClicks" as const,
unlockedAt: Date.now(),
};
const state = makeMinimalState({ achievements: [ achievement ] as GameState["achievements"] });
const { prestigeState } = buildPostPrestigeState(state, "Tester");
expect(prestigeState.achievements).toEqual([ achievement ]);
});
it("accumulates unlocked achievements into lifetime total", () => {
const achievement = {
description: "Did a thing",