mirror of
https://github.com/Vikeo/LifeTrinket.git
synced 2025-11-11 13:46:21 +00:00
Compare commits
9 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
334b46db6e | ||
|
|
e03ecc6f51 | ||
|
|
d4dc44076d | ||
|
|
a1b5cfd871 | ||
|
|
f11eea5e53 | ||
|
|
905912a7fd | ||
|
|
a90dd7c9ea | ||
|
|
ef1310d674 | ||
|
|
fe3bb6c78c |
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "life-trinket",
|
||||
"private": true,
|
||||
"version": "0.6.6",
|
||||
"version": "0.6.8",
|
||||
"type": "commonjs",
|
||||
"engines": {
|
||||
"node": ">=18",
|
||||
|
||||
@@ -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,8 +1,9 @@
|
||||
import { useEffect, useState } from 'react';
|
||||
import { useEffect, useRef, useState } from 'react';
|
||||
import { useSwipeable } from 'react-swipeable';
|
||||
import { twc } from 'react-twc';
|
||||
import { useGlobalSettings } from '../../Hooks/useGlobalSettings';
|
||||
import { usePlayers } from '../../Hooks/usePlayers';
|
||||
import { Cog } from '../../Icons/generated';
|
||||
import { Player, Rotation } from '../../Types/Player';
|
||||
import {
|
||||
RotationButtonProps,
|
||||
@@ -11,9 +12,10 @@ import {
|
||||
import { LoseGameButton } from '../Buttons/LoseButton';
|
||||
import CommanderDamageBar from '../Counters/CommanderDamageBar';
|
||||
import ExtraCountersBar from '../Counters/ExtraCountersBar';
|
||||
import PlayerMenu from '../Player/PlayerMenu';
|
||||
import { Paragraph } from '../Misc/TextComponents';
|
||||
import PlayerMenu from '../Players/PlayerMenu';
|
||||
import Health from './Health';
|
||||
import { Cog } from '../../Icons/generated';
|
||||
import { baseColors } from '../../../tailwind.config';
|
||||
|
||||
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',
|
||||
@@ -49,8 +51,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
|
||||
@@ -90,13 +90,16 @@ 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, setPlaying, stopPlayerRandomization } =
|
||||
useGlobalSettings();
|
||||
const playingTimerRef = useRef<NodeJS.Timeout | undefined>(undefined);
|
||||
|
||||
const [showPlayerMenu, setShowPlayerMenu] = useState(false);
|
||||
const [recentDifference, setRecentDifference] = useState(0);
|
||||
@@ -113,12 +116,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);
|
||||
},
|
||||
|
||||
@@ -150,17 +151,26 @@ const LifeCounter = ({ player, opponents }: LifeCounterProps) => {
|
||||
}, [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);
|
||||
if (
|
||||
player.isStartingPlayer &&
|
||||
((!playing &&
|
||||
settings.useRandomStartingPlayerInterval &&
|
||||
stopPlayerRandomization) ||
|
||||
(!settings.useRandomStartingPlayerInterval && !playing))
|
||||
) {
|
||||
playingTimerRef.current = setTimeout(() => {
|
||||
setPlaying(true);
|
||||
}, 10_000);
|
||||
}
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [player.showStartingPlayer]);
|
||||
|
||||
return () => clearTimeout(playingTimerRef.current);
|
||||
}, [
|
||||
player.isStartingPlayer,
|
||||
playing,
|
||||
setPlaying,
|
||||
settings.useRandomStartingPlayerInterval,
|
||||
stopPlayerRandomization,
|
||||
]);
|
||||
|
||||
player.settings.rotation === Rotation.SideFlipped ||
|
||||
player.settings.rotation === Rotation.Side;
|
||||
@@ -195,25 +205,52 @@ const LifeCounter = ({ player, opponents }: LifeCounterProps) => {
|
||||
style={{ rotate: `${calcRotation}deg` }}
|
||||
{...handlers}
|
||||
>
|
||||
{settings.showStartingPlayer &&
|
||||
player.isStartingPlayer &&
|
||||
player.showStartingPlayer && (
|
||||
<StartingPlayerNoticeWrapper
|
||||
style={{ rotate: `${calcRotation}deg` }}
|
||||
{!playing && settings.showStartingPlayer && player.isStartingPlayer && (
|
||||
<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:
|
||||
stopPlayerRandomization ||
|
||||
!settings.useRandomStartingPlayerInterval
|
||||
? `radial-gradient(circle at center, ${player.color}, ${baseColors.primary.main})`
|
||||
: 'none',
|
||||
}}
|
||||
onClick={() => {
|
||||
clearTimeout(playingTimerRef.current);
|
||||
setPlaying(true);
|
||||
}}
|
||||
>
|
||||
<DynamicText
|
||||
style={{
|
||||
rotate: `${calcTextRotation}deg`,
|
||||
}}
|
||||
>
|
||||
<DynamicText
|
||||
style={{
|
||||
rotate: `${calcTextRotation}deg`,
|
||||
}}
|
||||
>
|
||||
You start!
|
||||
</DynamicText>
|
||||
</StartingPlayerNoticeWrapper>
|
||||
)}
|
||||
<div className="flex flex-col justify-center items-center">
|
||||
<Paragraph>👑</Paragraph>
|
||||
{(stopPlayerRandomization ||
|
||||
!settings.useRandomStartingPlayerInterval) && (
|
||||
<>
|
||||
<Paragraph>You start!</Paragraph>
|
||||
<Paragraph className="text-xl">(Press to hide)</Paragraph>
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
</DynamicText>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{player.hasLost && (
|
||||
<PlayerLostWrapper $rotation={player.settings.rotation} />
|
||||
)}
|
||||
{settings.useRandomStartingPlayerInterval &&
|
||||
!stopPlayerRandomization &&
|
||||
!playing && (
|
||||
<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 }}
|
||||
/>
|
||||
)}
|
||||
<CommanderDamageBar
|
||||
opponents={opponents}
|
||||
player={player}
|
||||
|
||||
@@ -121,6 +121,26 @@ export const SettingsModal = ({ isOpen, closeModal }: SettingsModalProps) => {
|
||||
this is enabled.
|
||||
</Description>
|
||||
</SettingContainer>
|
||||
<SettingContainer>
|
||||
<ToggleContainer>
|
||||
<FormLabel>Randomize starting player with interval</FormLabel>
|
||||
<Switch
|
||||
checked={settings.useRandomStartingPlayerInterval}
|
||||
onChange={() => {
|
||||
setSettings({
|
||||
...settings,
|
||||
useRandomStartingPlayerInterval:
|
||||
!settings.useRandomStartingPlayerInterval,
|
||||
});
|
||||
}}
|
||||
/>
|
||||
</ToggleContainer>
|
||||
<Description>
|
||||
Will randomize between all players at when starting a game,
|
||||
pressing the screen aborts the interval and chooses the player
|
||||
that has the crown.
|
||||
</Description>
|
||||
</SettingContainer>
|
||||
<SettingContainer>
|
||||
<ToggleContainer>
|
||||
<FormLabel>Keep Awake</FormLabel>
|
||||
|
||||
@@ -1,50 +0,0 @@
|
||||
import LifeCounter from '../LifeCounter/LifeCounter';
|
||||
import { Player as PlayerType } from '../../Types/Player';
|
||||
import { twc } from 'react-twc';
|
||||
|
||||
const getGridArea = (player: PlayerType) => {
|
||||
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');
|
||||
}
|
||||
};
|
||||
|
||||
const PlayerWrapper = twc.div`w-full h-full bg-black`;
|
||||
|
||||
export const Player = (players: PlayerType[], gridClasses: string) => {
|
||||
return (
|
||||
<PlayerWrapper>
|
||||
<div className={`grid w-full h-full gap-1 box-border ${gridClasses} `}>
|
||||
{players.map((player) => {
|
||||
const gridArea = getGridArea(player);
|
||||
|
||||
return (
|
||||
<div
|
||||
key={player.index}
|
||||
className={`flex justify-center items-center align-middle ${gridArea}`}
|
||||
>
|
||||
<LifeCounter
|
||||
player={player}
|
||||
opponents={players.filter(
|
||||
(opponent) => opponent.index !== player.index
|
||||
)}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
</PlayerWrapper>
|
||||
);
|
||||
};
|
||||
@@ -104,7 +104,14 @@ const PlayerMenu = ({
|
||||
containerRef: settingsContainerRef,
|
||||
});
|
||||
|
||||
const { fullscreen, wakeLock, goToStart, settings } = useGlobalSettings();
|
||||
const {
|
||||
fullscreen,
|
||||
wakeLock,
|
||||
goToStart,
|
||||
settings,
|
||||
setPlaying,
|
||||
setStopPlayerRandomization,
|
||||
} = useGlobalSettings();
|
||||
const { updatePlayer, resetCurrentGame } = usePlayers();
|
||||
|
||||
const handleColorChange = (event: React.ChangeEvent<HTMLInputElement>) => {
|
||||
@@ -122,6 +129,13 @@ const PlayerMenu = ({
|
||||
const handleResetGame = () => {
|
||||
resetCurrentGame();
|
||||
setShowPlayerMenu(false);
|
||||
setPlaying(false);
|
||||
setStopPlayerRandomization(false);
|
||||
};
|
||||
|
||||
const handleGoToStart = () => {
|
||||
goToStart();
|
||||
setStopPlayerRandomization(false);
|
||||
};
|
||||
|
||||
const toggleFullscreen = () => {
|
||||
@@ -291,7 +305,7 @@ const PlayerMenu = ({
|
||||
cursor: 'pointer',
|
||||
userSelect: 'none',
|
||||
}}
|
||||
onClick={goToStart}
|
||||
onClick={handleGoToStart}
|
||||
aria-label="Back to start"
|
||||
>
|
||||
<Exit size={iconSize} style={{ rotate: '180deg' }} />
|
||||
144
src/Components/Players/Players.tsx
Normal file
144
src/Components/Players/Players.tsx
Normal file
@@ -0,0 +1,144 @@
|
||||
import { useEffect, useRef } from 'react';
|
||||
import { twc } from 'react-twc';
|
||||
import { useGlobalSettings } from '../../Hooks/useGlobalSettings';
|
||||
import { usePlayers } from '../../Hooks/usePlayers';
|
||||
import { Player as PlayerType } from '../../Types/Player';
|
||||
import LifeCounter from '../LifeCounter/LifeCounter';
|
||||
|
||||
const getGridArea = (player: PlayerType) => {
|
||||
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');
|
||||
}
|
||||
};
|
||||
|
||||
const PlayersWrapper = twc.div`w-full h-full bg-black`;
|
||||
|
||||
export const Players = (players: PlayerType[], gridClasses: string) => {
|
||||
const randomIntervalRef = useRef<NodeJS.Timeout | null>(null);
|
||||
|
||||
const prevRandomIndexRef = useRef<number>(-1);
|
||||
|
||||
const {
|
||||
settings,
|
||||
stopPlayerRandomization,
|
||||
setStopPlayerRandomization,
|
||||
playing,
|
||||
} = useGlobalSettings();
|
||||
|
||||
const { setPlayers } = usePlayers();
|
||||
|
||||
useEffect(() => {
|
||||
if (
|
||||
settings.useRandomStartingPlayerInterval &&
|
||||
!stopPlayerRandomization &&
|
||||
!playing
|
||||
) {
|
||||
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);
|
||||
}
|
||||
|
||||
if (!settings.useRandomStartingPlayerInterval) {
|
||||
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,
|
||||
playing,
|
||||
setPlayers,
|
||||
settings.useRandomStartingPlayerInterval,
|
||||
stopPlayerRandomization,
|
||||
]);
|
||||
|
||||
return (
|
||||
<PlayersWrapper>
|
||||
{settings.useRandomStartingPlayerInterval &&
|
||||
!stopPlayerRandomization &&
|
||||
!playing && (
|
||||
<div
|
||||
className="absolute flex justify-center items-center bg-black bg-opacity-40 h-screen w-screen portrait:h-[100vw] portrait:w-[100vh] z-50 cursor-pointer text-5xl"
|
||||
onClick={() => {
|
||||
if (randomIntervalRef.current) {
|
||||
clearInterval(randomIntervalRef.current);
|
||||
randomIntervalRef.current = null;
|
||||
}
|
||||
setStopPlayerRandomization(true);
|
||||
}}
|
||||
>
|
||||
<div className="bg-primary-main px-8 py-2 rounded-2xl opacity-70 text-[5vmax]">
|
||||
PRESS TO SELECT PLAYER
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
<div className={`grid w-full h-full gap-1 box-border ${gridClasses} `}>
|
||||
{players.map((player) => {
|
||||
const gridArea = getGridArea(player);
|
||||
|
||||
return (
|
||||
<div
|
||||
key={player.index}
|
||||
className={`flex justify-center items-center align-middle ${gridArea}`}
|
||||
>
|
||||
<LifeCounter
|
||||
player={player}
|
||||
opponents={players.filter(
|
||||
(opponent) => opponent.index !== player.index
|
||||
)}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
</PlayersWrapper>
|
||||
);
|
||||
};
|
||||
@@ -1,7 +1,7 @@
|
||||
import { useGlobalSettings } from '../../Hooks/useGlobalSettings';
|
||||
import { usePlayers } from '../../Hooks/usePlayers';
|
||||
import { Orientation } from '../../Types/Settings';
|
||||
import { Player } from '../Player/Player';
|
||||
import { Players } from '../Players/Players';
|
||||
import { twc } from 'react-twc';
|
||||
|
||||
const MainWrapper = twc.div`w-[100dvmax] h-[100dvmin] overflow-hidden`;
|
||||
@@ -14,52 +14,52 @@ export const Play = () => {
|
||||
switch (players.length) {
|
||||
case 1:
|
||||
if (initialGameSettings?.orientation === Orientation.Portrait) {
|
||||
Layout = Player(players, 'grid-areas-onePlayerPortrait');
|
||||
Layout = Players(players, 'grid-areas-onePlayerPortrait');
|
||||
}
|
||||
Layout = Player(players, 'grid-areas-onePlayerLandscape');
|
||||
Layout = Players(players, 'grid-areas-onePlayerLandscape');
|
||||
break;
|
||||
case 2:
|
||||
switch (initialGameSettings?.orientation) {
|
||||
case Orientation.Portrait:
|
||||
Layout = Player(players, 'grid-areas-twoPlayersOppositePortrait');
|
||||
Layout = Players(players, 'grid-areas-twoPlayersOppositePortrait');
|
||||
break;
|
||||
default:
|
||||
case Orientation.Landscape:
|
||||
Layout = Player(players, 'grid-areas-twoPlayersSameSideLandscape');
|
||||
Layout = Players(players, 'grid-areas-twoPlayersSameSideLandscape');
|
||||
break;
|
||||
case Orientation.OppositeLandscape:
|
||||
Layout = Player(players, 'grid-areas-twoPlayersOppositeLandscape');
|
||||
Layout = Players(players, 'grid-areas-twoPlayersOppositeLandscape');
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case 3:
|
||||
if (initialGameSettings?.orientation === Orientation.Portrait) {
|
||||
Layout = Player(players, 'grid-areas-threePlayersSide');
|
||||
Layout = Players(players, 'grid-areas-threePlayersSide');
|
||||
break;
|
||||
}
|
||||
Layout = Player(players, 'grid-areas-threePlayers');
|
||||
Layout = Players(players, 'grid-areas-threePlayers');
|
||||
break;
|
||||
default:
|
||||
case 4:
|
||||
if (initialGameSettings?.orientation === Orientation.Portrait) {
|
||||
Layout = Player(players, 'grid-areas-fourPlayerPortrait');
|
||||
Layout = Players(players, 'grid-areas-fourPlayerPortrait');
|
||||
break;
|
||||
}
|
||||
Layout = Player(players, 'grid-areas-fourPlayer');
|
||||
Layout = Players(players, 'grid-areas-fourPlayer');
|
||||
break;
|
||||
case 5:
|
||||
if (initialGameSettings?.orientation === Orientation.Portrait) {
|
||||
Layout = Player(players, 'grid-areas-fivePlayersSide');
|
||||
Layout = Players(players, 'grid-areas-fivePlayersSide');
|
||||
break;
|
||||
}
|
||||
Layout = Player(players, 'grid-areas-fivePlayers');
|
||||
Layout = Players(players, 'grid-areas-fivePlayers');
|
||||
break;
|
||||
case 6:
|
||||
if (initialGameSettings?.orientation === Orientation.Portrait) {
|
||||
Layout = Player(players, 'grid-areas-sixPlayersSide');
|
||||
Layout = Players(players, 'grid-areas-sixPlayersSide');
|
||||
break;
|
||||
}
|
||||
Layout = Player(players, 'grid-areas-sixPlayers');
|
||||
Layout = Players(players, 'grid-areas-sixPlayers');
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
@@ -22,6 +22,10 @@ export type GlobalSettingsContextType = {
|
||||
setInitialGameSettings: (initialGameSettings: InitialGameSettings) => void;
|
||||
settings: Settings;
|
||||
setSettings: (settings: Settings) => void;
|
||||
playing: boolean;
|
||||
setPlaying: (playing: boolean) => void;
|
||||
stopPlayerRandomization: boolean;
|
||||
setStopPlayerRandomization: (stopRandom: boolean) => void;
|
||||
isPWA: boolean;
|
||||
};
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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,
|
||||
};
|
||||
|
||||
|
||||
@@ -21,11 +21,23 @@ export const GlobalSettingsProvider = ({
|
||||
const savedShowPlay = localStorage.getItem('showPlay');
|
||||
const savedGameSettings = localStorage.getItem('initialGameSettings');
|
||||
const savedSettings = localStorage.getItem('settings');
|
||||
const savedPlaying = localStorage.getItem('playing');
|
||||
|
||||
const [playing, setPlaying] = useState<boolean>(
|
||||
savedPlaying ? savedPlaying === 'true' : false
|
||||
);
|
||||
const setPlayingAndLocalStorage = (playing: boolean) => {
|
||||
setPlaying(playing);
|
||||
localStorage.setItem('playing', String(playing));
|
||||
};
|
||||
|
||||
const [showPlay, setShowPlay] = useState<boolean>(
|
||||
savedShowPlay ? savedShowPlay === 'true' : false
|
||||
);
|
||||
|
||||
const [stopPlayerRandomization, setStopPlayerRandomization] =
|
||||
useState<boolean>(false);
|
||||
|
||||
const [initialGameSettings, setInitialGameSettings] =
|
||||
useState<InitialGameSettings | null>(
|
||||
savedGameSettings ? JSON.parse(savedGameSettings) : null
|
||||
@@ -39,6 +51,7 @@ export const GlobalSettingsProvider = ({
|
||||
keepAwake: true,
|
||||
showStartingPlayer: true,
|
||||
showPlayerMenuCog: true,
|
||||
useRandomStartingPlayerInterval: false,
|
||||
}
|
||||
);
|
||||
|
||||
@@ -47,6 +60,8 @@ export const GlobalSettingsProvider = ({
|
||||
localStorage.removeItem('players');
|
||||
localStorage.removeItem('playing');
|
||||
localStorage.removeItem('showPlay');
|
||||
|
||||
setPlaying(false);
|
||||
setShowPlay(false);
|
||||
};
|
||||
|
||||
@@ -153,10 +168,14 @@ export const GlobalSettingsProvider = ({
|
||||
goToStart,
|
||||
showPlay,
|
||||
setShowPlay,
|
||||
playing,
|
||||
setPlaying: setPlayingAndLocalStorage,
|
||||
initialGameSettings,
|
||||
setInitialGameSettings,
|
||||
settings,
|
||||
setSettings,
|
||||
stopPlayerRandomization,
|
||||
setStopPlayerRandomization,
|
||||
isPWA: window?.matchMedia('(display-mode: standalone)').matches,
|
||||
};
|
||||
}, [
|
||||
@@ -165,10 +184,12 @@ export const GlobalSettingsProvider = ({
|
||||
initialGameSettings,
|
||||
isFullscreen,
|
||||
isSupported,
|
||||
playing,
|
||||
release,
|
||||
request,
|
||||
settings,
|
||||
showPlay,
|
||||
stopPlayerRandomization,
|
||||
type,
|
||||
]);
|
||||
|
||||
|
||||
@@ -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;
|
||||
};
|
||||
|
||||
@@ -17,6 +17,7 @@ export type Settings = {
|
||||
showStartingPlayer: boolean;
|
||||
showPlayerMenuCog: boolean;
|
||||
goFullscreenOnStart: boolean;
|
||||
useRandomStartingPlayerInterval: boolean;
|
||||
};
|
||||
|
||||
export type InitialGameSettings = {
|
||||
|
||||
@@ -2,6 +2,50 @@
|
||||
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',
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
/** @type {import('tailwindcss').Config} */
|
||||
export default {
|
||||
content: ['./index.html', './src/**/*.{js,ts,jsx,tsx}'],
|
||||
@@ -40,49 +84,7 @@ export default {
|
||||
'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',
|
||||
},
|
||||
},
|
||||
},
|
||||
colors: baseColors,
|
||||
keyframes: {
|
||||
fadeOut: {
|
||||
'0%': {
|
||||
|
||||
Reference in New Issue
Block a user