Skip to content

Commit 918143a

Browse files
committed
Fixed saved game thing
1 parent d6ae772 commit 918143a

File tree

2 files changed

+21
-13
lines changed

2 files changed

+21
-13
lines changed

jam-25/src/providers/GameDataProvider.jsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,11 @@ const GameDataProvider = ({ children }) => {
111111
}, [gridSizeY, gridSizeX, tileLibrary, funds, target, bonusSpaces, round, inventory, jokers, maxJokers, gameStarted]);
112112

113113
const savedGame = useCallback(() => {
114-
const data = JSON.parse(localStorage.getItem('gameData')) ?? {};
115-
data.inventory = data?.inventory?.map((i) => <InventoryItem key={i.id} item={i} />) ?? [];
116-
data.jokers = data?.jokers?.map((j) => <Joker joker={j} id={j.id} />) ?? [];
114+
const data = JSON.parse(localStorage.getItem('gameData')) ?? null;
115+
if (data) {
116+
data.inventory = data?.inventory?.map((i) => <InventoryItem key={i.id} item={i} />) ?? [];
117+
data.jokers = data?.jokers?.map((j) => <Joker joker={j} id={j.id} />) ?? [];
118+
}
117119
return data;
118120
}, []);
119121

jam-25/src/routes/App.jsx

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -891,7 +891,7 @@ const App = () => {
891891
if (!gameStarted) {
892892
return (
893893
<Box sx={{ display: 'flex', flexDirection: 'column', alignItems: 'center', justifyContent: 'center', p: 2, boxSizing: 'border-box' }}>
894-
<Box className="glow" sx={{ fontSize: '56px', mt: 4, textAlign: 'center', fontFamily: '"Orbitron", serif', fontWeight: 400, color: 'white' }}>
894+
<Box className="glow" sx={{ fontSize: '56px', mt: 4, mb: 2, textAlign: 'center', fontFamily: '"Orbitron", serif', fontWeight: 400, color: 'white' }}>
895895
Glyphoria
896896
</Box>
897897
<MuiGrid container spacing={2}>
@@ -912,15 +912,21 @@ const App = () => {
912912
<MuiGrid size={{ xs: 12, md: 8 }} sx={{ borderRadius: 8, backgroundColor: 'rgba(189,189,189,0.6)', display: 'flex', flexDirection: 'column', alignItems: 'center', justifyContent: 'center', p: 2, boxSizing: 'border-box' }}>
913913
<Box sx={{ mt: 4, display: 'flex', flexDirection: 'row', justifyContent: 'center', backgroundColor: 'lightgrey', borderRadius: 4 }}>
914914
<Box sx={{ p: 2, display: 'flex', flexDirection: 'column', alignItems: 'center', justifyContent: 'center', backgroundColor: 'whitesmoke', borderRadius: 4, mr: 1 }}>
915-
<Typography variant='overline' sx={{ fontFamily: 'Orbitron' }}>Saved Game</Typography>
916-
<Typography variant='body1' sx={{ fontFamily: 'Orbitron' }}>Round: {savedGameAvailable.round}</Typography>
917-
<Box sx={{ mb: 1, display: 'flex', flexDirection: 'row', justifyContent: 'center', alignItems: 'center', p: 2, border: '1px solid ghostwhite', backgroundColor: '#564c59', borderRadius: '8px', zIndex: 5 }}>
918-
{
919-
Array(savedGameAvailable?.maxJokers).fill().map((_, i) => (
920-
<JokerSpace key={i} joker={savedGameAvailable?.jokers?.[i] ?? null} />
921-
))
922-
}
923-
</Box>
915+
{
916+
savedGameAvailable ? (
917+
<>
918+
<Typography variant='overline' sx={{ fontFamily: 'Orbitron' }}>Saved Game</Typography>
919+
<Typography variant='body1' sx={{ fontFamily: 'Orbitron' }}>Round: {savedGameAvailable.round}</Typography>
920+
<Box sx={{ mb: 1, display: 'flex', flexDirection: 'row', justifyContent: 'center', alignItems: 'center', p: 2, border: '1px solid ghostwhite', backgroundColor: '#564c59', borderRadius: '8px', zIndex: 5 }}>
921+
{
922+
Array(savedGameAvailable?.maxJokers).fill().map((_, i) => (
923+
<JokerSpace key={i} joker={savedGameAvailable?.jokers?.[i] ?? null} />
924+
))
925+
}
926+
</Box>
927+
</>
928+
) : <Typography variant='overline' sx={{ fontFamily: 'Orbitron', mt: 'auto'}}>No Saved Game Found</Typography>
929+
}
924930
<Button className="button" disabled={!savedGameAvailable} variant="contained" onClick={loadGame}>
925931
Load Saved Game
926932
</Button>

0 commit comments

Comments
 (0)