diff --git a/Frontend/src/lib/components/EvolutionTree.svelte b/Frontend/src/lib/components/EvolutionTree.svelte index c1d7b2f..9007c9b 100644 --- a/Frontend/src/lib/components/EvolutionTree.svelte +++ b/Frontend/src/lib/components/EvolutionTree.svelte @@ -44,13 +44,7 @@ let activeBranch = $state('ponte'); let branchConfig = $derived(BRANCH_CONFIG[activeBranch]); - let branchNodes = $derived(game.state.evolutionTree.filter((n: any) => n.branch === activeBranch)); - - // Debug — remove after fix confirmed - $effect(() => { - const tree = game.state.evolutionTree; - console.log('[EvolutionTree] tree length:', tree.length, 'activeBranch:', activeBranch, 'filtered:', tree.filter((n: any) => n.branch === activeBranch).length, 'first node:', tree[0] ? { id: tree[0].id, branch: tree[0].branch } : 'empty'); - }); + let branchNodes = $derived(game.state.evolutionTree.filter((n) => n.branch === activeBranch)); let spentDna = $derived(getSpentDna(game.state.evolutionTree)); let hasUnlocked = $derived(spentDna > 0); let resetCost = $derived(getTreeResetCost(game.state)); diff --git a/Frontend/src/lib/core/migrateSave.ts b/Frontend/src/lib/core/migrateSave.ts index 0bde37d..5fbfad5 100644 --- a/Frontend/src/lib/core/migrateSave.ts +++ b/Frontend/src/lib/core/migrateSave.ts @@ -23,6 +23,15 @@ export function migrateSave(raw: Record): GameState { // Futures migrations : // if (version < 3) state = migrateV2toV3(state); + // Always rebuild tree & generators from defaults — the server/localStorage + // may not store all fields (branch, cost, effect, baseProduction, etc.) + state.evolutionTree = mergeEvolutionTree( + state.evolutionTree as Array> | undefined + ); + state.generators = mergeGenerators( + state.generators as Array> | undefined + ); + return state as unknown as GameState; }