From 67931eeadb1d6df76d37b6e584e414f740a800d7 Mon Sep 17 00:00:00 2001 From: Tetardtek Date: Sat, 28 Mar 2026 20:39:21 +0100 Subject: [PATCH] fix: refactor store to singleton class pattern (s.subscribe fix) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Exported $state proxies were confused with Svelte stores by SvelteKit runtime, causing "s.subscribe is not a function" on /jeu. Fix: encapsulate all $state fields in a Game class, export singleton. Components import { game } and access game.state, game.click(), etc. Class fields are proper $state — no raw proxy exported. --- .../src/lib/components/CockpitHeader.svelte | 12 +- .../src/lib/components/CosmeticsPanel.svelte | 8 +- .../src/lib/components/EvolutionTree.svelte | 32 +- Frontend/src/lib/components/GameSync.svelte | 8 +- Frontend/src/lib/components/GameTick.svelte | 4 +- .../src/lib/components/GeneratorShop.svelte | 12 +- .../src/lib/components/MilestoneBar.svelte | 10 +- .../src/lib/components/MilestonesPanel.svelte | 16 +- .../src/lib/components/OfflineReport.svelte | 16 +- .../src/lib/components/PrestigePanel.svelte | 14 +- .../src/lib/components/PrestigeScreen.svelte | 32 +- .../src/lib/components/TadpoleSprite.svelte | 4 +- Frontend/src/lib/save-sync.svelte.ts | 22 +- Frontend/src/lib/stores/game.svelte.ts | 394 ++++++++---------- Frontend/src/routes/achievements/+page.svelte | 6 +- Frontend/src/routes/jeu/+page.svelte | 12 +- 16 files changed, 277 insertions(+), 325 deletions(-) diff --git a/Frontend/src/lib/components/CockpitHeader.svelte b/Frontend/src/lib/components/CockpitHeader.svelte index 122a214..a46b285 100644 --- a/Frontend/src/lib/components/CockpitHeader.svelte +++ b/Frontend/src/lib/components/CockpitHeader.svelte @@ -1,5 +1,5 @@ @@ -7,23 +7,23 @@
Prod/s - {formatNumber(getProductionPerSecond())} + {formatNumber(game.productionPerSecond)}
/clic - {formatNumber(getCurrentClickGain())} + {formatNumber(game.clickGain)}
Mult - x{state.prestigeMultiplier.toFixed(1)} + x{game.state.prestigeMultiplier.toFixed(1)}
ADN - {state.ancestralDna} + {game.state.ancestralDna}
Gen. - {state.prestigeCount} + {game.state.prestigeCount}
diff --git a/Frontend/src/lib/components/CosmeticsPanel.svelte b/Frontend/src/lib/components/CosmeticsPanel.svelte index 5783075..206e7b1 100644 --- a/Frontend/src/lib/components/CosmeticsPanel.svelte +++ b/Frontend/src/lib/components/CosmeticsPanel.svelte @@ -1,7 +1,7 @@ @@ -40,7 +40,7 @@ {cos.description} @@ -38,11 +38,11 @@ {/if} {#if nextMilestone} - {@const progressPct = Math.min((state.prestigeCount / nextMilestone.threshold) * 100, 100).toFixed(1)} + {@const progressPct = Math.min((game.state.prestigeCount / nextMilestone.threshold) * 100, 100).toFixed(1)}
Prochain : {nextMilestone.name} - {state.prestigeCount}/{nextMilestone.threshold} + {game.state.prestigeCount}/{nextMilestone.threshold}
diff --git a/Frontend/src/lib/components/OfflineReport.svelte b/Frontend/src/lib/components/OfflineReport.svelte index bcc1401..b513a4d 100644 --- a/Frontend/src/lib/components/OfflineReport.svelte +++ b/Frontend/src/lib/components/OfflineReport.svelte @@ -1,7 +1,7 @@ - { if (e.key === 'Escape' && refs.offlineReport) dismissOfflineReport(); }} /> + { if (e.key === 'Escape' && game.offlineReport) game.dismissOfflineReport(); }} /> -{#if refs.offlineReport} +{#if game.offlineReport}
dismissOfflineReport()} + onclick={() => game.dismissOfflineReport()} >

Retour au Marais

- Absent pendant {formatDuration(refs.offlineReport.duration)} + Absent pendant {formatDuration(game.offlineReport.duration)}

@@ -41,17 +41,17 @@ class="gp-value text-3xl! mt-4 mb-2 gp-accent-green" style="text-shadow: 0 0 15px rgba(52,211,153,0.3);" > - +{formatNumber(refs.offlineReport.gains)} tetards + +{formatNumber(game.offlineReport.gains)} tetards

- Efficacite : {Math.round(refs.offlineReport.efficiency * 100)}% + Efficacite : {Math.round(game.offlineReport.efficiency * 100)}%

diff --git a/Frontend/src/lib/components/PrestigeScreen.svelte b/Frontend/src/lib/components/PrestigeScreen.svelte index 25428aa..a627ce0 100644 --- a/Frontend/src/lib/components/PrestigeScreen.svelte +++ b/Frontend/src/lib/components/PrestigeScreen.svelte @@ -1,7 +1,7 @@ - { if (e.key === 'Escape' && refs.showPrestigeScreen) closePrestige(); }} /> + { if (e.key === 'Escape' && game.showPrestigeScreen) game.game.closePrestige(); }} /> -{#if refs.showPrestigeScreen} +{#if game.showPrestigeScreen}
Nouvelle Generation -

Generation #{state.prestigeCount + 1}

+

Generation #{game.state.prestigeCount + 1}

@@ -68,7 +68,7 @@ {#if dnaBonus > 0} (base {formatNumber(baseDna)} + {Math.round(dnaBonus * 100)}% arbre) {/if} - Total apres : {formatNumber(state.ancestralDna + dnaPreview)} ADN + Total apres : {formatNumber(game.state.ancestralDna + dnaPreview)} ADN
@@ -85,7 +85,7 @@
Tetards produits - {formatNumber(state.lifetimeTadpoles)} + {formatNumber(game.state.lifetimeTadpoles)} {#if isBestTadpoles && bestRun} ★{/if}
@@ -141,7 +141,7 @@
{:else} {/if}
diff --git a/Frontend/src/lib/components/TadpoleSprite.svelte b/Frontend/src/lib/components/TadpoleSprite.svelte index af0c02f..04951e4 100644 --- a/Frontend/src/lib/components/TadpoleSprite.svelte +++ b/Frontend/src/lib/components/TadpoleSprite.svelte @@ -1,5 +1,5 @@