feat(sprint1-step5): migration Tailwind v4 + Zustand — suppression WildCoinContext
- Install tailwindcss @tailwindcss/vite zustand - useGameStore.ts : Zustand store wrappant economy.ts (tick, click, buy, prestige, buyNode, loadFromServer) - GameTick.tsx : composant timer 1s - GeneratorShop.tsx : boutique générateurs Tailwind (remplace Amelioration.jsx) - EvolutionTree, PrestigePanel, MilestoneBar : rewrite Zustand + Tailwind - Hud.jsx : rewrite Zustand + Tailwind (suppression Hud.scss) - BoutiqueCard, Achievements : migrés vers Zustand - Supprimé : WildCoin/ (4 fichiers), timer/Timer.jsx, useEconomy.ts, Hud.scss - WildCoinProvider retiré de main.jsx
This commit is contained in:
@@ -1,93 +0,0 @@
|
||||
// useEconomy.ts — Hook React avec lazy calculation + localStorage
|
||||
// Pas de setInterval pour les gains passifs — tout est calculé au read
|
||||
|
||||
import { useState, useCallback, useEffect } from "react";
|
||||
import {
|
||||
GameState,
|
||||
DEFAULT_STATE,
|
||||
applyIdleGains,
|
||||
applyClick,
|
||||
buyGenerator,
|
||||
applyPrestige,
|
||||
canPrestige,
|
||||
totalProductionPerSecond,
|
||||
generatorCost,
|
||||
} from "../core/economy";
|
||||
|
||||
const SAVE_KEY = "clickerz_state";
|
||||
|
||||
function loadState(): GameState {
|
||||
try {
|
||||
const raw = localStorage.getItem(SAVE_KEY);
|
||||
if (!raw) return { ...DEFAULT_STATE, lastTick: Date.now() };
|
||||
const saved = JSON.parse(raw) as GameState;
|
||||
// Appliquer les gains idle accumulés pendant l'absence
|
||||
return applyIdleGains(saved, Date.now());
|
||||
} catch {
|
||||
return { ...DEFAULT_STATE, lastTick: Date.now() };
|
||||
}
|
||||
}
|
||||
|
||||
function saveState(state: GameState): void {
|
||||
localStorage.setItem(SAVE_KEY, JSON.stringify(state));
|
||||
}
|
||||
|
||||
export function useEconomy() {
|
||||
const [state, setState] = useState<GameState>(loadState);
|
||||
|
||||
// Auto-save + tick UI toutes les secondes (pour rafraîchir l'affichage uniquement)
|
||||
// La vraie valeur est calculée lazily dans totalProductionPerSecond
|
||||
useEffect(() => {
|
||||
const id = setInterval(() => {
|
||||
setState((prev) => {
|
||||
const updated = applyIdleGains(prev, Date.now());
|
||||
saveState(updated);
|
||||
return updated;
|
||||
});
|
||||
}, 1000);
|
||||
return () => clearInterval(id);
|
||||
}, []);
|
||||
|
||||
const click = useCallback(() => {
|
||||
setState((prev) => {
|
||||
const updated = applyClick(applyIdleGains(prev, Date.now()));
|
||||
saveState(updated);
|
||||
return updated;
|
||||
});
|
||||
}, []);
|
||||
|
||||
const buy = useCallback((genId: string) => {
|
||||
setState((prev) => {
|
||||
const withIdle = applyIdleGains(prev, Date.now());
|
||||
const updated = buyGenerator(withIdle, genId);
|
||||
if (!updated) return prev;
|
||||
saveState(updated);
|
||||
return updated;
|
||||
});
|
||||
}, []);
|
||||
|
||||
const prestige = useCallback(() => {
|
||||
setState((prev) => {
|
||||
if (!canPrestige(prev)) return prev;
|
||||
const updated = applyPrestige(prev);
|
||||
saveState(updated);
|
||||
return updated;
|
||||
});
|
||||
}, []);
|
||||
|
||||
const reset = useCallback(() => {
|
||||
const fresh = { ...DEFAULT_STATE, lastTick: Date.now() };
|
||||
saveState(fresh);
|
||||
setState(fresh);
|
||||
}, []);
|
||||
|
||||
return {
|
||||
state,
|
||||
click,
|
||||
buy,
|
||||
prestige,
|
||||
canPrestige: canPrestige(state),
|
||||
productionPerSecond: totalProductionPerSecond(state),
|
||||
generatorCost,
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user