generated from nhcarrigan/template
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:
@@ -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
|
||||
|
||||
@@ -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",
|
||||
|
||||
Reference in New Issue
Block a user