mirror of
https://github.com/Vikeo/LifeTrinket.git
synced 2025-11-14 15:07:59 +00:00
fix default values when going back to start (#11)
* add border radius * fix settings styling a little * move hook * get default values from localstorage
This commit is contained in:
26
src/App.tsx
26
src/App.tsx
@@ -7,7 +7,7 @@ import { Player } from './Types/Player';
|
|||||||
|
|
||||||
import { ThemeProvider } from '@mui/material';
|
import { ThemeProvider } from '@mui/material';
|
||||||
import { theme } from './Data/theme';
|
import { theme } from './Data/theme';
|
||||||
import { useAnalytics } from './Data/useAnalytics';
|
import { useAnalytics } from './Hooks/useAnalytics';
|
||||||
|
|
||||||
const GlobalStyles = createGlobalStyle`
|
const GlobalStyles = createGlobalStyle`
|
||||||
html,
|
html,
|
||||||
@@ -19,12 +19,12 @@ const GlobalStyles = createGlobalStyle`
|
|||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
|
|
||||||
const RootWrapper2 = styled.div`
|
const StartWrapper = styled.div`
|
||||||
max-width: fit-content;
|
max-width: fit-content;
|
||||||
max-height: fit-content;
|
max-height: fit-content;
|
||||||
`;
|
`;
|
||||||
|
|
||||||
const RootWrapper = styled.div`
|
const PlayWrapper = styled.div`
|
||||||
max-width: fit-content;
|
max-width: fit-content;
|
||||||
max-height: fit-content;
|
max-height: fit-content;
|
||||||
@media (orientation: portrait) {
|
@media (orientation: portrait) {
|
||||||
@@ -32,6 +32,12 @@ const RootWrapper = styled.div`
|
|||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
const removeLocalStorage = async () => {
|
||||||
|
localStorage.removeItem('initialGameSettings');
|
||||||
|
localStorage.removeItem('players');
|
||||||
|
localStorage.removeItem('playing');
|
||||||
|
};
|
||||||
|
|
||||||
const App = () => {
|
const App = () => {
|
||||||
const analytics = useAnalytics();
|
const analytics = useAnalytics();
|
||||||
const savedPlayers = localStorage.getItem('players');
|
const savedPlayers = localStorage.getItem('players');
|
||||||
@@ -61,18 +67,16 @@ const App = () => {
|
|||||||
setPlayers(updatedPlayers);
|
setPlayers(updatedPlayers);
|
||||||
};
|
};
|
||||||
|
|
||||||
const resetCurrentGame = () => {
|
const resetCurrentGame = async () => {
|
||||||
const currentPlayers = localStorage.getItem('players');
|
const currentPlayers = localStorage.getItem('players');
|
||||||
if (currentPlayers) {
|
if (currentPlayers) {
|
||||||
analytics.trackEvent('go_to_start', {
|
analytics.trackEvent('go_to_start', {
|
||||||
playersBeforeReset: currentPlayers,
|
playersBeforeReset: currentPlayers,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
await removeLocalStorage();
|
||||||
|
|
||||||
setPlayers([]);
|
setPlayers([]);
|
||||||
localStorage.removeItem('players');
|
|
||||||
localStorage.removeItem('playing');
|
|
||||||
localStorage.removeItem('initialGameSettings');
|
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -80,22 +84,22 @@ const App = () => {
|
|||||||
<GlobalStyles />
|
<GlobalStyles />
|
||||||
|
|
||||||
{players.length > 0 && initialGameSettings ? (
|
{players.length > 0 && initialGameSettings ? (
|
||||||
<RootWrapper>
|
<PlayWrapper>
|
||||||
<Play
|
<Play
|
||||||
players={players}
|
players={players}
|
||||||
onPlayerChange={handlePlayerChange}
|
onPlayerChange={handlePlayerChange}
|
||||||
gridAreas={initialGameSettings?.gridAreas}
|
gridAreas={initialGameSettings?.gridAreas}
|
||||||
resetCurrentGame={resetCurrentGame}
|
resetCurrentGame={resetCurrentGame}
|
||||||
/>
|
/>
|
||||||
</RootWrapper>
|
</PlayWrapper>
|
||||||
) : (
|
) : (
|
||||||
<RootWrapper2>
|
<StartWrapper>
|
||||||
<StartMenu
|
<StartMenu
|
||||||
initialGameSettings={initialGameSettings}
|
initialGameSettings={initialGameSettings}
|
||||||
setInitialGameSettings={setInitialGameSettings}
|
setInitialGameSettings={setInitialGameSettings}
|
||||||
setPlayers={setPlayers}
|
setPlayers={setPlayers}
|
||||||
/>
|
/>
|
||||||
</RootWrapper2>
|
</StartWrapper>
|
||||||
)}
|
)}
|
||||||
</ThemeProvider>
|
</ThemeProvider>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import { theme } from '../../Data/theme';
|
|||||||
import { BuyMeCoffee, KoFi } from '../../Icons/generated/Support';
|
import { BuyMeCoffee, KoFi } from '../../Icons/generated/Support';
|
||||||
import { Paragraph } from './TextComponents';
|
import { Paragraph } from './TextComponents';
|
||||||
import LittleGuy from '../../Icons/generated/LittleGuy';
|
import LittleGuy from '../../Icons/generated/LittleGuy';
|
||||||
import { useAnalytics } from '../../Data/useAnalytics';
|
import { useAnalytics } from '../../Hooks/useAnalytics';
|
||||||
|
|
||||||
// import { ButtonBase } from '@mui/material';
|
// import { ButtonBase } from '@mui/material';
|
||||||
|
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ import { Player } from '../../../Types/Player';
|
|||||||
import { SupportMe } from '../../Misc/SupportMe';
|
import { SupportMe } from '../../Misc/SupportMe';
|
||||||
import { H2, Paragraph } from '../../Misc/TextComponents';
|
import { H2, Paragraph } from '../../Misc/TextComponents';
|
||||||
import LayoutOptions from './LayoutOptions';
|
import LayoutOptions from './LayoutOptions';
|
||||||
import { useAnalytics } from '../../../Data/useAnalytics';
|
import { useAnalytics } from '../../../Hooks/useAnalytics';
|
||||||
|
|
||||||
const MainWrapper = styled.div`
|
const MainWrapper = styled.div`
|
||||||
width: 100vw;
|
width: 100vw;
|
||||||
@@ -101,6 +101,7 @@ const Start = ({
|
|||||||
gridAreas: GridTemplateAreas.FourPlayers,
|
gridAreas: GridTemplateAreas.FourPlayers,
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
const doStartGame = () => {
|
const doStartGame = () => {
|
||||||
if (!initialGameSettings) {
|
if (!initialGameSettings) {
|
||||||
return;
|
return;
|
||||||
@@ -166,7 +167,7 @@ const Start = ({
|
|||||||
max={6}
|
max={6}
|
||||||
min={1}
|
min={1}
|
||||||
aria-label="Custom marks"
|
aria-label="Custom marks"
|
||||||
defaultValue={4}
|
defaultValue={initialGameSettings?.numberOfPlayers ?? 4}
|
||||||
getAriaValueText={valuetext}
|
getAriaValueText={valuetext}
|
||||||
step={null}
|
step={null}
|
||||||
marks={playerMarks}
|
marks={playerMarks}
|
||||||
@@ -183,7 +184,7 @@ const Start = ({
|
|||||||
max={60}
|
max={60}
|
||||||
min={20}
|
min={20}
|
||||||
aria-label="Custom marks"
|
aria-label="Custom marks"
|
||||||
defaultValue={40}
|
defaultValue={initialGameSettings?.startingLifeTotal ?? 40}
|
||||||
getAriaValueText={valuetext}
|
getAriaValueText={valuetext}
|
||||||
step={10}
|
step={10}
|
||||||
marks={healthMarks}
|
marks={healthMarks}
|
||||||
@@ -197,7 +198,7 @@ const Start = ({
|
|||||||
<FormLabel>Commander</FormLabel>
|
<FormLabel>Commander</FormLabel>
|
||||||
<Switch
|
<Switch
|
||||||
checked={playerOptions.useCommanderDamage}
|
checked={playerOptions.useCommanderDamage}
|
||||||
defaultChecked
|
defaultChecked={initialGameSettings?.useCommanderDamage ?? true}
|
||||||
onChange={(_e, value) =>
|
onChange={(_e, value) =>
|
||||||
setPlayerOptions({
|
setPlayerOptions({
|
||||||
...playerOptions,
|
...playerOptions,
|
||||||
|
|||||||
Reference in New Issue
Block a user