главный экран
This commit is contained in:
+22
-1
@@ -1,16 +1,37 @@
|
||||
import { useState } from 'react';
|
||||
import GameMap from './components/GameMap';
|
||||
import MainMenu from './components/MainMenu';
|
||||
import Sidebar from './components/Sidebar';
|
||||
import Topbar from './components/Topbar';
|
||||
import { GameStore } from './game/GameStore';
|
||||
import { clearSave } from './game/persistence';
|
||||
import './App.css';
|
||||
|
||||
type Screen = 'menu' | 'game';
|
||||
|
||||
function App() {
|
||||
const [store] = useState(() => new GameStore());
|
||||
// Always starts on the menu, regardless of whether a save exists — loading straight into a
|
||||
// resumed game on every page (re)load isn't what was asked for.
|
||||
const [screen, setScreen] = useState<Screen>('menu');
|
||||
|
||||
function handleNewGame() {
|
||||
clearSave();
|
||||
setScreen('game');
|
||||
}
|
||||
|
||||
function handleExitToMenu() {
|
||||
store.save();
|
||||
setScreen('menu');
|
||||
}
|
||||
|
||||
if (screen === 'menu') {
|
||||
return <MainMenu onNewGame={handleNewGame} onContinue={() => setScreen('game')} />;
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="app">
|
||||
<Topbar store={store} />
|
||||
<Topbar store={store} onExitToMenu={handleExitToMenu} />
|
||||
<div className="main-row">
|
||||
<Sidebar store={store} />
|
||||
<GameMap store={store} />
|
||||
|
||||
Reference in New Issue
Block a user