mirror of
https://github.com/Vikeo/LifeTrinket.git
synced 2025-11-17 08:18:00 +00:00
show starting player on first load
This commit is contained in:
@@ -79,6 +79,7 @@ const App = () => {
|
|||||||
|
|
||||||
const newGame = () => {
|
const newGame = () => {
|
||||||
localStorage.removeItem('players');
|
localStorage.removeItem('players');
|
||||||
|
localStorage.removeItem('playing');
|
||||||
localStorage.removeItem('initialGameSettings');
|
localStorage.removeItem('initialGameSettings');
|
||||||
|
|
||||||
window.location.reload();
|
window.location.reload();
|
||||||
|
|||||||
@@ -78,6 +78,37 @@ const LifeCountainer = styled.div<{
|
|||||||
}}
|
}}
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
const StartingPlayer = styled.div<{
|
||||||
|
rotation: Rotation;
|
||||||
|
}>`
|
||||||
|
z-index: 1;
|
||||||
|
display: flex;
|
||||||
|
position: absolute;
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
justify-content: center;
|
||||||
|
align-items: center;
|
||||||
|
font-size: 8vmin;
|
||||||
|
background: turquoise;
|
||||||
|
pointer-events: none;
|
||||||
|
-webkit-touch-callout: none;
|
||||||
|
-webkit-tap-highlight-color: transparent;
|
||||||
|
user-select: none;
|
||||||
|
-moz-user-select: -moz-none;
|
||||||
|
-webkit-user-select: none;
|
||||||
|
-ms-user-select: none;
|
||||||
|
${(props) => {
|
||||||
|
if (
|
||||||
|
props.rotation === Rotation.SideFlipped ||
|
||||||
|
props.rotation === Rotation.Side
|
||||||
|
) {
|
||||||
|
return css`
|
||||||
|
flex-direction: column-reverse;
|
||||||
|
`;
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
`;
|
||||||
|
|
||||||
const LifeCounterTextContainer = styled.p<{
|
const LifeCounterTextContainer = styled.p<{
|
||||||
rotation: Rotation;
|
rotation: Rotation;
|
||||||
}>`
|
}>`
|
||||||
@@ -155,16 +186,30 @@ const LifeCounter = ({
|
|||||||
|
|
||||||
const [showPlayerMenu, setShowPlayerMenu] = useState(false);
|
const [showPlayerMenu, setShowPlayerMenu] = useState(false);
|
||||||
const [recentDifference, setRecentDifference] = useState(0);
|
const [recentDifference, setRecentDifference] = useState(0);
|
||||||
|
const [showStartingPlayer, setShowStartingPlayer] = useState(
|
||||||
|
localStorage.getItem('playing') === 'true'
|
||||||
|
);
|
||||||
const [key, setKey] = useState(Date.now());
|
const [key, setKey] = useState(Date.now());
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const timer = setTimeout(() => {
|
const timer = setTimeout(() => {
|
||||||
setRecentDifference(0);
|
setRecentDifference(0);
|
||||||
}, 3000);
|
}, 3_000);
|
||||||
|
|
||||||
return () => clearTimeout(timer);
|
return () => clearTimeout(timer);
|
||||||
}, [recentDifference]);
|
}, [recentDifference]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (!showStartingPlayer) {
|
||||||
|
const playingTimer = setTimeout(() => {
|
||||||
|
localStorage.setItem('playing', 'true');
|
||||||
|
setShowStartingPlayer(localStorage.getItem('playing') === 'true');
|
||||||
|
}, 3_000);
|
||||||
|
|
||||||
|
return () => clearTimeout(playingTimer);
|
||||||
|
}
|
||||||
|
}, [showStartingPlayer]);
|
||||||
|
|
||||||
const size = 30;
|
const size = 30;
|
||||||
const fontSize = `${size}vmin`;
|
const fontSize = `${size}vmin`;
|
||||||
const strokeWidth = `${size / 20}vmin`;
|
const strokeWidth = `${size / 20}vmin`;
|
||||||
@@ -172,6 +217,12 @@ const LifeCounter = ({
|
|||||||
return (
|
return (
|
||||||
<LifeCounterContentWrapper backgroundColor={backgroundColor}>
|
<LifeCounterContentWrapper backgroundColor={backgroundColor}>
|
||||||
<LifeCounterWrapper rotation={player.settings.rotation}>
|
<LifeCounterWrapper rotation={player.settings.rotation}>
|
||||||
|
{player.isStartingPlayer && !showStartingPlayer && (
|
||||||
|
<StartingPlayer rotation={player.settings.rotation}>
|
||||||
|
You start!
|
||||||
|
</StartingPlayer>
|
||||||
|
)}
|
||||||
|
|
||||||
<CommanderDamageBar
|
<CommanderDamageBar
|
||||||
opponents={opponents}
|
opponents={opponents}
|
||||||
player={player}
|
player={player}
|
||||||
|
|||||||
@@ -152,6 +152,7 @@ const Settings = ({ player, onChange, resetCurrentGame }: SettingsProps) => {
|
|||||||
|
|
||||||
const handleNewGame = () => {
|
const handleNewGame = () => {
|
||||||
localStorage.removeItem('players');
|
localStorage.removeItem('players');
|
||||||
|
localStorage.removeItem('playing');
|
||||||
localStorage.removeItem('initialGameSettings');
|
localStorage.removeItem('initialGameSettings');
|
||||||
|
|
||||||
window.location.reload();
|
window.location.reload();
|
||||||
|
|||||||
@@ -200,8 +200,10 @@ export const createInitialPlayers = ({
|
|||||||
}: InitialSettings): Player[] => {
|
}: InitialSettings): Player[] => {
|
||||||
const players: Player[] = [];
|
const players: Player[] = [];
|
||||||
const availableColors = [...presetColors]; // Create a copy of the colors array
|
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++) {
|
for (let i = 0; i <= numberOfPlayers - 1; i++) {
|
||||||
|
const isStartingPlayer = i === firstPlayerIndex;
|
||||||
const colorIndex = Math.floor(Math.random() * availableColors.length);
|
const colorIndex = Math.floor(Math.random() * availableColors.length);
|
||||||
const color = availableColors[colorIndex];
|
const color = availableColors[colorIndex];
|
||||||
|
|
||||||
@@ -231,7 +233,7 @@ export const createInitialPlayers = ({
|
|||||||
usePoison: false,
|
usePoison: false,
|
||||||
rotation,
|
rotation,
|
||||||
},
|
},
|
||||||
|
isStartingPlayer: isStartingPlayer,
|
||||||
extraCounters: [],
|
extraCounters: [],
|
||||||
commanderDamage,
|
commanderDamage,
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ export type Player = {
|
|||||||
settings: PlayerSettings;
|
settings: PlayerSettings;
|
||||||
commanderDamage: CommanderDamage[];
|
commanderDamage: CommanderDamage[];
|
||||||
extraCounters: ExtraCounter[];
|
extraCounters: ExtraCounter[];
|
||||||
|
isStartingPlayer: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type PlayerSettings = {
|
export type PlayerSettings = {
|
||||||
|
|||||||
Reference in New Issue
Block a user