forked from external-repos/LifeTrinket
Compare commits
21 Commits
0.6.6
...
finger-thi
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
eb99cff736 | ||
|
|
318520ea53 | ||
|
|
fa5829b402 | ||
|
|
71f26d0dc5 | ||
|
|
3a568fc3ab | ||
|
|
355f4bd4cd | ||
|
|
17e174bfe1 | ||
|
|
e1e8da858b | ||
|
|
e02f071415 | ||
|
|
e04f31bb67 | ||
|
|
e5386d08a4 | ||
|
|
d6cd678e9f | ||
|
|
334b46db6e | ||
|
|
e03ecc6f51 | ||
|
|
d4dc44076d | ||
|
|
a1b5cfd871 | ||
|
|
f11eea5e53 | ||
|
|
905912a7fd | ||
|
|
a90dd7c9ea | ||
|
|
ef1310d674 | ||
|
|
fe3bb6c78c |
@@ -1,8 +1,12 @@
|
||||
index.html,1705225256081,6ef0d7e2de82bf64addbb9294fb28845fd06daaa544b010a47422c12ae3ad97f
|
||||
robots.txt,1705225255906,391d14b3c2f8c9143a27a28c7399585142228d4d1bdbe2c87ac946de411fa9a2
|
||||
manifest.json,1705225255906,91ce94afb71f33a477f5d8d48c3f98bd7de422279c74f17b6500eec72003ac1a
|
||||
assets/index-08359bdb.css,1705225256081,d2766260d28230d960d75362810713efaddf40687205e697432b52869f162af7
|
||||
logo192.png,1705225255905,3b0fcf91fe2128f493de0bce2f6e2d35520a4260a04e05b8d855181359b3d3fe
|
||||
favicon.ico,1705225255905,75661e6187b524767554b4f28ec09a64bc72b0bb102a0b453aaead88519d9ed3
|
||||
logo512.png,1705225255906,cf49739c9e6890bbfcd4157f299dde425df60759b7320ae9188d7ab9dc51e8ca
|
||||
assets/index-20658f4b.js,1705225256081,742f2c10740beea3a23f269aa6266b3c288d1fd9c7e20b6829034e8a898bf1e1
|
||||
index.html,1711189442688,fa2549e32940c356ac5cee88c8db61076ad62fb4e599858c8e45cfc68cd901c4
|
||||
manifest.json,1711189442512,7ff5111aa04a42adff3b38924ec467b6f345ed0309dba1486dc9b783b60c2a9d
|
||||
registerSW.js,1711189442688,5b6445b5215737c53ef0d379c151d57de165a056de2d1c5812ed614f158ebcbd
|
||||
sw.js,1711189443521,9c09d33ea573bb818864bfad526fa911839637171773eca8e31905458679846d
|
||||
robots.txt,1711189442512,391d14b3c2f8c9143a27a28c7399585142228d4d1bdbe2c87ac946de411fa9a2
|
||||
manifest.webmanifest,1711189442688,f2bf253209f6e292a6b0dbfa06fb4ac188eb5f2dba568c3ad5511b9ed52c1f51
|
||||
workbox-3e911b1d.js,1711189443521,d5dbc868a5c07af633d29de7ba3ffe37542aaaabdf33713b4298df31f92f11ff
|
||||
assets/index-WLCHZTqE.css,1711189442688,877e5ea9bfd3a1ca0e6449e8213da8a3c7717e530370f12669bb5c70dd21e700
|
||||
favicon.ico,1711189442511,8cefe5adbf00d337d8633fb744b9f2c4914f769b319be4bb7e184b7a4aa17160
|
||||
logo192.png,1711189442511,3d1e2e6f064d4fd325828f21bb6493ff0dbf2390b0e7d2aba9f2b6def4829799
|
||||
logo512.png,1711189442511,892a4da1cc5434929a83a71fcbcb0d0d80aa82f44e3c21e9b20ffe9267197133
|
||||
assets/index-OHs0lOr7.js,1711189442688,aa0dca732cd5b6f621ecb7c6dbcbfdbccde78941cfad954f6626d4ff83040c7f
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "life-trinket",
|
||||
"private": true,
|
||||
"version": "0.6.6",
|
||||
"version": "0.8.1",
|
||||
"type": "commonjs",
|
||||
"engines": {
|
||||
"node": ">=18",
|
||||
|
||||
@@ -21,9 +21,9 @@ const Container = twc.div<RotationDivProps>((props) => [
|
||||
]);
|
||||
|
||||
export const ExtraCountersGrid = twc.div<RotationDivProps>((props) => [
|
||||
'flex absolute flex-row flex-grow pointer-events-none',
|
||||
'flex absolute flex-row flex-grow pointer-events-none overflow-x-scroll overflow-y-hidden',
|
||||
props.$rotation === Rotation.SideFlipped || props.$rotation === Rotation.Side
|
||||
? 'flex-col-reverse h-full w-auto bottom-auto'
|
||||
? 'flex-col-reverse h-full w-auto bottom-auto right-0'
|
||||
: 'w-full bottom-0',
|
||||
]);
|
||||
|
||||
|
||||
@@ -53,23 +53,9 @@ const Health = ({
|
||||
differenceKey,
|
||||
recentDifference,
|
||||
}: HealthProps) => {
|
||||
const [showStartingPlayer, setShowStartingPlayer] = useState(
|
||||
localStorage.getItem('playing') === 'true'
|
||||
);
|
||||
const [fontSize, setFontSize] = useState(16);
|
||||
const textContainerRef = useRef<HTMLDivElement | null>(null);
|
||||
|
||||
useEffect(() => {
|
||||
if (!showStartingPlayer) {
|
||||
const playingTimer = setTimeout(() => {
|
||||
localStorage.setItem('playing', 'true');
|
||||
setShowStartingPlayer(localStorage.getItem('playing') === 'true');
|
||||
}, 3_000);
|
||||
|
||||
return () => clearTimeout(playingTimer);
|
||||
}
|
||||
}, [showStartingPlayer]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!textContainerRef.current) {
|
||||
return;
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
import { useEffect, useState } from 'react';
|
||||
import { useEffect, useRef, useState } from 'react';
|
||||
import { useSwipeable } from 'react-swipeable';
|
||||
import { twc } from 'react-twc';
|
||||
import { useAnalytics } from '../../Hooks/useAnalytics';
|
||||
import { useGlobalSettings } from '../../Hooks/useGlobalSettings';
|
||||
import { usePlayers } from '../../Hooks/usePlayers';
|
||||
import { Cog } from '../../Icons/generated';
|
||||
import { Player, Rotation } from '../../Types/Player';
|
||||
import { checkContrast } from '../../Utils/checkContrast';
|
||||
import {
|
||||
RotationButtonProps,
|
||||
RotationDivProps,
|
||||
@@ -11,9 +14,9 @@ import {
|
||||
import { LoseGameButton } from '../Buttons/LoseButton';
|
||||
import CommanderDamageBar from '../Counters/CommanderDamageBar';
|
||||
import ExtraCountersBar from '../Counters/ExtraCountersBar';
|
||||
import PlayerMenu from '../Player/PlayerMenu';
|
||||
import PlayerMenu from '../Players/PlayerMenu';
|
||||
import { StartingPlayerCard } from '../PreStartGame/StartingPlayerCard';
|
||||
import Health from './Health';
|
||||
import { Cog } from '../../Icons/generated';
|
||||
|
||||
const SettingsButtonTwc = twc.button<RotationButtonProps>((props) => [
|
||||
'absolute flex-grow border-none outline-none cursor-pointer bg-transparent z-[1] select-none webkit-user-select-none',
|
||||
@@ -25,16 +28,33 @@ const SettingsButtonTwc = twc.button<RotationButtonProps>((props) => [
|
||||
type SettingsButtonProps = {
|
||||
onClick: () => void;
|
||||
rotation: Rotation;
|
||||
color: string;
|
||||
};
|
||||
|
||||
const SettingsButton = ({ onClick, rotation }: SettingsButtonProps) => {
|
||||
const SettingsButton = ({ onClick, rotation, color }: SettingsButtonProps) => {
|
||||
const [iconColor, setIconColor] = useState<'dark' | 'light'>('dark');
|
||||
|
||||
useEffect(() => {
|
||||
const contrast = checkContrast(color, '#00000080');
|
||||
|
||||
if (contrast === 'Fail') {
|
||||
setIconColor('light');
|
||||
} else {
|
||||
setIconColor('dark');
|
||||
}
|
||||
}, [color]);
|
||||
|
||||
return (
|
||||
<SettingsButtonTwc
|
||||
onClick={onClick}
|
||||
$rotation={rotation}
|
||||
aria-label={`Settings`}
|
||||
>
|
||||
<Cog size="5vmin" color="black" opacity="0.3" />
|
||||
<Cog
|
||||
size="5vmin"
|
||||
data-contrast={iconColor}
|
||||
className="data-[contrast=dark]:text-icons-dark data-[contrast=light]:text-icons-light"
|
||||
/>
|
||||
</SettingsButtonTwc>
|
||||
);
|
||||
};
|
||||
@@ -49,8 +69,6 @@ const LifeCounterWrapper = twc.div<RotationDivProps>((props) => [
|
||||
: `flex-col`,
|
||||
]);
|
||||
|
||||
const StartingPlayerNoticeWrapper = twc.div`z-10 flex absolute w-full h-full justify-center items-center pointer-events-none select-none webkit-user-select-none bg-primary-main`;
|
||||
|
||||
const PlayerLostWrapper = twc.div<RotationDivProps>((props) => [
|
||||
'z-[1] flex absolute w-full h-full justify-center items-center pointer-events-none select-none webkit-user-select-none bg-lifeCounter-lostWrapper opacity-75',
|
||||
props.$rotation === Rotation.SideFlipped || props.$rotation === Rotation.Side
|
||||
@@ -58,8 +76,6 @@ const PlayerLostWrapper = twc.div<RotationDivProps>((props) => [
|
||||
: '',
|
||||
]);
|
||||
|
||||
const DynamicText = twc.div`text-[8vmin] whitespace-nowrap`;
|
||||
|
||||
const hasCommanderDamageReached21 = (player: Player) => {
|
||||
const commanderDamageTotals = player.commanderDamage.map(
|
||||
(commanderDamage) => commanderDamage.damageTotal
|
||||
@@ -90,13 +106,17 @@ const playerCanLose = (player: Player) => {
|
||||
type LifeCounterProps = {
|
||||
player: Player;
|
||||
opponents: Player[];
|
||||
isStartingPlayer?: boolean;
|
||||
};
|
||||
|
||||
const RECENT_DIFFERENCE_TTL = 3_000;
|
||||
|
||||
const LifeCounter = ({ player, opponents }: LifeCounterProps) => {
|
||||
const { updatePlayer, updateLifeTotal } = usePlayers();
|
||||
const { settings } = useGlobalSettings();
|
||||
const { settings, playing } = useGlobalSettings();
|
||||
const recentDifferenceTimerRef = useRef<NodeJS.Timeout | undefined>(
|
||||
undefined
|
||||
);
|
||||
|
||||
const [showPlayerMenu, setShowPlayerMenu] = useState(false);
|
||||
const [recentDifference, setRecentDifference] = useState(0);
|
||||
@@ -113,12 +133,10 @@ const LifeCounter = ({ player, opponents }: LifeCounterProps) => {
|
||||
trackMouse: true,
|
||||
onSwipedDown: (e) => {
|
||||
e.event.stopPropagation();
|
||||
console.log(`User DOWN Swiped on player ${player.index}`);
|
||||
setShowPlayerMenu(true);
|
||||
},
|
||||
onSwipedUp: (e) => {
|
||||
e.event.stopPropagation();
|
||||
console.log(`User UP Swiped on player ${player.index}`);
|
||||
setShowPlayerMenu(false);
|
||||
},
|
||||
|
||||
@@ -126,41 +144,41 @@ const LifeCounter = ({ player, opponents }: LifeCounterProps) => {
|
||||
onSwiping: (e) => e.event.stopPropagation(),
|
||||
rotationAngle,
|
||||
});
|
||||
const analytics = useAnalytics();
|
||||
|
||||
useEffect(() => {
|
||||
const timer = setTimeout(() => {
|
||||
if (recentDifference === 0) {
|
||||
clearTimeout(recentDifferenceTimerRef.current);
|
||||
return;
|
||||
}
|
||||
|
||||
recentDifferenceTimerRef.current = setTimeout(() => {
|
||||
analytics.trackEvent('life_changed', {
|
||||
lifeChangedAmount: recentDifference,
|
||||
});
|
||||
setRecentDifference(0);
|
||||
}, RECENT_DIFFERENCE_TTL);
|
||||
|
||||
return () => {
|
||||
clearTimeout(recentDifferenceTimerRef.current);
|
||||
};
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [recentDifference]);
|
||||
|
||||
useEffect(() => {
|
||||
const resizeObserver = new ResizeObserver(() => {
|
||||
if (document.body.clientWidth > document.body.clientHeight)
|
||||
setIsLandscape(true);
|
||||
else setIsLandscape(false);
|
||||
return;
|
||||
return () => {
|
||||
// Cleanup: disconnect the ResizeObserver when the component unmounts.
|
||||
resizeObserver.disconnect();
|
||||
};
|
||||
});
|
||||
|
||||
resizeObserver.observe(document.body);
|
||||
|
||||
return () => {
|
||||
clearTimeout(timer);
|
||||
// Cleanup: disconnect the ResizeObserver when the component unmounts.
|
||||
resizeObserver.disconnect();
|
||||
};
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [recentDifference, document.body.clientHeight, document.body.clientWidth]);
|
||||
|
||||
useEffect(() => {
|
||||
if (player.showStartingPlayer) {
|
||||
const playingTimer = setTimeout(() => {
|
||||
localStorage.setItem('playing', 'true');
|
||||
player.showStartingPlayer = false;
|
||||
updatePlayer(player);
|
||||
}, 3_000);
|
||||
|
||||
return () => clearTimeout(playingTimer);
|
||||
}
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [player.showStartingPlayer]);
|
||||
}, [document.body.clientHeight, document.body.clientWidth]);
|
||||
|
||||
player.settings.rotation === Rotation.SideFlipped ||
|
||||
player.settings.rotation === Rotation.Side;
|
||||
@@ -182,11 +200,7 @@ const LifeCounter = ({ player, opponents }: LifeCounterProps) => {
|
||||
? player.settings.rotation - 90
|
||||
: player.settings.rotation;
|
||||
|
||||
const calcTextRotation =
|
||||
player.settings.rotation === Rotation.SideFlipped ||
|
||||
player.settings.rotation === Rotation.Side
|
||||
? player.settings.rotation - 180
|
||||
: player.settings.rotation;
|
||||
const amountOfPlayers = opponents.length + 1;
|
||||
|
||||
return (
|
||||
<LifeCounterContentWrapper style={{ background: player.color }}>
|
||||
@@ -195,25 +209,15 @@ const LifeCounter = ({ player, opponents }: LifeCounterProps) => {
|
||||
style={{ rotate: `${calcRotation}deg` }}
|
||||
{...handlers}
|
||||
>
|
||||
{settings.showStartingPlayer &&
|
||||
player.isStartingPlayer &&
|
||||
player.showStartingPlayer && (
|
||||
<StartingPlayerNoticeWrapper
|
||||
style={{ rotate: `${calcRotation}deg` }}
|
||||
>
|
||||
<DynamicText
|
||||
style={{
|
||||
rotate: `${calcTextRotation}deg`,
|
||||
}}
|
||||
>
|
||||
You start!
|
||||
</DynamicText>
|
||||
</StartingPlayerNoticeWrapper>
|
||||
)}
|
||||
{amountOfPlayers > 1 &&
|
||||
!playing &&
|
||||
settings.showStartingPlayer &&
|
||||
player.isStartingPlayer && <StartingPlayerCard player={player} />}
|
||||
|
||||
{player.hasLost && (
|
||||
<PlayerLostWrapper $rotation={player.settings.rotation} />
|
||||
)}
|
||||
|
||||
<CommanderDamageBar
|
||||
opponents={opponents}
|
||||
player={player}
|
||||
@@ -226,6 +230,7 @@ const LifeCounter = ({ player, opponents }: LifeCounterProps) => {
|
||||
setShowPlayerMenu(!showPlayerMenu);
|
||||
}}
|
||||
rotation={player.settings.rotation}
|
||||
color={player.color}
|
||||
/>
|
||||
)}
|
||||
{playerCanLose(player) && (
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
import { Button, FormLabel, Modal, Switch } from '@mui/material';
|
||||
import { Button, Modal, Switch } from '@mui/material';
|
||||
import { useEffect, useState } from 'react';
|
||||
import { twc } from 'react-twc';
|
||||
import { useGlobalSettings } from '../../Hooks/useGlobalSettings';
|
||||
import { Cross } from '../../Icons/generated';
|
||||
import { PreStartMode } from '../../Types/Settings';
|
||||
import { ModalWrapper } from './InfoModal';
|
||||
import { Separator } from './Separator';
|
||||
import { Paragraph } from './TextComponents';
|
||||
import { useEffect, useState } from 'react';
|
||||
import { Cross } from '../../Icons/generated';
|
||||
|
||||
const SettingContainer = twc.div`w-full flex flex-col mb-2`;
|
||||
|
||||
@@ -84,28 +85,35 @@ export const SettingsModal = ({ isOpen, closeModal }: SettingsModalProps) => {
|
||||
<ModalWrapper>
|
||||
<Container>
|
||||
<h2 className="text-center text-2xl mb-2">⚙️ Settings ⚙️</h2>
|
||||
<Separator height="1px" />
|
||||
<SettingContainer>
|
||||
<ToggleContainer>
|
||||
<FormLabel>Show Start Player</FormLabel>
|
||||
<Switch
|
||||
checked={settings.showStartingPlayer}
|
||||
onChange={() => {
|
||||
setSettings({
|
||||
...settings,
|
||||
showStartingPlayer: !settings.showStartingPlayer,
|
||||
});
|
||||
}}
|
||||
/>
|
||||
</ToggleContainer>
|
||||
<Description>
|
||||
On start or reset of game, will pick a random player who will
|
||||
start first if this is enabled.
|
||||
</Description>
|
||||
<Paragraph>
|
||||
{/* @ts-expect-error is defined in vite.config.ts*/}
|
||||
Current version: {APP_VERSION}{' '}
|
||||
{isLatestVersion && (
|
||||
<span className="text-sm text-text-secondary">(latest)</span>
|
||||
)}
|
||||
</Paragraph>
|
||||
{!isLatestVersion && newVersion && (
|
||||
<Paragraph className="text-text-secondary text-lg text-center">
|
||||
New version ({newVersion}) is available!{' '}
|
||||
</Paragraph>
|
||||
)}
|
||||
</SettingContainer>
|
||||
{!isLatestVersion && newVersion && (
|
||||
<Button
|
||||
variant="contained"
|
||||
style={{ marginTop: '0.25rem', marginBottom: '0.25rem' }}
|
||||
onClick={() => window?.location?.reload()}
|
||||
>
|
||||
<span>Update</span>
|
||||
<span className="text-xs"> (reload app)</span>
|
||||
</Button>
|
||||
)}
|
||||
<Separator height="1px" />
|
||||
|
||||
<SettingContainer>
|
||||
<ToggleContainer>
|
||||
<FormLabel>Show Player Menu Cog</FormLabel>
|
||||
<label>Show Player Menu Cog</label>
|
||||
<Switch
|
||||
checked={settings.showPlayerMenuCog}
|
||||
onChange={() => {
|
||||
@@ -123,7 +131,73 @@ export const SettingsModal = ({ isOpen, closeModal }: SettingsModalProps) => {
|
||||
</SettingContainer>
|
||||
<SettingContainer>
|
||||
<ToggleContainer>
|
||||
<FormLabel>Keep Awake</FormLabel>
|
||||
<label>Show Start Player</label>
|
||||
<Switch
|
||||
checked={settings.showStartingPlayer}
|
||||
onChange={() => {
|
||||
setSettings({
|
||||
...settings,
|
||||
showStartingPlayer: !settings.showStartingPlayer,
|
||||
});
|
||||
}}
|
||||
/>
|
||||
</ToggleContainer>
|
||||
<Description>
|
||||
On start or reset of game, will pick a random starting player,
|
||||
according to the <b>Pre-Start mode</b>
|
||||
</Description>
|
||||
</SettingContainer>
|
||||
<SettingContainer>
|
||||
<div className="flex flex-row justify-between items-center mb-1">
|
||||
<label htmlFor="pre-start-modes">Pre-Start mode</label>
|
||||
<select
|
||||
name="pre-start-modes"
|
||||
id="pre-start-modes"
|
||||
value={settings.preStartMode}
|
||||
className="bg-primary-main border-none outline-none text-text-primary rounded-md p-1 text-xs disabled:bg-primary-dark"
|
||||
onChange={(e) => {
|
||||
setSettings({
|
||||
...settings,
|
||||
preStartMode: e.target.value as PreStartMode,
|
||||
});
|
||||
}}
|
||||
disabled={!settings.showStartingPlayer}
|
||||
>
|
||||
<option value={PreStartMode.None}>None</option>
|
||||
<option value={PreStartMode.RandomKing}>Random King</option>
|
||||
<option value={PreStartMode.FingerGame}>Finger Game</option>
|
||||
</select>
|
||||
</div>
|
||||
<div className="text-xs text-left text-text-secondary">
|
||||
Different ways to determine the starting player before the game
|
||||
starts.
|
||||
</div>
|
||||
|
||||
{settings.preStartMode === PreStartMode.None && (
|
||||
<div className="text-xs text-left text-text-secondary mt-1">
|
||||
<span className="text-text-primary">None:</span> The starting
|
||||
player will simply be shown.
|
||||
</div>
|
||||
)}
|
||||
{settings.preStartMode === PreStartMode.RandomKing && (
|
||||
<div className="text-xs text-left text-text-secondary mt-1">
|
||||
<span className="text-text-primary">Random King:</span>{' '}
|
||||
Randomly pass a crown between all players, press the screen to
|
||||
stop it. The player who has the crown when it stops gets to
|
||||
start.
|
||||
</div>
|
||||
)}
|
||||
{settings.preStartMode === PreStartMode.FingerGame && (
|
||||
<div className="text-xs text-left text-text-secondary mt-1">
|
||||
<span className="text-text-primary">Finger Game:</span> All
|
||||
players put a finger on the screen, one will be chosen at
|
||||
random.
|
||||
</div>
|
||||
)}
|
||||
</SettingContainer>
|
||||
<SettingContainer>
|
||||
<ToggleContainer>
|
||||
<label>Keep Awake</label>
|
||||
<Switch
|
||||
checked={settings.keepAwake}
|
||||
onChange={() => {
|
||||
@@ -141,7 +215,10 @@ export const SettingsModal = ({ isOpen, closeModal }: SettingsModalProps) => {
|
||||
</SettingContainer>
|
||||
<SettingContainer>
|
||||
<ToggleContainer>
|
||||
<FormLabel>Go fullscreen on start (Android only)</FormLabel>
|
||||
<label>
|
||||
Fullscreen on start{' '}
|
||||
<span className="text-xs">(Android only)</span>
|
||||
</label>
|
||||
<Switch
|
||||
checked={settings.goFullscreenOnStart}
|
||||
onChange={() => {
|
||||
@@ -177,31 +254,6 @@ export const SettingsModal = ({ isOpen, closeModal }: SettingsModalProps) => {
|
||||
</>
|
||||
)}
|
||||
<Separator height="1px" />
|
||||
<SettingContainer>
|
||||
<Paragraph>
|
||||
{/* @ts-expect-error is defined in vite.config.ts*/}
|
||||
Current version: {APP_VERSION}{' '}
|
||||
{isLatestVersion && (
|
||||
<span className="text-sm text-text-secondary">(latest)</span>
|
||||
)}
|
||||
</Paragraph>
|
||||
{!isLatestVersion && newVersion && (
|
||||
<Paragraph className="text-text-secondary text-lg text-center">
|
||||
New version ({newVersion}) is available!{' '}
|
||||
</Paragraph>
|
||||
)}
|
||||
</SettingContainer>
|
||||
{!isLatestVersion && newVersion && (
|
||||
<Button
|
||||
variant="contained"
|
||||
style={{ marginTop: '0.25rem', marginBottom: '0.25rem' }}
|
||||
onClick={() => window?.location?.reload()}
|
||||
>
|
||||
<span>Update</span>
|
||||
<span className="text-xs"> (reload app)</span>
|
||||
</Button>
|
||||
)}
|
||||
<Separator height="1px" />
|
||||
|
||||
<Button
|
||||
variant="contained"
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Button, Checkbox } from '@mui/material';
|
||||
import { Checkbox } from '@mui/material';
|
||||
import { useRef } from 'react';
|
||||
import { twc } from 'react-twc';
|
||||
import { theme } from '../../Data/theme';
|
||||
@@ -19,8 +19,6 @@ import {
|
||||
import { Player, Rotation } from '../../Types/Player';
|
||||
import { RotationDivProps } from '../Buttons/CommanderDamage';
|
||||
|
||||
const CheckboxContainer = twc.div``;
|
||||
|
||||
const PlayerMenuWrapper = twc.div`
|
||||
flex
|
||||
flex-col
|
||||
@@ -51,7 +49,6 @@ const TogglesSection = twc.div`
|
||||
flex-row
|
||||
flex-wrap
|
||||
relative
|
||||
gap-2
|
||||
h-full
|
||||
justify-evenly
|
||||
items-center
|
||||
@@ -60,11 +57,11 @@ const TogglesSection = twc.div`
|
||||
const ButtonsSections = twc.div`
|
||||
flex
|
||||
max-w-full
|
||||
gap-4
|
||||
justify-between
|
||||
p-[3%]
|
||||
justify-evenly
|
||||
items-center
|
||||
flex-wrap
|
||||
mt-0
|
||||
px-2
|
||||
`;
|
||||
|
||||
const ColorPickerButton = twc.div`
|
||||
@@ -79,7 +76,7 @@ const ColorPickerButton = twc.div`
|
||||
`;
|
||||
|
||||
const SettingsContainer = twc.div<RotationDivProps>((props) => [
|
||||
'flex flex-wrap h-full w-full',
|
||||
'flex flex-wrap h-full w-full overflow-y-scroll',
|
||||
props.$rotation === Rotation.SideFlipped || props.$rotation === Rotation.Side
|
||||
? 'flex-col'
|
||||
: 'flex-row',
|
||||
@@ -98,13 +95,22 @@ const PlayerMenu = ({
|
||||
}: PlayerMenuProps) => {
|
||||
const settingsContainerRef = useRef<HTMLDivElement | null>(null);
|
||||
const resetGameDialogRef = useRef<HTMLDialogElement | null>(null);
|
||||
const endGameDialogRef = useRef<HTMLDialogElement | null>(null);
|
||||
|
||||
const { isSide } = useSafeRotate({
|
||||
rotation: player.settings.rotation,
|
||||
containerRef: settingsContainerRef,
|
||||
});
|
||||
|
||||
const { fullscreen, wakeLock, goToStart, settings } = useGlobalSettings();
|
||||
const {
|
||||
fullscreen,
|
||||
wakeLock,
|
||||
goToStart,
|
||||
settings,
|
||||
setPlaying,
|
||||
setRandomizingPlayer,
|
||||
} = useGlobalSettings();
|
||||
|
||||
const { updatePlayer, resetCurrentGame } = usePlayers();
|
||||
|
||||
const handleColorChange = (event: React.ChangeEvent<HTMLInputElement>) => {
|
||||
@@ -122,6 +128,13 @@ const PlayerMenu = ({
|
||||
const handleResetGame = () => {
|
||||
resetCurrentGame();
|
||||
setShowPlayerMenu(false);
|
||||
setPlaying(false);
|
||||
setRandomizingPlayer(true);
|
||||
};
|
||||
|
||||
const handleGoToStart = () => {
|
||||
goToStart();
|
||||
setRandomizingPlayer(true);
|
||||
};
|
||||
|
||||
const toggleFullscreen = () => {
|
||||
@@ -159,14 +172,13 @@ const PlayerMenu = ({
|
||||
}}
|
||||
ref={settingsContainerRef}
|
||||
>
|
||||
{settings.showPlayerMenuCog && (
|
||||
<button
|
||||
onClick={() => setShowPlayerMenu(false)}
|
||||
className="flex absolute top-0 right-2 z-10 w-8 h-8 bg-transparent items-center justify-center rounded-full border-solid border-primary-main border-2"
|
||||
>
|
||||
<Cross size="16px" className="text-primary-main " />
|
||||
</button>
|
||||
)}
|
||||
<button
|
||||
onClick={() => setShowPlayerMenu(false)}
|
||||
className="flex absolute top-0 right-2 z-10 bg-transparent items-center justify-center rounded-full border-solid border-primary-main border-2 p-[0.2rem]"
|
||||
>
|
||||
<Cross size={buttonFontSize} className="text-primary-main " />
|
||||
</button>
|
||||
|
||||
<BetterRowContainer>
|
||||
<TogglesSection>
|
||||
<ColorPickerButton aria-label="Color picker">
|
||||
@@ -178,7 +190,7 @@ const PlayerMenu = ({
|
||||
/>
|
||||
</ColorPickerButton>
|
||||
{player.settings.useCommanderDamage && (
|
||||
<CheckboxContainer>
|
||||
<div>
|
||||
<Checkbox
|
||||
name="usePartner"
|
||||
checked={player.settings.usePartner}
|
||||
@@ -203,9 +215,9 @@ const PlayerMenu = ({
|
||||
aria-checked={player.settings.usePartner}
|
||||
aria-label="Partner"
|
||||
/>
|
||||
</CheckboxContainer>
|
||||
</div>
|
||||
)}
|
||||
<CheckboxContainer>
|
||||
<div>
|
||||
<Checkbox
|
||||
name="usePoison"
|
||||
checked={player.settings.usePoison}
|
||||
@@ -230,8 +242,8 @@ const PlayerMenu = ({
|
||||
aria-checked={player.settings.usePoison}
|
||||
aria-label="Poison"
|
||||
/>
|
||||
</CheckboxContainer>
|
||||
<CheckboxContainer>
|
||||
</div>
|
||||
<div>
|
||||
<Checkbox
|
||||
name="useEnergy"
|
||||
checked={player.settings.useEnergy}
|
||||
@@ -256,8 +268,8 @@ const PlayerMenu = ({
|
||||
aria-checked={player.settings.useEnergy}
|
||||
aria-label="Energy"
|
||||
/>
|
||||
</CheckboxContainer>
|
||||
<CheckboxContainer>
|
||||
</div>
|
||||
<div>
|
||||
<Checkbox
|
||||
name="useExperience"
|
||||
checked={player.settings.useExperience}
|
||||
@@ -282,21 +294,22 @@ const PlayerMenu = ({
|
||||
aria-checked={player.settings.useExperience}
|
||||
aria-label="Experience"
|
||||
/>
|
||||
</CheckboxContainer>
|
||||
</div>
|
||||
</TogglesSection>
|
||||
<ButtonsSections className="mt-4">
|
||||
<Button
|
||||
variant="text"
|
||||
style={{
|
||||
cursor: 'pointer',
|
||||
userSelect: 'none',
|
||||
}}
|
||||
onClick={goToStart}
|
||||
<ButtonsSections>
|
||||
<button
|
||||
className="text-primary-main cursor-pointer webkit-user-select-none"
|
||||
onClick={() => endGameDialogRef.current?.show()}
|
||||
aria-label="Back to start"
|
||||
>
|
||||
<Exit size={iconSize} style={{ rotate: '180deg' }} />
|
||||
</Button>
|
||||
<CheckboxContainer>
|
||||
</button>
|
||||
<div
|
||||
data-fullscreen={document.fullscreenElement ? true : false}
|
||||
className="flex
|
||||
data-[fullscreen=true]:bg-secondary-dark rounded-lg border border-transparent
|
||||
data-[fullscreen=true]:border-primary-main"
|
||||
>
|
||||
<Checkbox
|
||||
name="fullscreen"
|
||||
checked={document.fullscreenElement ? true : false}
|
||||
@@ -311,65 +324,113 @@ const PlayerMenu = ({
|
||||
role="checkbox"
|
||||
aria-checked={document.fullscreenElement ? true : false}
|
||||
aria-label="Fullscreen"
|
||||
style={{ padding: '4px' }}
|
||||
/>
|
||||
</CheckboxContainer>
|
||||
</div>
|
||||
|
||||
<Button
|
||||
variant={wakeLock.active ? 'contained' : 'outlined'}
|
||||
<button
|
||||
data-wake-lock-active={settings.keepAwake}
|
||||
style={{
|
||||
cursor: 'pointer',
|
||||
userSelect: 'none',
|
||||
fontSize: buttonFontSize,
|
||||
padding: '0 4px 0 4px',
|
||||
}}
|
||||
onClick={wakeLock.toggleWakeLock}
|
||||
className="text-primary-main px-1 webkit-user-select-none cursor-pointer
|
||||
data-[wake-lock-active=true]:bg-secondary-dark rounded-lg border border-transparent
|
||||
data-[wake-lock-active=true]:border-primary-main
|
||||
"
|
||||
onClick={() => {
|
||||
wakeLock.toggleWakeLock();
|
||||
}}
|
||||
role="checkbox"
|
||||
aria-checked={wakeLock.active}
|
||||
aria-checked={settings.keepAwake}
|
||||
aria-label="Keep awake"
|
||||
>
|
||||
Keep Awake
|
||||
</Button>
|
||||
</button>
|
||||
|
||||
<Button
|
||||
<button
|
||||
style={{
|
||||
cursor: 'pointer',
|
||||
userSelect: 'none',
|
||||
fontSize: buttonFontSize,
|
||||
padding: '4px',
|
||||
padding: '2px',
|
||||
}}
|
||||
className="text-primary-main"
|
||||
onClick={() => resetGameDialogRef.current?.show()}
|
||||
role="checkbox"
|
||||
aria-checked={wakeLock.active}
|
||||
aria-label="Reset Game"
|
||||
>
|
||||
<ResetGame size={iconSize} />
|
||||
</Button>
|
||||
</button>
|
||||
</ButtonsSections>
|
||||
</BetterRowContainer>
|
||||
|
||||
<dialog
|
||||
ref={resetGameDialogRef}
|
||||
className="z-[999] size-full bg-background-settings"
|
||||
className="z-[999] size-full bg-background-settings overflow-y-scroll"
|
||||
onClick={() => resetGameDialogRef.current?.close()}
|
||||
>
|
||||
<div className="flex size-full items-center justify-center">
|
||||
<div className="flex flex-col justify-center p-4 gap-2 bg-background-default rounded-2xl border-none">
|
||||
<h1 className="text-center text-text-primary">Reset Game?</h1>
|
||||
<div className="flex justify-evenly gap-4">
|
||||
<Button
|
||||
variant="contained"
|
||||
<div className="flex flex-col justify-center p-4 gap-2 bg-background-default rounded-xl border-none">
|
||||
<h1
|
||||
className="text-center text-text-primary"
|
||||
style={{ fontSize: extraCountersSize }}
|
||||
>
|
||||
Reset Game?
|
||||
</h1>
|
||||
<div className="flex justify-evenly gap-2">
|
||||
<button
|
||||
className="bg-primary-main border border-primary-dark text-text-primary rounded-lg flex-grow"
|
||||
style={{ fontSize: iconSize }}
|
||||
onClick={() => resetGameDialogRef.current?.close()}
|
||||
>
|
||||
No
|
||||
</Button>
|
||||
<Button
|
||||
variant="contained"
|
||||
</button>
|
||||
<button
|
||||
className="bg-primary-main border border-primary-dark text-text-primary rounded-lg flex-grow"
|
||||
onClick={() => {
|
||||
handleResetGame();
|
||||
resetGameDialogRef.current?.close();
|
||||
}}
|
||||
style={{ fontSize: iconSize }}
|
||||
>
|
||||
Yes
|
||||
</Button>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</dialog>
|
||||
|
||||
<dialog
|
||||
ref={endGameDialogRef}
|
||||
className="z-[999] size-full bg-background-settings overflow-y-scroll"
|
||||
onClick={() => endGameDialogRef.current?.close()}
|
||||
>
|
||||
<div className="flex size-full items-center justify-center">
|
||||
<div className="flex flex-col justify-center p-4 gap-2 bg-background-default rounded-xl border-none">
|
||||
<h1
|
||||
className="text-center text-text-primary"
|
||||
style={{ fontSize: extraCountersSize }}
|
||||
>
|
||||
End Game?
|
||||
</h1>
|
||||
<div className="flex justify-evenly gap-2">
|
||||
<button
|
||||
className="bg-primary-main border border-primary-dark text-text-primary rounded-lg flex-grow"
|
||||
style={{ fontSize: iconSize }}
|
||||
onClick={() => endGameDialogRef.current?.close()}
|
||||
>
|
||||
No
|
||||
</button>
|
||||
<button
|
||||
className="bg-primary-main border border-primary-dark text-text-primary rounded-lg flex-grow"
|
||||
onClick={() => {
|
||||
handleGoToStart();
|
||||
endGameDialogRef.current?.close();
|
||||
}}
|
||||
style={{ fontSize: iconSize }}
|
||||
>
|
||||
Yes
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -1,6 +1,8 @@
|
||||
import LifeCounter from '../LifeCounter/LifeCounter';
|
||||
import { Player as PlayerType } from '../../Types/Player';
|
||||
import { twc } from 'react-twc';
|
||||
import { usePlayers } from '../../Hooks/usePlayers';
|
||||
import { Player as PlayerType } from '../../Types/Player';
|
||||
import LifeCounter from '../LifeCounter/LifeCounter';
|
||||
import { GridLayout } from '../Views/Play';
|
||||
|
||||
const getGridArea = (player: PlayerType) => {
|
||||
switch (player.index) {
|
||||
@@ -21,15 +23,16 @@ const getGridArea = (player: PlayerType) => {
|
||||
}
|
||||
};
|
||||
|
||||
const PlayerWrapper = twc.div`w-full h-full bg-black`;
|
||||
const PlayersWrapper = twc.div`w-full h-full bg-black`;
|
||||
|
||||
export const Players = ({ gridLayout }: { gridLayout: GridLayout }) => {
|
||||
const { players } = usePlayers();
|
||||
|
||||
export const Player = (players: PlayerType[], gridClasses: string) => {
|
||||
return (
|
||||
<PlayerWrapper>
|
||||
<div className={`grid w-full h-full gap-1 box-border ${gridClasses} `}>
|
||||
<PlayersWrapper>
|
||||
<div className={`grid w-full h-full gap-1 box-border ${gridLayout} `}>
|
||||
{players.map((player) => {
|
||||
const gridArea = getGridArea(player);
|
||||
|
||||
return (
|
||||
<div
|
||||
key={player.index}
|
||||
@@ -45,6 +48,6 @@ export const Player = (players: PlayerType[], gridClasses: string) => {
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
</PlayerWrapper>
|
||||
</PlayersWrapper>
|
||||
);
|
||||
};
|
||||
198
src/Components/PreStartGame/Games/FingerGame.tsx
Normal file
198
src/Components/PreStartGame/Games/FingerGame.tsx
Normal file
@@ -0,0 +1,198 @@
|
||||
import { useEffect, useRef, useState } from 'react';
|
||||
import { useGlobalSettings } from '../../../Hooks/useGlobalSettings';
|
||||
import { usePlayers } from '../../../Hooks/usePlayers';
|
||||
|
||||
type TouchPoint = {
|
||||
x: number;
|
||||
y: number;
|
||||
id: number;
|
||||
};
|
||||
|
||||
const getOrientation = () => {
|
||||
return window.matchMedia('(orientation: portrait)').matches
|
||||
? 'portrait'
|
||||
: 'landscape';
|
||||
};
|
||||
|
||||
export const FingerGame = () => {
|
||||
const { players } = usePlayers();
|
||||
|
||||
const aboutToStartTimerRef = useRef<NodeJS.Timeout | null>(null);
|
||||
const selectingPlayerTimerRef = useRef<NodeJS.Timeout | null>(null);
|
||||
|
||||
const [touchPoints, setTouchPoints] = useState<TouchPoint[]>([]);
|
||||
const [selectedTouchPoint, setSelectedTouchPoint] = useState<
|
||||
TouchPoint | undefined
|
||||
>();
|
||||
const [timerStarted, setTimerStarted] = useState(false);
|
||||
|
||||
const { setPlaying, goToStart } = useGlobalSettings();
|
||||
|
||||
useEffect(() => {
|
||||
//Start playing when someone is selected and any touch point is released
|
||||
if (selectedTouchPoint && touchPoints.length !== players.length) {
|
||||
aboutToStartTimerRef.current = setTimeout(() => {
|
||||
setSelectedTouchPoint(undefined);
|
||||
setPlaying(true);
|
||||
}, 500);
|
||||
|
||||
setTimerStarted(true);
|
||||
return;
|
||||
}
|
||||
|
||||
// If no touch point is selected, select one with a delay
|
||||
if (touchPoints.length === players.length && !selectedTouchPoint) {
|
||||
selectingPlayerTimerRef.current = setTimeout(() => {
|
||||
const randomIndex = Math.floor(Math.random() * touchPoints.length);
|
||||
const randomTouchPoint = touchPoints[randomIndex];
|
||||
setSelectedTouchPoint(randomTouchPoint);
|
||||
}, 250);
|
||||
return;
|
||||
}
|
||||
|
||||
if (selectingPlayerTimerRef.current) {
|
||||
clearTimeout(selectingPlayerTimerRef.current);
|
||||
}
|
||||
|
||||
return () => {
|
||||
if (aboutToStartTimerRef.current) {
|
||||
clearTimeout(aboutToStartTimerRef.current);
|
||||
}
|
||||
};
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [touchPoints, players.length]);
|
||||
|
||||
const handleOnTouchStart = (e: React.TouchEvent) => {
|
||||
if (selectedTouchPoint) {
|
||||
return;
|
||||
}
|
||||
//Get the first touch point id that isn't already in the touchPoints array
|
||||
const touch = Array.from(e.changedTouches).find(
|
||||
(t) => !touchPoints.find((p) => p.id === t.identifier)
|
||||
);
|
||||
|
||||
if (!touch) {
|
||||
console.error('No touch found');
|
||||
return;
|
||||
}
|
||||
|
||||
let { clientX, clientY } = touch;
|
||||
|
||||
// Adjust coordinates for portrait mode
|
||||
if (getOrientation() === 'portrait') {
|
||||
const tempX = clientX;
|
||||
clientX = clientY;
|
||||
clientY = window.innerWidth - tempX;
|
||||
}
|
||||
|
||||
const newTouchPoints = {
|
||||
x: clientX,
|
||||
y: clientY,
|
||||
id: touch.identifier,
|
||||
};
|
||||
|
||||
setTouchPoints([...touchPoints, newTouchPoints]);
|
||||
};
|
||||
|
||||
const handleOnTouchEnd = (e: React.TouchEvent) => {
|
||||
if (selectedTouchPoint) {
|
||||
aboutToStartTimerRef.current = setTimeout(() => {
|
||||
setSelectedTouchPoint(undefined);
|
||||
setPlaying(true);
|
||||
}, 500);
|
||||
setTimerStarted(true);
|
||||
return;
|
||||
}
|
||||
|
||||
// Get the touch point that was just released
|
||||
const touch = e.changedTouches[e.changedTouches.length - 1];
|
||||
|
||||
// Get the index of the touch point that was just released
|
||||
const index = touchPoints.findIndex((p) => p.id === touch.identifier);
|
||||
|
||||
// Remove the touch point that was just released
|
||||
setTouchPoints([
|
||||
...touchPoints.slice(0, index),
|
||||
...touchPoints.slice(index + 1),
|
||||
]);
|
||||
};
|
||||
|
||||
return (
|
||||
<div
|
||||
className="absolute flex justify-center items-center w-full h-full portrait:h-[100dvw] portrait:w-[100dvh] z-50 bg-secondary-main overflow-hidden"
|
||||
onTouchStart={handleOnTouchStart}
|
||||
onTouchEnd={handleOnTouchEnd}
|
||||
|
||||
// FIXEME: This code is not performant, but updates a touch point's position when it moves
|
||||
// onTouchMove={(e) => {
|
||||
// e.preventDefault();
|
||||
|
||||
// // Get the touch point that was just moved
|
||||
// const touch = Array.from(e.changedTouches).find((t) =>
|
||||
// touchPoints.find((p) => p.id === t.identifier)
|
||||
// );
|
||||
|
||||
// if (!touch) {
|
||||
// console.error('No touch found');
|
||||
// return;
|
||||
// }
|
||||
|
||||
// let { clientX, clientY } = touch;
|
||||
|
||||
// // Adjust coordinates for portrait mode
|
||||
// if (getOrientation() === 'portrait') {
|
||||
// const tempX = clientX;
|
||||
// clientX = clientY;
|
||||
// clientY = window.innerWidth - tempX;
|
||||
// }
|
||||
|
||||
// // Get the index of the touch point that was just moved
|
||||
// const index = touchPoints.findIndex(
|
||||
// (p) => p.id === touch.identifier
|
||||
// );
|
||||
|
||||
// // Update the touch point that was just moved
|
||||
// setTouchPoints([
|
||||
// ...touchPoints.slice(0, index),
|
||||
// { x: clientX, y: clientY, id: touch.identifier },
|
||||
// ...touchPoints.slice(index + 1),
|
||||
// ]);
|
||||
// }}
|
||||
>
|
||||
<button
|
||||
className="absolute flex top-4 left-4 rounded-lg px-2 py-1 justify-center bg-primary-main text-text-primary text-xs"
|
||||
onClick={goToStart}
|
||||
>
|
||||
<div className="text-xl leading-4">{'<'} </div>
|
||||
Back
|
||||
</button>
|
||||
{touchPoints.length !== players.length && (
|
||||
<div className="flex flex-col items-center text-[13vmin] whitespace-nowrap pointer-events-none webkit-user-select-none">
|
||||
Waiting for fingers <br />
|
||||
<div className="tabular-nums">
|
||||
{touchPoints.length}/{players.length}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{touchPoints.map((point, index) => (
|
||||
<div
|
||||
key={`touch-point-${index}`}
|
||||
data-is-selected={selectedTouchPoint?.id === point.id}
|
||||
data-unloading={timerStarted}
|
||||
className="absolute rounded-full translate-x-[-50%] translate-y-[-50%] transition-all duration-1000
|
||||
h-[75px] w-[75px]
|
||||
data-[unloading=false]:data-[is-selected=true]:h-[250px] data-[unloading=false]:data-[is-selected=true]:w-[250px]
|
||||
data-[unloading=true]:h-[0px] data-[unloading=true]:w-[0px] data-[unloading=true]:duration-[400ms]
|
||||
pointer-events-none
|
||||
"
|
||||
style={{
|
||||
left: point.x,
|
||||
top: point.y,
|
||||
backgroundColor: players[index]?.color ?? 'red',
|
||||
}}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1,49 @@
|
||||
import { usePlayers } from '../../../../Hooks/usePlayers';
|
||||
import { Player } from '../../../../Types/Player';
|
||||
import { GridLayout } from '../../../Views/Play';
|
||||
import { RoulettePlayerCard } from './RoulettePlayerCard';
|
||||
|
||||
const getGridArea = (player: Player) => {
|
||||
switch (player.index) {
|
||||
case 0:
|
||||
return 'grid-in-player0';
|
||||
case 1:
|
||||
return 'grid-in-player1';
|
||||
case 2:
|
||||
return 'grid-in-player2';
|
||||
case 3:
|
||||
return 'grid-in-player3';
|
||||
case 4:
|
||||
return 'grid-in-player4';
|
||||
case 5:
|
||||
return 'grid-in-player5';
|
||||
default:
|
||||
throw new Error('Invalid player index');
|
||||
}
|
||||
};
|
||||
|
||||
export const RandomKingPlayers = ({
|
||||
gridLayout,
|
||||
}: {
|
||||
gridLayout: GridLayout;
|
||||
}) => {
|
||||
const { players } = usePlayers();
|
||||
|
||||
return (
|
||||
<div className="w-full h-full bg-black">
|
||||
<div className={`grid w-full h-full gap-1 box-border ${gridLayout} `}>
|
||||
{players.map((player) => {
|
||||
const gridArea = getGridArea(player);
|
||||
return (
|
||||
<div
|
||||
key={player.index}
|
||||
className={`flex justify-center items-center align-middle ${gridArea}`}
|
||||
>
|
||||
<RoulettePlayerCard player={player} />
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1,94 @@
|
||||
import { useEffect, useRef } from 'react';
|
||||
import { useGlobalSettings } from '../../../../Hooks/useGlobalSettings';
|
||||
import { usePlayers } from '../../../../Hooks/usePlayers';
|
||||
|
||||
export const RandomKingSelectWrapper = () => {
|
||||
const { setRandomizingPlayer } = useGlobalSettings();
|
||||
|
||||
const randomIntervalRef = useRef<NodeJS.Timeout | null>(null);
|
||||
const prevRandomIndexRef = useRef<number>(-1);
|
||||
|
||||
const { settings, randomizingPlayer, setPreStartCompleted } =
|
||||
useGlobalSettings();
|
||||
|
||||
const { players, setPlayers } = usePlayers();
|
||||
|
||||
useEffect(() => {
|
||||
if (
|
||||
players.length > 1 &&
|
||||
settings.showStartingPlayer &&
|
||||
randomizingPlayer
|
||||
) {
|
||||
randomIntervalRef.current = setInterval(() => {
|
||||
let randomIndex: number;
|
||||
|
||||
do {
|
||||
randomIndex = Math.floor(Math.random() * players.length);
|
||||
} while (randomIndex === prevRandomIndexRef.current);
|
||||
|
||||
prevRandomIndexRef.current = randomIndex;
|
||||
setPlayers(
|
||||
players.map((p) =>
|
||||
p.index === prevRandomIndexRef.current
|
||||
? {
|
||||
...p,
|
||||
isStartingPlayer: true,
|
||||
}
|
||||
: {
|
||||
...p,
|
||||
isStartingPlayer: false,
|
||||
}
|
||||
)
|
||||
);
|
||||
}, 100);
|
||||
}
|
||||
|
||||
const randomPlayerIndex = Math.floor(Math.random() * players.length);
|
||||
setPlayers(
|
||||
players.map((p) =>
|
||||
p.index === randomPlayerIndex
|
||||
? {
|
||||
...p,
|
||||
isStartingPlayer: true,
|
||||
}
|
||||
: {
|
||||
...p,
|
||||
isStartingPlayer: false,
|
||||
}
|
||||
)
|
||||
);
|
||||
|
||||
return () => {
|
||||
if (randomIntervalRef.current) {
|
||||
clearInterval(randomIntervalRef.current);
|
||||
}
|
||||
};
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [players.length, setPlayers, randomizingPlayer]);
|
||||
|
||||
const gradientColors = players.map((player) => player.color).join(', ');
|
||||
|
||||
return (
|
||||
<div
|
||||
className="absolute flex justify-center items-center h-screen w-screen portrait:h-[100vw] portrait:w-[100vh] z-40 cursor-pointer text-5xl"
|
||||
onClick={() => {
|
||||
if (randomIntervalRef.current) {
|
||||
clearInterval(randomIntervalRef.current);
|
||||
randomIntervalRef.current = null;
|
||||
}
|
||||
setRandomizingPlayer(false);
|
||||
setPreStartCompleted(true);
|
||||
}}
|
||||
>
|
||||
<div className="absolute flex top-[30%] justify-center items-center px-8 py-4">
|
||||
<div
|
||||
className="absolute size-full blur-[3px] rounded-2xl opacity-90 saturate-150"
|
||||
style={{
|
||||
backgroundImage: `linear-gradient(60deg, ${gradientColors})`,
|
||||
}}
|
||||
/>
|
||||
<p className="relative z-10 text-[5vmax]">PRESS TO SELECT PLAYER</p>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1,58 @@
|
||||
import { useEffect, useRef } from 'react';
|
||||
import { useGlobalSettings } from '../../../../Hooks/useGlobalSettings';
|
||||
import { Player, Rotation } from '../../../../Types/Player';
|
||||
import { Paragraph } from '../../../Misc/TextComponents';
|
||||
import { DynamicText } from '../../StartingPlayerCard';
|
||||
|
||||
export const RoulettePlayerCard = ({ player }: { player: Player }) => {
|
||||
const startPlayingTimerRef = useRef<NodeJS.Timeout | undefined>(undefined);
|
||||
|
||||
const { settings, randomizingPlayer, playing, setPlaying } =
|
||||
useGlobalSettings();
|
||||
|
||||
useEffect(() => {
|
||||
if (
|
||||
player.isStartingPlayer &&
|
||||
((!playing && randomizingPlayer) || !playing)
|
||||
) {
|
||||
startPlayingTimerRef.current = setTimeout(() => {
|
||||
setPlaying(true);
|
||||
}, 10_000);
|
||||
}
|
||||
|
||||
return () => clearTimeout(startPlayingTimerRef.current);
|
||||
}, [
|
||||
player.isStartingPlayer,
|
||||
playing,
|
||||
setPlaying,
|
||||
settings.preStartMode,
|
||||
randomizingPlayer,
|
||||
]);
|
||||
|
||||
const calcTextRotation =
|
||||
player.settings.rotation === Rotation.SideFlipped ||
|
||||
player.settings.rotation === Rotation.Side
|
||||
? player.settings.rotation - 180
|
||||
: player.settings.rotation;
|
||||
|
||||
return (
|
||||
<div className="relative flex flex-grow flex-col items-center w-full h-full overflow-hidden">
|
||||
<div
|
||||
className="flex absolute w-full h-full justify-center items-center pointer-events-none select-none webkit-user-select-none z-10"
|
||||
style={{ backgroundColor: player.color }}
|
||||
>
|
||||
{player.isStartingPlayer && (
|
||||
<DynamicText
|
||||
style={{
|
||||
rotate: `${calcTextRotation}deg`,
|
||||
}}
|
||||
>
|
||||
<div className="flex flex-col justify-center items-center">
|
||||
<Paragraph>👑</Paragraph>
|
||||
</div>
|
||||
</DynamicText>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
30
src/Components/PreStartGame/PreStart.tsx
Normal file
30
src/Components/PreStartGame/PreStart.tsx
Normal file
@@ -0,0 +1,30 @@
|
||||
import { useGlobalSettings } from '../../Hooks/useGlobalSettings';
|
||||
import { PreStartMode } from '../../Types/Settings';
|
||||
import { GridLayout } from '../Views/Play';
|
||||
import { FingerGame } from './Games/FingerGame';
|
||||
import { RandomKingPlayers } from './Games/RandomKing/RandomKingPlayers';
|
||||
import { RandomKingSelectWrapper } from './Games/RandomKing/RandomKingSelectWrapper';
|
||||
|
||||
export const PreStart = ({ gridLayout }: { gridLayout: GridLayout }) => {
|
||||
const { settings, randomizingPlayer, goToStart } = useGlobalSettings();
|
||||
|
||||
if (settings.preStartMode === PreStartMode.RandomKing) {
|
||||
if (!randomizingPlayer) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
<RandomKingSelectWrapper />
|
||||
<RandomKingPlayers gridLayout={gridLayout} />
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
if (settings.preStartMode === PreStartMode.FingerGame) {
|
||||
return <FingerGame />;
|
||||
}
|
||||
|
||||
goToStart();
|
||||
return null;
|
||||
};
|
||||
60
src/Components/PreStartGame/StartingPlayerCard.tsx
Normal file
60
src/Components/PreStartGame/StartingPlayerCard.tsx
Normal file
@@ -0,0 +1,60 @@
|
||||
import { twc } from 'react-twc';
|
||||
import { baseColors } from '../../../tailwind.config';
|
||||
import { useGlobalSettings } from '../../Hooks/useGlobalSettings';
|
||||
import { Player, Rotation } from '../../Types/Player';
|
||||
import { PreStartMode } from '../../Types/Settings';
|
||||
import { Paragraph } from '../Misc/TextComponents';
|
||||
|
||||
export const DynamicText = twc.div`text-[8vmin] whitespace-nowrap`;
|
||||
|
||||
export const StartingPlayerCard = ({ player }: { player: Player }) => {
|
||||
const { settings, setPlaying, randomizingPlayer } = useGlobalSettings();
|
||||
|
||||
const calcTextRotation =
|
||||
player.settings.rotation === Rotation.SideFlipped ||
|
||||
player.settings.rotation === Rotation.Side
|
||||
? player.settings.rotation - 180
|
||||
: player.settings.rotation;
|
||||
|
||||
const calcRotation =
|
||||
player.settings.rotation === Rotation.SideFlipped ||
|
||||
player.settings.rotation === Rotation.Side
|
||||
? player.settings.rotation - 90
|
||||
: player.settings.rotation;
|
||||
|
||||
return (
|
||||
<div
|
||||
className="z-20 flex absolute w-full h-full justify-center items-center select-none cursor-pointer webkit-user-select-none"
|
||||
style={{
|
||||
rotate: `${calcRotation}deg`,
|
||||
backgroundImage:
|
||||
!randomizingPlayer ||
|
||||
(settings.preStartMode !== PreStartMode.None &&
|
||||
settings.preStartMode !== PreStartMode.FingerGame)
|
||||
? `radial-gradient(circle at center, ${player.color}, ${baseColors.primary.main})`
|
||||
: 'none',
|
||||
}}
|
||||
onClick={() => {
|
||||
setPlaying(true);
|
||||
}}
|
||||
>
|
||||
<DynamicText
|
||||
style={{
|
||||
rotate: `${calcTextRotation}deg`,
|
||||
}}
|
||||
>
|
||||
<div className="flex flex-col justify-center items-center">
|
||||
<Paragraph>👑</Paragraph>
|
||||
{(!randomizingPlayer ||
|
||||
(settings.preStartMode !== PreStartMode.None &&
|
||||
settings.preStartMode !== PreStartMode.FingerGame)) && (
|
||||
<>
|
||||
<Paragraph>You start!</Paragraph>
|
||||
<Paragraph className="text-xl">(Press to hide)</Paragraph>
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
</DynamicText>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
@@ -1,67 +1,115 @@
|
||||
import { useEffect } from 'react';
|
||||
import { twc } from 'react-twc';
|
||||
import { twGridTemplateAreas } from '../../../tailwind.config';
|
||||
import { useGlobalSettings } from '../../Hooks/useGlobalSettings';
|
||||
import { usePlayers } from '../../Hooks/usePlayers';
|
||||
import { Orientation } from '../../Types/Settings';
|
||||
import { Player } from '../Player/Player';
|
||||
import { twc } from 'react-twc';
|
||||
import { Orientation, PreStartMode } from '../../Types/Settings';
|
||||
import { Players } from '../Players/Players';
|
||||
import { PreStart } from '../PreStartGame/PreStart';
|
||||
|
||||
const MainWrapper = twc.div`w-[100dvmax] h-[100dvmin] overflow-hidden`;
|
||||
const MainWrapper = twc.div`w-[100dvmax] h-[100dvmin] overflow-hidden, setPlayers`;
|
||||
|
||||
type GridTemplateAreasKeys = keyof typeof twGridTemplateAreas;
|
||||
|
||||
export type GridLayout = `grid-areas-${GridTemplateAreasKeys}`;
|
||||
|
||||
export const Play = () => {
|
||||
const { players } = usePlayers();
|
||||
const { initialGameSettings } = useGlobalSettings();
|
||||
const { players, setPlayers } = usePlayers();
|
||||
const { initialGameSettings, playing, settings, preStartCompleted } =
|
||||
useGlobalSettings();
|
||||
|
||||
let Layout: JSX.Element;
|
||||
let gridLayout: GridLayout;
|
||||
switch (players.length) {
|
||||
case 1:
|
||||
if (initialGameSettings?.orientation === Orientation.Portrait) {
|
||||
Layout = Player(players, 'grid-areas-onePlayerPortrait');
|
||||
gridLayout = 'grid-areas-onePlayerPortrait';
|
||||
}
|
||||
Layout = Player(players, 'grid-areas-onePlayerLandscape');
|
||||
gridLayout = 'grid-areas-onePlayerLandscape';
|
||||
break;
|
||||
case 2:
|
||||
switch (initialGameSettings?.orientation) {
|
||||
case Orientation.Portrait:
|
||||
Layout = Player(players, 'grid-areas-twoPlayersOppositePortrait');
|
||||
gridLayout = 'grid-areas-twoPlayersOppositePortrait';
|
||||
break;
|
||||
default:
|
||||
case Orientation.Landscape:
|
||||
Layout = Player(players, 'grid-areas-twoPlayersSameSideLandscape');
|
||||
gridLayout = 'grid-areas-twoPlayersSameSideLandscape';
|
||||
break;
|
||||
case Orientation.OppositeLandscape:
|
||||
Layout = Player(players, 'grid-areas-twoPlayersOppositeLandscape');
|
||||
gridLayout = 'grid-areas-twoPlayersOppositeLandscape';
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case 3:
|
||||
if (initialGameSettings?.orientation === Orientation.Portrait) {
|
||||
Layout = Player(players, 'grid-areas-threePlayersSide');
|
||||
gridLayout = 'grid-areas-threePlayersSide';
|
||||
break;
|
||||
}
|
||||
Layout = Player(players, 'grid-areas-threePlayers');
|
||||
gridLayout = 'grid-areas-threePlayers';
|
||||
break;
|
||||
default:
|
||||
case 4:
|
||||
if (initialGameSettings?.orientation === Orientation.Portrait) {
|
||||
Layout = Player(players, 'grid-areas-fourPlayerPortrait');
|
||||
gridLayout = 'grid-areas-fourPlayerPortrait';
|
||||
break;
|
||||
}
|
||||
Layout = Player(players, 'grid-areas-fourPlayer');
|
||||
gridLayout = 'grid-areas-fourPlayer';
|
||||
break;
|
||||
case 5:
|
||||
if (initialGameSettings?.orientation === Orientation.Portrait) {
|
||||
Layout = Player(players, 'grid-areas-fivePlayersSide');
|
||||
gridLayout = 'grid-areas-fivePlayersSide';
|
||||
break;
|
||||
}
|
||||
Layout = Player(players, 'grid-areas-fivePlayers');
|
||||
gridLayout = 'grid-areas-fivePlayers';
|
||||
break;
|
||||
case 6:
|
||||
if (initialGameSettings?.orientation === Orientation.Portrait) {
|
||||
Layout = Player(players, 'grid-areas-sixPlayersSide');
|
||||
gridLayout = 'grid-areas-sixPlayersSide';
|
||||
break;
|
||||
}
|
||||
Layout = Player(players, 'grid-areas-sixPlayers');
|
||||
gridLayout = 'grid-areas-sixPlayers';
|
||||
break;
|
||||
}
|
||||
|
||||
return <MainWrapper>{Layout}</MainWrapper>;
|
||||
useEffect(() => {
|
||||
if (settings.preStartMode !== PreStartMode.None) {
|
||||
return;
|
||||
}
|
||||
|
||||
const randomIndex = Math.floor(Math.random() * players.length);
|
||||
|
||||
setPlayers(
|
||||
players.map((p) =>
|
||||
p.index === randomIndex
|
||||
? {
|
||||
...p,
|
||||
isStartingPlayer: true,
|
||||
}
|
||||
: {
|
||||
...p,
|
||||
isStartingPlayer: false,
|
||||
}
|
||||
)
|
||||
);
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, []);
|
||||
|
||||
if (
|
||||
!preStartCompleted &&
|
||||
settings.preStartMode !== PreStartMode.None &&
|
||||
!playing &&
|
||||
settings.showStartingPlayer
|
||||
) {
|
||||
return (
|
||||
<MainWrapper>
|
||||
<PreStart gridLayout={gridLayout} />
|
||||
</MainWrapper>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<MainWrapper>
|
||||
<Players gridLayout={gridLayout} />
|
||||
</MainWrapper>
|
||||
);
|
||||
};
|
||||
|
||||
@@ -3,10 +3,12 @@ import React from 'react';
|
||||
import { theme } from '../../../Data/theme';
|
||||
import {
|
||||
FivePlayers,
|
||||
FivePlayersSide,
|
||||
FourPlayers,
|
||||
FourPlayersSide,
|
||||
OnePlayerPortrait,
|
||||
SixPlayers,
|
||||
SixPlayersSide,
|
||||
ThreePlayers,
|
||||
ThreePlayersSide,
|
||||
TwoPlayersOppositeLandscape,
|
||||
@@ -40,7 +42,7 @@ export const LayoutOptions: React.FC<LayoutOptionsProps> = ({
|
||||
switch (numberOfPlayers) {
|
||||
case 1:
|
||||
return (
|
||||
<div>
|
||||
<>
|
||||
<FormControlLabel
|
||||
value={Orientation.Landscape}
|
||||
control={
|
||||
@@ -89,7 +91,7 @@ export const LayoutOptions: React.FC<LayoutOptionsProps> = ({
|
||||
}
|
||||
label=""
|
||||
/>
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
case 2:
|
||||
return (
|
||||
@@ -303,20 +305,21 @@ export const LayoutOptions: React.FC<LayoutOptionsProps> = ({
|
||||
}
|
||||
label=""
|
||||
/>
|
||||
{/* <FormControlLabel
|
||||
value={GridTemplateAreas.FivePlayersSide}
|
||||
<FormControlLabel
|
||||
value={Orientation.Portrait}
|
||||
control={
|
||||
<Radio
|
||||
style={{ maxWidth: iconMaxWidth, maxHeight: iconMaxHeight }}
|
||||
icon={
|
||||
<FivePlayersSide
|
||||
height={iconHeight}
|
||||
height={iconHeight}
|
||||
width={iconWidth}
|
||||
fill={theme.palette.secondary.main}
|
||||
/>
|
||||
}
|
||||
checkedIcon={
|
||||
<FivePlayersSide
|
||||
height={iconHeight}
|
||||
height={iconHeight}
|
||||
width={iconWidth}
|
||||
fill={theme.palette.primary.main}
|
||||
/>
|
||||
@@ -325,7 +328,7 @@ export const LayoutOptions: React.FC<LayoutOptionsProps> = ({
|
||||
/>
|
||||
}
|
||||
label=""
|
||||
/> */}
|
||||
/>
|
||||
</>
|
||||
);
|
||||
|
||||
@@ -356,20 +359,21 @@ export const LayoutOptions: React.FC<LayoutOptionsProps> = ({
|
||||
}
|
||||
label=""
|
||||
/>
|
||||
{/* <FormControlLabel
|
||||
value={GridTemplateAreas.SixPlayersSide}
|
||||
<FormControlLabel
|
||||
value={Orientation.Portrait}
|
||||
control={
|
||||
<Radio
|
||||
style={{ maxWidth: iconMaxWidth, maxHeight: iconMaxHeight }}
|
||||
icon={
|
||||
<SixPlayersSide
|
||||
height={iconHeight}
|
||||
height={iconHeight}
|
||||
width={iconWidth}
|
||||
fill={theme.palette.secondary.main}
|
||||
/>
|
||||
}
|
||||
checkedIcon={
|
||||
<SixPlayersSide
|
||||
height={iconHeight}
|
||||
height={iconHeight}
|
||||
width={iconWidth}
|
||||
fill={theme.palette.primary.main}
|
||||
/>
|
||||
@@ -378,7 +382,7 @@ export const LayoutOptions: React.FC<LayoutOptionsProps> = ({
|
||||
/>
|
||||
}
|
||||
label=""
|
||||
/> */}
|
||||
/>
|
||||
</>
|
||||
);
|
||||
|
||||
|
||||
@@ -12,6 +12,7 @@ import {
|
||||
GameFormat,
|
||||
InitialGameSettings,
|
||||
Orientation,
|
||||
PreStartMode,
|
||||
} from '../../../Types/Settings';
|
||||
import { InfoModal } from '../../Misc/InfoModal';
|
||||
import { SettingsModal } from '../../Misc/SettingsModal';
|
||||
@@ -89,6 +90,7 @@ const Start = () => {
|
||||
setInitialGameSettings,
|
||||
settings,
|
||||
isPWA,
|
||||
setRandomizingPlayer,
|
||||
} = useGlobalSettings();
|
||||
|
||||
const [openInfoModal, setOpenInfoModal] = useState(false);
|
||||
@@ -126,6 +128,7 @@ const Start = () => {
|
||||
setInitialGameSettings(initialGameSettings);
|
||||
setPlayers(createInitialPlayers(initialGameSettings));
|
||||
setShowPlay(true);
|
||||
setRandomizingPlayer(settings.preStartMode === PreStartMode.RandomKing);
|
||||
localStorage.setItem('playing', 'false');
|
||||
localStorage.setItem('showPlay', 'true');
|
||||
};
|
||||
@@ -262,18 +265,6 @@ const Start = () => {
|
||||
</ToggleButtonsWrapper>
|
||||
|
||||
<FormLabel>Layout</FormLabel>
|
||||
{/* <LayoutOptions
|
||||
numberOfPlayers={playerOptions.numberOfPlayers}
|
||||
gridAreas={playerOptions.gridAreas}
|
||||
onChange={(gridAreas) =>
|
||||
setPlayerOptions({
|
||||
...playerOptions,
|
||||
gridAreas,
|
||||
//TODO fix the layout selection
|
||||
orientation: Orientation.Portrait,
|
||||
})
|
||||
}
|
||||
/> */}
|
||||
<LayoutOptions
|
||||
numberOfPlayers={playerOptions.numberOfPlayers}
|
||||
selectedOrientation={playerOptions.orientation}
|
||||
|
||||
@@ -22,7 +22,13 @@ export type GlobalSettingsContextType = {
|
||||
setInitialGameSettings: (initialGameSettings: InitialGameSettings) => void;
|
||||
settings: Settings;
|
||||
setSettings: (settings: Settings) => void;
|
||||
playing: boolean;
|
||||
setPlaying: (playing: boolean) => void;
|
||||
randomizingPlayer: boolean;
|
||||
setRandomizingPlayer: (stopRandom: boolean) => void;
|
||||
isPWA: boolean;
|
||||
preStartCompleted: boolean;
|
||||
setPreStartCompleted: (completed: boolean) => void;
|
||||
};
|
||||
|
||||
export const GlobalSettingsContext =
|
||||
|
||||
@@ -7,6 +7,8 @@ export type PlayersContextType = {
|
||||
updatePlayer: (updatedPlayer: Player) => void;
|
||||
updateLifeTotal: (player: Player, updatedLifeTotal: number) => number;
|
||||
resetCurrentGame: () => void;
|
||||
startingPlayerIndex: number;
|
||||
setStartingPlayerIndex: (index: number) => void;
|
||||
};
|
||||
|
||||
export const PlayersContext = createContext<PlayersContextType | null>(null);
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { Player, Rotation } from '../Types/Player';
|
||||
import { InitialGameSettings, Orientation } from '../Types/Settings';
|
||||
|
||||
const presetColors = [
|
||||
export const presetColors = [
|
||||
'#F06292', // Light Pink
|
||||
'#4DB6AC', // Teal
|
||||
'#FFA726', // Orange
|
||||
@@ -127,15 +127,15 @@ const getOrientationRotations = (
|
||||
case Orientation.Portrait:
|
||||
switch (index) {
|
||||
case 0:
|
||||
return Rotation.Side;
|
||||
return Rotation.Flipped;
|
||||
case 1:
|
||||
return Rotation.Side;
|
||||
return Rotation.Flipped;
|
||||
case 2:
|
||||
return Rotation.SideFlipped;
|
||||
return Rotation.Side;
|
||||
case 3:
|
||||
return Rotation.SideFlipped;
|
||||
return Rotation.Normal;
|
||||
case 4:
|
||||
return Rotation.SideFlipped;
|
||||
return Rotation.Normal;
|
||||
default:
|
||||
return Rotation.Normal;
|
||||
}
|
||||
@@ -163,17 +163,17 @@ const getOrientationRotations = (
|
||||
case Orientation.Portrait:
|
||||
switch (index) {
|
||||
case 0:
|
||||
return Rotation.Side;
|
||||
return Rotation.SideFlipped;
|
||||
case 1:
|
||||
return Rotation.Side;
|
||||
return Rotation.Flipped;
|
||||
case 2:
|
||||
return Rotation.Side;
|
||||
return Rotation.Flipped;
|
||||
case 3:
|
||||
return Rotation.SideFlipped;
|
||||
return Rotation.Side;
|
||||
case 4:
|
||||
return Rotation.SideFlipped;
|
||||
return Rotation.Normal;
|
||||
case 5:
|
||||
return Rotation.SideFlipped;
|
||||
return Rotation.Normal;
|
||||
default:
|
||||
return Rotation.Normal;
|
||||
}
|
||||
@@ -191,10 +191,8 @@ export const createInitialPlayers = ({
|
||||
}: InitialGameSettings): Player[] => {
|
||||
const players: Player[] = [];
|
||||
const availableColors = [...presetColors]; // Create a copy of the colors array
|
||||
const firstPlayerIndex = Math.floor(Math.random() * numberOfPlayers);
|
||||
|
||||
for (let i = 0; i <= numberOfPlayers - 1; i++) {
|
||||
const isStartingPlayer = i === firstPlayerIndex;
|
||||
const colorIndex = Math.floor(Math.random() * availableColors.length);
|
||||
const color = availableColors[colorIndex];
|
||||
|
||||
@@ -224,11 +222,10 @@ export const createInitialPlayers = ({
|
||||
usePoison: false,
|
||||
rotation,
|
||||
},
|
||||
isStartingPlayer,
|
||||
showStartingPlayer: isStartingPlayer,
|
||||
extraCounters: [],
|
||||
commanderDamage,
|
||||
hasLost: false,
|
||||
isStartingPlayer: false,
|
||||
isSide: rotation === Rotation.Side || rotation === Rotation.SideFlipped,
|
||||
};
|
||||
|
||||
|
||||
@@ -18,6 +18,11 @@ export const useAnalytics = () => {
|
||||
eventName: string,
|
||||
eventParams?: { [key: string]: unknown }
|
||||
) => {
|
||||
if (process.env.NODE_ENV === 'development') {
|
||||
console.info('Event not tracked:', { eventName, eventParams });
|
||||
return;
|
||||
}
|
||||
|
||||
logEvent(analytics, eventName, eventParams);
|
||||
};
|
||||
|
||||
|
||||
@@ -23,7 +23,6 @@ export default function useOrientation(
|
||||
const onChange = () => {
|
||||
if (mounted) {
|
||||
const { orientation } = screen;
|
||||
console.log(orientation);
|
||||
|
||||
if (orientation) {
|
||||
const { angle, type } = orientation;
|
||||
|
||||
@@ -7,8 +7,10 @@ import {
|
||||
import { useAnalytics } from '../Hooks/useAnalytics';
|
||||
import {
|
||||
InitialGameSettings,
|
||||
InitialGameSettingsSchema,
|
||||
initialGameSettingsSchema,
|
||||
PreStartMode,
|
||||
Settings,
|
||||
settingsSchema,
|
||||
} from '../Types/Settings';
|
||||
|
||||
export const GlobalSettingsProvider = ({
|
||||
@@ -21,33 +23,66 @@ export const GlobalSettingsProvider = ({
|
||||
const savedShowPlay = localStorage.getItem('showPlay');
|
||||
const savedGameSettings = localStorage.getItem('initialGameSettings');
|
||||
const savedSettings = localStorage.getItem('settings');
|
||||
const savedPlaying = localStorage.getItem('playing');
|
||||
const savedPreStartComplete = localStorage.getItem('preStartComplete');
|
||||
|
||||
const [playing, setPlaying] = useState<boolean>(
|
||||
savedPlaying ? savedPlaying === 'true' : false
|
||||
);
|
||||
const setPlayingAndLocalStorage = (playing: boolean) => {
|
||||
setPlaying(playing);
|
||||
localStorage.setItem('playing', String(playing));
|
||||
};
|
||||
|
||||
const [preStartCompleted, setPreStartCompleted] = useState<boolean>(
|
||||
savedPreStartComplete ? savedPreStartComplete === 'true' : false
|
||||
);
|
||||
|
||||
const [showPlay, setShowPlay] = useState<boolean>(
|
||||
savedShowPlay ? savedShowPlay === 'true' : false
|
||||
);
|
||||
|
||||
const [randomizingPlayer, setRandomizingPlayer] = useState<boolean>(
|
||||
savedSettings
|
||||
? Boolean(JSON.parse(savedSettings).preStartMode === 'random-king')
|
||||
: true
|
||||
);
|
||||
|
||||
const [initialGameSettings, setInitialGameSettings] =
|
||||
useState<InitialGameSettings | null>(
|
||||
savedGameSettings ? JSON.parse(savedGameSettings) : null
|
||||
);
|
||||
|
||||
const parsedSettings = settingsSchema.safeParse(
|
||||
JSON.parse(savedSettings ?? '')
|
||||
);
|
||||
const [settings, setSettings] = useState<Settings>(
|
||||
savedSettings
|
||||
? JSON.parse(savedSettings)
|
||||
parsedSettings.success
|
||||
? parsedSettings.data
|
||||
: {
|
||||
goFullscreenOnStart: true,
|
||||
keepAwake: true,
|
||||
showStartingPlayer: true,
|
||||
showPlayerMenuCog: true,
|
||||
preStartMode: PreStartMode.None,
|
||||
}
|
||||
);
|
||||
|
||||
const setSettingsAndLocalStorage = (settings: Settings) => {
|
||||
setSettings(settings);
|
||||
localStorage.setItem('settings', JSON.stringify(settings));
|
||||
};
|
||||
|
||||
const removeLocalStorage = async () => {
|
||||
localStorage.removeItem('initialGameSettings');
|
||||
localStorage.removeItem('players');
|
||||
localStorage.removeItem('playing');
|
||||
localStorage.removeItem('showPlay');
|
||||
localStorage.removeItem('preStartComplete');
|
||||
|
||||
setPlaying(false);
|
||||
setShowPlay(false);
|
||||
setPreStartCompleted(false);
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
@@ -59,7 +94,7 @@ export const GlobalSettingsProvider = ({
|
||||
|
||||
//parse existing game settings with zod schema
|
||||
const parsedInitialGameSettings =
|
||||
InitialGameSettingsSchema.safeParse(initialGameSettings);
|
||||
initialGameSettingsSchema.safeParse(initialGameSettings);
|
||||
|
||||
if (!parsedInitialGameSettings.success) {
|
||||
removeLocalStorage();
|
||||
@@ -73,10 +108,6 @@ export const GlobalSettingsProvider = ({
|
||||
);
|
||||
}, [initialGameSettings, savedGameSettings]);
|
||||
|
||||
useEffect(() => {
|
||||
localStorage.setItem('settings', JSON.stringify(settings));
|
||||
}, [settings]);
|
||||
|
||||
const [isFullscreen, setIsFullscreen] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
@@ -140,6 +171,11 @@ export const GlobalSettingsProvider = ({
|
||||
}
|
||||
};
|
||||
|
||||
const setPreStartCompletedAndLocalStorage = (preStartComplete: boolean) => {
|
||||
setPreStartCompleted(preStartComplete);
|
||||
localStorage.setItem('playing', String(playing));
|
||||
};
|
||||
|
||||
return {
|
||||
fullscreen: { isFullscreen, enableFullscreen, disableFullscreen },
|
||||
wakeLock: {
|
||||
@@ -153,23 +189,32 @@ export const GlobalSettingsProvider = ({
|
||||
goToStart,
|
||||
showPlay,
|
||||
setShowPlay,
|
||||
playing,
|
||||
setPlaying: setPlayingAndLocalStorage,
|
||||
initialGameSettings,
|
||||
setInitialGameSettings,
|
||||
settings,
|
||||
setSettings,
|
||||
setSettings: setSettingsAndLocalStorage,
|
||||
randomizingPlayer,
|
||||
setRandomizingPlayer,
|
||||
isPWA: window?.matchMedia('(display-mode: standalone)').matches,
|
||||
preStartCompleted,
|
||||
setPreStartCompleted: setPreStartCompletedAndLocalStorage,
|
||||
};
|
||||
}, [
|
||||
active,
|
||||
analytics,
|
||||
initialGameSettings,
|
||||
isFullscreen,
|
||||
isSupported,
|
||||
release,
|
||||
active,
|
||||
request,
|
||||
settings,
|
||||
showPlay,
|
||||
type,
|
||||
showPlay,
|
||||
playing,
|
||||
initialGameSettings,
|
||||
settings,
|
||||
randomizingPlayer,
|
||||
preStartCompleted,
|
||||
analytics,
|
||||
]);
|
||||
|
||||
return (
|
||||
|
||||
@@ -7,6 +7,17 @@ import { InitialGameSettings } from '../Types/Settings';
|
||||
export const PlayersProvider = ({ children }: { children: ReactNode }) => {
|
||||
const savedPlayers = localStorage.getItem('players');
|
||||
|
||||
const savedStartingPlayerIndex = localStorage.getItem('startingPlayerIndex');
|
||||
|
||||
const [startingPlayerIndex, setStartingPlayerIndex] = useState<number>(
|
||||
savedStartingPlayerIndex ? parseInt(savedStartingPlayerIndex) : -1
|
||||
);
|
||||
|
||||
const setStartingPlayerIndexAndLocalStorage = (index: number) => {
|
||||
setStartingPlayerIndex(index);
|
||||
localStorage.setItem('startingPlayerIndex', String(index));
|
||||
};
|
||||
|
||||
const [players, setPlayers] = useState<Player[]>(
|
||||
savedPlayers ? JSON.parse(savedPlayers) : []
|
||||
);
|
||||
@@ -50,9 +61,7 @@ export const PlayersProvider = ({ children }: { children: ReactNode }) => {
|
||||
return;
|
||||
}
|
||||
|
||||
const startingPlayerIndex = Math.floor(
|
||||
Math.random() * initialGameSettings.numberOfPlayers
|
||||
);
|
||||
const newStartingPlayerIndex = Math.floor(Math.random() * players.length);
|
||||
|
||||
players.forEach((player: Player) => {
|
||||
player.commanderDamage.map((damage) => {
|
||||
@@ -65,16 +74,9 @@ export const PlayersProvider = ({ children }: { children: ReactNode }) => {
|
||||
});
|
||||
|
||||
player.lifeTotal = initialGameSettings.startingLifeTotal;
|
||||
|
||||
player.hasLost = false;
|
||||
|
||||
const isStartingPlayer = player.index === startingPlayerIndex;
|
||||
|
||||
player.isStartingPlayer = isStartingPlayer;
|
||||
|
||||
if (player.isStartingPlayer) {
|
||||
player.showStartingPlayer = true;
|
||||
}
|
||||
player.isStartingPlayer = newStartingPlayerIndex === player.index;
|
||||
|
||||
updatePlayer(player);
|
||||
});
|
||||
@@ -87,8 +89,10 @@ export const PlayersProvider = ({ children }: { children: ReactNode }) => {
|
||||
updatePlayer,
|
||||
updateLifeTotal,
|
||||
resetCurrentGame,
|
||||
startingPlayerIndex,
|
||||
setStartingPlayerIndex: setStartingPlayerIndexAndLocalStorage,
|
||||
};
|
||||
}, [players]);
|
||||
}, [players, startingPlayerIndex]);
|
||||
|
||||
return (
|
||||
<PlayersContext.Provider value={ctxValue}>
|
||||
|
||||
@@ -6,7 +6,6 @@ export type Player = {
|
||||
commanderDamage: CommanderDamage[];
|
||||
extraCounters: ExtraCounter[];
|
||||
isStartingPlayer: boolean;
|
||||
showStartingPlayer: boolean;
|
||||
hasLost: boolean;
|
||||
isSide: boolean;
|
||||
};
|
||||
|
||||
@@ -12,11 +12,18 @@ export enum GameFormat {
|
||||
TwoHeadedGiant = 'two-headed-giant',
|
||||
}
|
||||
|
||||
export enum PreStartMode {
|
||||
None = 'none',
|
||||
RandomKing = 'random-king',
|
||||
FingerGame = 'finger-game',
|
||||
}
|
||||
|
||||
export type Settings = {
|
||||
keepAwake: boolean;
|
||||
showStartingPlayer: boolean;
|
||||
showPlayerMenuCog: boolean;
|
||||
goFullscreenOnStart: boolean;
|
||||
preStartMode: PreStartMode;
|
||||
};
|
||||
|
||||
export type InitialGameSettings = {
|
||||
@@ -27,10 +34,18 @@ export type InitialGameSettings = {
|
||||
orientation: Orientation;
|
||||
};
|
||||
|
||||
export const InitialGameSettingsSchema = z.object({
|
||||
export const initialGameSettingsSchema = z.object({
|
||||
startingLifeTotal: z.number().min(1).max(200).default(20),
|
||||
useCommanderDamage: z.boolean().default(false),
|
||||
gameFormat: z.nativeEnum(GameFormat).optional(),
|
||||
numberOfPlayers: z.number().min(1).max(6).default(2),
|
||||
orientation: z.nativeEnum(Orientation).default(Orientation.Landscape),
|
||||
});
|
||||
|
||||
export const settingsSchema = z.object({
|
||||
keepAwake: z.boolean().default(true),
|
||||
showStartingPlayer: z.boolean().default(true),
|
||||
showPlayerMenuCog: z.boolean().default(true),
|
||||
goFullscreenOnStart: z.boolean().default(true),
|
||||
preStartMode: z.nativeEnum(PreStartMode).default(PreStartMode.None),
|
||||
});
|
||||
|
||||
@@ -2,6 +2,81 @@
|
||||
import tailwindcssGridAreas from '@savvywombat/tailwindcss-grid-areas';
|
||||
import type { Config } from 'tailwindcss';
|
||||
|
||||
export const baseColors = {
|
||||
primary: {
|
||||
main: '#3E7D78',
|
||||
dark: '#2D5F5B',
|
||||
},
|
||||
secondary: {
|
||||
main: '#284F4C',
|
||||
dark: '#1B3B38',
|
||||
},
|
||||
background: {
|
||||
default: '#08253B',
|
||||
backdrop: 'rgba(0, 0, 0, 0.3)',
|
||||
settings: 'rgba(20, 20, 0, 0.9)',
|
||||
},
|
||||
icons: {
|
||||
dark: '#00000080',
|
||||
light: '#ffffff4f',
|
||||
},
|
||||
text: {
|
||||
primary: '#F5F5F5',
|
||||
secondary: '#76A6A5',
|
||||
},
|
||||
action: {
|
||||
disabled: '#234A47',
|
||||
},
|
||||
common: {
|
||||
white: '#F9FFE3',
|
||||
black: '#000000',
|
||||
},
|
||||
lifeCounter: {
|
||||
text: 'rgba(0, 0, 0, 0.4)',
|
||||
lostWrapper: '#000000',
|
||||
},
|
||||
interface: {
|
||||
loseButton: {
|
||||
background: '#43434380',
|
||||
},
|
||||
recentDifference: {
|
||||
background: 'rgba(255, 255, 255, 0.6);',
|
||||
text: '#333333',
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
export const twGridTemplateAreas = {
|
||||
onePlayerLandscape: ['player0 player0'],
|
||||
onePlayerPortrait: ['player0', 'player0'],
|
||||
twoPlayersOppositeLandscape: ['player0', 'player1'],
|
||||
twoPlayersOppositePortrait: ['player0 player1', 'player0 player1'],
|
||||
twoPlayersSameSideLandscape: ['player0 player1'],
|
||||
threePlayers: ['player0 player0', 'player1 player2'],
|
||||
threePlayersSide: [
|
||||
'player0 player0 player0 player2',
|
||||
'player1 player1 player1 player2',
|
||||
],
|
||||
fourPlayerPortrait: [
|
||||
'player0 player1 player1 player1 player1 player3',
|
||||
'player0 player2 player2 player2 player2 player3',
|
||||
],
|
||||
fourPlayer: ['player0 player1', 'player2 player3'],
|
||||
fivePlayers: [
|
||||
'player0 player0 player0 player1 player1 player1',
|
||||
'player2 player2 player3 player3 player4 player4',
|
||||
],
|
||||
fivePlayersSide: [
|
||||
'player0 player0 player0 player0 player0 player1 player1 player1 player1 player1 player2',
|
||||
'player3 player3 player3 player3 player3 player4 player4 player4 player4 player4 player2',
|
||||
],
|
||||
sixPlayers: ['player0 player1 player2', 'player3 player4 player5'],
|
||||
sixPlayersSide: [
|
||||
'player0 player1 player1 player1 player1 player1 player1 player2 player2 player2 player2 player2 player2 player3',
|
||||
'player0 player4 player4 player4 player4 player4 player4 player5 player5 player5 player5 player5 player5 player3',
|
||||
],
|
||||
};
|
||||
|
||||
/** @type {import('tailwindcss').Config} */
|
||||
export default {
|
||||
content: ['./index.html', './src/**/*.{js,ts,jsx,tsx}'],
|
||||
@@ -10,79 +85,8 @@ export default {
|
||||
modalSm: '548px',
|
||||
},
|
||||
extend: {
|
||||
gridTemplateAreas: {
|
||||
onePlayerLandscape: ['player0 player0'],
|
||||
onePlayerPortrait: ['player0', 'player0'],
|
||||
twoPlayersOppositeLandscape: ['player0', 'player1'],
|
||||
twoPlayersOppositePortrait: ['player0 player1', 'player0 player1'],
|
||||
twoPlayersSameSideLandscape: ['player0 player1'],
|
||||
threePlayers: ['player0 player0', 'player1 player2'],
|
||||
threePlayersSide: [
|
||||
'player0 player0 player0 player2',
|
||||
'player1 player1 player1 player2',
|
||||
],
|
||||
fourPlayerPortrait: [
|
||||
'player0 player1 player1 player1 player1 player3',
|
||||
'player0 player2 player2 player2 player2 player3',
|
||||
],
|
||||
fourPlayer: ['player0 player1', 'player2 player3'],
|
||||
fivePlayers: [
|
||||
'player0 player0 player0 player1 player1 player1',
|
||||
'player2 player2 player3 player3 player4 player4',
|
||||
],
|
||||
fivePlayersSide: [
|
||||
'player0 player0 player0 player0 player0 player1 player1 player1 player1 player1 player2',
|
||||
'player3 player3 player3 player3 player3 player4 player4 player4 player4 player4 player2',
|
||||
],
|
||||
sixPlayers: ['player0 player1 player2', 'player3 player4 player5'],
|
||||
sixPlayersSide: [
|
||||
'player0 player1 player1 player1 player1 player2 player2 player2 player2 player3',
|
||||
'player0 player4 player4 player4 player4 player5 player5 player5 player5 player3',
|
||||
],
|
||||
},
|
||||
colors: {
|
||||
primary: {
|
||||
main: '#3E7D78',
|
||||
dark: '#2D5F5B',
|
||||
},
|
||||
secondary: {
|
||||
main: '#284F4C',
|
||||
dark: '#1B3B38',
|
||||
},
|
||||
background: {
|
||||
default: '#08253B',
|
||||
backdrop: 'rgba(0, 0, 0, 0.3)',
|
||||
settings: 'rgba(20, 20, 0, 0.9)',
|
||||
},
|
||||
icons: {
|
||||
dark: '#00000080',
|
||||
light: '#ffffff4f',
|
||||
},
|
||||
text: {
|
||||
primary: '#F5F5F5',
|
||||
secondary: '#76A6A5',
|
||||
},
|
||||
action: {
|
||||
disabled: '#234A47',
|
||||
},
|
||||
common: {
|
||||
white: '#F9FFE3',
|
||||
black: '#000000',
|
||||
},
|
||||
lifeCounter: {
|
||||
text: 'rgba(0, 0, 0, 0.4)',
|
||||
lostWrapper: '#000000',
|
||||
},
|
||||
interface: {
|
||||
loseButton: {
|
||||
background: '#43434380',
|
||||
},
|
||||
recentDifference: {
|
||||
background: 'rgba(255, 255, 255, 0.6);',
|
||||
text: '#333333',
|
||||
},
|
||||
},
|
||||
},
|
||||
gridTemplateAreas: twGridTemplateAreas,
|
||||
colors: baseColors,
|
||||
keyframes: {
|
||||
fadeOut: {
|
||||
'0%': {
|
||||
|
||||
Reference in New Issue
Block a user