Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Masterplan -> TS/React #65

Merged
merged 29 commits into from
Oct 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
92 changes: 0 additions & 92 deletions games/masterplan/src/css/designer.css

This file was deleted.

41 changes: 0 additions & 41 deletions games/masterplan/src/css/main.css

This file was deleted.

3 changes: 2 additions & 1 deletion games/masterplan/src/global-styles.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { createGlobalStyle } from 'styled-components';
import '@fontsource/press-start-2p';
import './css/main.css';

export const GlobalStyles = createGlobalStyle`
:root {
Expand All @@ -25,5 +24,7 @@ body {
align-items: center;
height: 100vh;
background-color: #242424;
overscroll-behavior: none;
background: radial-gradient(ellipse at center, #30c530 0%, #30c530 64%, #138c13 100%);
}
`;
49 changes: 40 additions & 9 deletions games/masterplan/src/index.tsx
Original file line number Diff line number Diff line change
@@ -1,27 +1,58 @@
import React, { useState } from 'react';
import ReactDOM from 'react-dom/client';
import { GlobalStyles } from './global-styles';
import { OldApp } from './old-app';
import { IntroScreen } from './components/IntroScreen';
import { IntroScreen } from './screens/intro/intro-screen';
import { DesignerScreen, Unit } from './screens/designer/designer-screen';
import { BattleScreen } from './screens/battle/battle-screen';

type CurrentScreen =
| {
name: 'intro';
}
| { name: 'designer'; playerUnits?: Unit[] }
| {
name: 'battle';
playerUnits: Unit[];
oppositionUnits: Unit[];
};

const App: React.FC = () => {
const [showIntro, setShowIntro] = useState(true);
const [currentScreen, setCurrentScreen] = useState<CurrentScreen>({ name: 'intro' });

const handlePlayClick = () => {
setShowIntro(false);
setCurrentScreen({ name: 'designer' });
};

const handleStartBattle = (playerUnits: Unit[], oppositionUnits: Unit[]) => {
setCurrentScreen({ name: 'battle', playerUnits, oppositionUnits });
// Here you would typically initialize the battle with the designed units
console.log('Battle started!');
};

const handleBattleEnd = () => {
setCurrentScreen({
name: 'designer',
playerUnits: currentScreen.name === 'battle' ? currentScreen.playerUnits : undefined,
});
};

return (
<React.StrictMode>
<GlobalStyles />
{showIntro ? (
<IntroScreen onPlayClick={handlePlayClick} />
) : (
<OldApp />
{currentScreen?.name === 'intro' && <IntroScreen onPlayClick={handlePlayClick} />}
{currentScreen?.name === 'designer' && (
<DesignerScreen onStartBattle={handleStartBattle} initialPlayerUnits={currentScreen.playerUnits} />
)}
{currentScreen?.name === 'battle' && (
<BattleScreen
onBattleEnd={handleBattleEnd}
playerUnits={currentScreen.playerUnits}
oppositionUnits={currentScreen.oppositionUnits}
/>
)}
</React.StrictMode>
);
};

const root = ReactDOM.createRoot(document.getElementById('root') as HTMLElement);
root.render(<App />);
root.render(<App />);
58 changes: 0 additions & 58 deletions games/masterplan/src/js/battle-string.js

This file was deleted.

Loading
Loading