mirror of
https://github.com/Vikeo/LifeTrinket.git
synced 2025-11-11 21:56:25 +00:00
Compare commits
140 Commits
tailwind-w
...
0.9.4
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ed10edc6d2 | ||
|
|
7696b357b4 | ||
|
|
a7b78b8e7a | ||
|
|
fa95d171b7 | ||
|
|
00a556be0e | ||
|
|
3276dc81fc | ||
|
|
28c2ff536f | ||
|
|
6beddf06e2 | ||
|
|
2a885f9a43 | ||
|
|
9c27f34261 | ||
|
|
fa5829b402 | ||
|
|
71f26d0dc5 | ||
|
|
3a568fc3ab | ||
|
|
355f4bd4cd | ||
|
|
17e174bfe1 | ||
|
|
e1e8da858b | ||
|
|
e02f071415 | ||
|
|
e04f31bb67 | ||
|
|
e5386d08a4 | ||
|
|
d6cd678e9f | ||
|
|
334b46db6e | ||
|
|
e03ecc6f51 | ||
|
|
d4dc44076d | ||
|
|
a1b5cfd871 | ||
|
|
f11eea5e53 | ||
|
|
905912a7fd | ||
|
|
a90dd7c9ea | ||
|
|
ef1310d674 | ||
|
|
fe3bb6c78c | ||
|
|
6d2b3b6a6f | ||
|
|
0f86928cb3 | ||
|
|
efbfb7719c | ||
|
|
71e5614f52 | ||
|
|
677fd79bee | ||
|
|
1bff41bc10 | ||
|
|
7852520f8e | ||
|
|
04c3d60967 | ||
|
|
664e2e5688 | ||
|
|
6eb7ac9f50 | ||
|
|
ef06e0d125 | ||
|
|
ae9f5707b2 | ||
|
|
a18c253624 | ||
|
|
3f319c4f3c | ||
|
|
8b33a2a38a | ||
|
|
cc915dff36 | ||
|
|
db80e563f2 | ||
|
|
573af42b75 | ||
|
|
89e1eaff4e | ||
|
|
0f4e896342 | ||
|
|
dc1d5fe01d | ||
|
|
41e73d2c0c | ||
|
|
724dcf086c | ||
|
|
51f9c4d20e | ||
|
|
354c0dbbb2 | ||
|
|
3770d13beb | ||
|
|
13733242a2 | ||
|
|
81f3891b20 | ||
|
|
e153de9093 | ||
|
|
07775f85d2 | ||
|
|
10039175a1 | ||
|
|
bcf2a0a840 | ||
|
|
d25da5d97b | ||
|
|
f5a80e573e | ||
|
|
1f36264e39 | ||
|
|
d615cfd3ba | ||
|
|
4453b12ce6 | ||
|
|
d601a820f8 | ||
|
|
0455f43794 | ||
|
|
f94103fe51 | ||
|
|
c36668b933 | ||
|
|
f9d0346300 | ||
|
|
2f3ee74c74 | ||
|
|
f8f0788b97 | ||
|
|
bfe25eacb7 | ||
|
|
7b0965c0dd | ||
|
|
e55ea6a83a | ||
|
|
481196de9b | ||
|
|
a136dbd3f9 | ||
|
|
8d23349dac | ||
|
|
a7caa46156 | ||
|
|
39cd3faae2 | ||
|
|
bdaa8e602f | ||
|
|
26490103a9 | ||
|
|
56b07784d5 | ||
|
|
4544c689a5 | ||
|
|
8a7a4b4127 | ||
|
|
391e654779 | ||
|
|
f79a0d3e7e | ||
|
|
0664e340a0 | ||
|
|
dcb98aeac6 | ||
|
|
89b62ddac4 | ||
|
|
c704e3c7f4 | ||
|
|
69a71e2d6e | ||
|
|
18945204bf | ||
|
|
495e731636 | ||
|
|
67b231f0d4 | ||
|
|
9d42fb1635 | ||
|
|
38ad046344 | ||
|
|
bc87f073af | ||
|
|
da46c25944 | ||
|
|
104f54f5b7 | ||
|
|
101a055694 | ||
|
|
38e4cb8e8c | ||
|
|
4ecb83060d | ||
|
|
4f231ba6f4 | ||
|
|
3cd982c643 | ||
|
|
1013914cdf | ||
|
|
db85fc2102 | ||
|
|
2b0d8102d8 | ||
|
|
35e0224066 | ||
|
|
1fa433a38f | ||
|
|
26821273d7 | ||
|
|
7f19214624 | ||
|
|
8b2cd43a96 | ||
|
|
23e18f8f41 | ||
|
|
23b844c47e | ||
|
|
6ade1998f6 | ||
|
|
cc98a1b84a | ||
|
|
2ca6b91d09 | ||
|
|
00bda4fb68 | ||
|
|
d09d992535 | ||
|
|
e96e4f3aa9 | ||
|
|
cb132360a9 | ||
|
|
66b0892461 | ||
|
|
fdab09d598 | ||
|
|
ec030e7076 | ||
|
|
9812c6737c | ||
|
|
e8528f46ae | ||
|
|
4ff7f67484 | ||
|
|
bc97e459cd | ||
|
|
866dca8e41 | ||
|
|
5859bb5a49 | ||
|
|
20fb2153b3 | ||
|
|
75038212c5 | ||
|
|
b712fb6e03 | ||
|
|
3d27335fd0 | ||
|
|
18b53669d2 | ||
|
|
28954eb948 | ||
|
|
3c59d5d05b | ||
|
|
22b58c74d6 |
@@ -1,8 +1,12 @@
|
|||||||
robots.txt,1693082171694,391d14b3c2f8c9143a27a28c7399585142228d4d1bdbe2c87ac946de411fa9a2
|
index.html,1711189442688,fa2549e32940c356ac5cee88c8db61076ad62fb4e599858c8e45cfc68cd901c4
|
||||||
manifest.json,1693082171694,91ce94afb71f33a477f5d8d48c3f98bd7de422279c74f17b6500eec72003ac1a
|
manifest.json,1711189442512,7ff5111aa04a42adff3b38924ec467b6f345ed0309dba1486dc9b783b60c2a9d
|
||||||
assets/index-5265c558.css,1693082171837,08c4451946bbdf520fe337edb365417a8bbf91914c018b83866723ef52d57b43
|
registerSW.js,1711189442688,5b6445b5215737c53ef0d379c151d57de165a056de2d1c5812ed614f158ebcbd
|
||||||
index.html,1693082171837,09e1919fbaaa3a0bf08f43eb46c29136d62a7747b41f8b5d0f4a7ed23337c344
|
sw.js,1711189443521,9c09d33ea573bb818864bfad526fa911839637171773eca8e31905458679846d
|
||||||
logo192.png,1693082171693,4309255bccbdbb341b5ab88708677e3d43b9e171d2666528ff932295a8257e4e
|
robots.txt,1711189442512,391d14b3c2f8c9143a27a28c7399585142228d4d1bdbe2c87ac946de411fa9a2
|
||||||
favicon.ico,1693082171692,48d8c1b9714dbc9bcb012d9c9f04112d229f20e6c889bda588ac159f973e6a8d
|
manifest.webmanifest,1711189442688,f2bf253209f6e292a6b0dbfa06fb4ac188eb5f2dba568c3ad5511b9ed52c1f51
|
||||||
logo512.png,1693082171694,92c7c05dc98170596d04f48e5e60eaae9535f409bcaeff129fd98fef8aba9f4e
|
workbox-3e911b1d.js,1711189443521,d5dbc868a5c07af633d29de7ba3ffe37542aaaabdf33713b4298df31f92f11ff
|
||||||
assets/index-5023e89e.js,1693082171838,8a6177168e95e1ca90e5ad8774252a8a02a9a78765bd329b7deae729c01aedf3
|
assets/index-WLCHZTqE.css,1711189442688,877e5ea9bfd3a1ca0e6449e8213da8a3c7717e530370f12669bb5c70dd21e700
|
||||||
|
favicon.ico,1711189442511,8cefe5adbf00d337d8633fb744b9f2c4914f769b319be4bb7e184b7a4aa17160
|
||||||
|
logo192.png,1711189442511,3d1e2e6f064d4fd325828f21bb6493ff0dbf2390b0e7d2aba9f2b6def4829799
|
||||||
|
logo512.png,1711189442511,892a4da1cc5434929a83a71fcbcb0d0d80aa82f44e3c21e9b20ffe9267197133
|
||||||
|
assets/index-OHs0lOr7.js,1711189442688,aa0dca732cd5b6f621ecb7c6dbcbfdbccde78941cfad954f6626d4ff83040c7f
|
||||||
|
|||||||
20
.github/workflows/firebase-hosting-mege.yml
vendored
20
.github/workflows/firebase-hosting-mege.yml
vendored
@@ -1,20 +0,0 @@
|
|||||||
# This file was auto-generated by the Firebase CLI
|
|
||||||
# https://github.com/firebase/firebase-tools
|
|
||||||
name: Deploy to Firebase Hosting on merge
|
|
||||||
'on':
|
|
||||||
push:
|
|
||||||
branches:
|
|
||||||
- main
|
|
||||||
jobs:
|
|
||||||
build_and_deploy:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v3
|
|
||||||
- uses: oven-sh/setup-bun@v1
|
|
||||||
- run: bun install && bun run build && bun run lint
|
|
||||||
- uses: FirebaseExtended/action-hosting-deploy@v0
|
|
||||||
with:
|
|
||||||
repoToken: '${{ secrets.GITHUB_TOKEN }}'
|
|
||||||
firebaseServiceAccount: '${{ secrets.FIREBASE_SERVICE_ACCOUNT_LIFE_TRINKET }}'
|
|
||||||
channelId: live
|
|
||||||
projectId: life-trinket
|
|
||||||
58
.github/workflows/firebase-release.yml
vendored
Normal file
58
.github/workflows/firebase-release.yml
vendored
Normal file
@@ -0,0 +1,58 @@
|
|||||||
|
name: Deploy to Firebase Hosting
|
||||||
|
'on':
|
||||||
|
push:
|
||||||
|
tags:
|
||||||
|
- '*'
|
||||||
|
jobs:
|
||||||
|
build_and_deploy:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
env:
|
||||||
|
VITE_REPO_READ_ACCESS_TOKEN: ${{ secrets.REPO_READ_ACCESS_TOKEN }}
|
||||||
|
steps:
|
||||||
|
- name: Checkout repository
|
||||||
|
uses: actions/checkout@v3
|
||||||
|
|
||||||
|
- name: Setup bun
|
||||||
|
uses: oven-sh/setup-bun@v1
|
||||||
|
|
||||||
|
- name: Build, lint, and deploy
|
||||||
|
run: |
|
||||||
|
bun install
|
||||||
|
bun run build
|
||||||
|
bun run lint
|
||||||
|
- name: Deploy to Firebase Hosting
|
||||||
|
uses: FirebaseExtended/action-hosting-deploy@v0
|
||||||
|
with:
|
||||||
|
repoToken: '${{ secrets.GITHUB_TOKEN }}'
|
||||||
|
firebaseServiceAccount: '${{ secrets.FIREBASE_SERVICE_ACCOUNT_LIFE_TRINKET }}'
|
||||||
|
channelId: live
|
||||||
|
projectId: life-trinket
|
||||||
|
|
||||||
|
release:
|
||||||
|
needs: build_and_deploy
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
env:
|
||||||
|
working-directory: ${{ github.workspace }}
|
||||||
|
steps:
|
||||||
|
- name: Checkout repository
|
||||||
|
uses: actions/checkout@v3
|
||||||
|
|
||||||
|
- name: get version
|
||||||
|
id: version
|
||||||
|
uses: notiz-dev/github-action-json-property@v0.2.0
|
||||||
|
|
||||||
|
with:
|
||||||
|
path: 'package.json'
|
||||||
|
prop_path: 'version'
|
||||||
|
|
||||||
|
- name: Create Release Note
|
||||||
|
id: create_release_note
|
||||||
|
run: echo "Release Note for version ${{ steps.version.outputs.prop }}" > release_note.txt
|
||||||
|
|
||||||
|
- name: Create Release
|
||||||
|
uses: ncipollo/release-action@v1.13.0
|
||||||
|
with:
|
||||||
|
bodyFile: release_note.txt
|
||||||
|
commit: ${{ github.sha }}
|
||||||
|
tag: '${{ steps.version.outputs.prop }}'
|
||||||
|
token: ${{ secrets.RELEASE_TOKEN }}
|
||||||
12
CHANGELOG.md
Normal file
12
CHANGELOG.md
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
# Changelog
|
||||||
|
|
||||||
|
All notable changes to this project will be documented in this file.
|
||||||
|
|
||||||
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
||||||
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
||||||
|
|
||||||
|
## [0.5.0] - 2024-01-13
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
|
||||||
|
- Styling with Tailwind CSS instead of styled-components
|
||||||
18
package.json
18
package.json
@@ -1,11 +1,12 @@
|
|||||||
{
|
{
|
||||||
"name": "life-trinket",
|
"name": "life-trinket",
|
||||||
"private": true,
|
"private": true,
|
||||||
"version": "0.4.0",
|
"version": "0.9.4",
|
||||||
"type": "commonjs",
|
"type": "commonjs",
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=18",
|
"node": ">=18",
|
||||||
"npm": "please use bun or yarn :) "
|
"yarn": "use pnpm",
|
||||||
|
"npm": "please use pnpm"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "vite",
|
"dev": "vite",
|
||||||
@@ -13,7 +14,7 @@
|
|||||||
"lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
|
"lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
|
||||||
"preview": "vite preview",
|
"preview": "vite preview",
|
||||||
"generate-icons": "npx @svgr/cli src/Icons/svgs",
|
"generate-icons": "npx @svgr/cli src/Icons/svgs",
|
||||||
"deploy": "bun build && firebase deploy --only hosting"
|
"deploy": "bun run build && firebase deploy --only hosting"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@mui/material": "^5.13.6",
|
"@mui/material": "^5.13.6",
|
||||||
@@ -22,7 +23,9 @@
|
|||||||
"react": "^18.2.0",
|
"react": "^18.2.0",
|
||||||
"react-dom": "^18.2.0",
|
"react-dom": "^18.2.0",
|
||||||
"react-screen-wake-lock": "^3.0.2",
|
"react-screen-wake-lock": "^3.0.2",
|
||||||
"styled-components": "^6.0.7"
|
"react-swipeable": "^7.0.1",
|
||||||
|
"react-twc": "^1.3.0",
|
||||||
|
"zod": "^3.22.4"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@emotion/react": "^11.11.1",
|
"@emotion/react": "^11.11.1",
|
||||||
@@ -42,8 +45,9 @@
|
|||||||
"install": "^0.13.0",
|
"install": "^0.13.0",
|
||||||
"postcss": "^8.4.32",
|
"postcss": "^8.4.32",
|
||||||
"prettier": "2.8.8",
|
"prettier": "2.8.8",
|
||||||
"tailwindcss": "^3.4.0",
|
"tailwindcss": "^3.4.1",
|
||||||
"typescript": "^5.0.2",
|
"typescript": "^5.3.3",
|
||||||
"vite": "^4.4.5"
|
"vite": "^5.0.12",
|
||||||
|
"vite-plugin-pwa": "^0.17.4"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
9603
pnpm-lock.yaml
generated
Normal file
9603
pnpm-lock.yaml
generated
Normal file
File diff suppressed because it is too large
Load Diff
12
src/App.tsx
12
src/App.tsx
@@ -1,24 +1,12 @@
|
|||||||
import { createGlobalStyle } from 'styled-components';
|
|
||||||
import { ThemeProvider } from '@mui/material';
|
import { ThemeProvider } from '@mui/material';
|
||||||
import { LifeTrinket } from './Components/LifeTrinket';
|
import { LifeTrinket } from './Components/LifeTrinket';
|
||||||
import { theme } from './Data/theme';
|
import { theme } from './Data/theme';
|
||||||
import { GlobalSettingsProvider } from './Providers/GlobalSettingsProvider';
|
import { GlobalSettingsProvider } from './Providers/GlobalSettingsProvider';
|
||||||
import { PlayersProvider } from './Providers/PlayersProvider';
|
import { PlayersProvider } from './Providers/PlayersProvider';
|
||||||
|
|
||||||
const GlobalStyles = createGlobalStyle`
|
|
||||||
html,
|
|
||||||
body {
|
|
||||||
background-color: ${theme.palette.background.default};
|
|
||||||
}
|
|
||||||
#root {
|
|
||||||
touch-action: manipulation;
|
|
||||||
}
|
|
||||||
`;
|
|
||||||
|
|
||||||
const App = () => {
|
const App = () => {
|
||||||
return (
|
return (
|
||||||
<ThemeProvider theme={theme}>
|
<ThemeProvider theme={theme}>
|
||||||
<GlobalStyles />
|
|
||||||
<PlayersProvider>
|
<PlayersProvider>
|
||||||
<GlobalSettingsProvider>
|
<GlobalSettingsProvider>
|
||||||
<LifeTrinket />
|
<LifeTrinket />
|
||||||
|
|||||||
@@ -1,110 +1,51 @@
|
|||||||
import styled from 'styled-components';
|
|
||||||
import { css } from 'styled-components';
|
|
||||||
import { Player, Rotation } from '../../Types/Player';
|
|
||||||
import { useRef, useState } from 'react';
|
import { useRef, useState } from 'react';
|
||||||
import { OutlinedText } from '../Misc/OutlinedText';
|
import { TwcComponentProps, twc } from 'react-twc';
|
||||||
import { decrementTimeoutMs } from '../../Data/constants';
|
import { decrementTimeoutMs } from '../../Data/constants';
|
||||||
import { usePlayers } from '../../Hooks/usePlayers';
|
import { usePlayers } from '../../Hooks/usePlayers';
|
||||||
|
import { Player, Rotation } from '../../Types/Player';
|
||||||
|
import { OutlinedText } from '../Misc/OutlinedText';
|
||||||
|
|
||||||
const CommanderDamageContainer = styled.div<{
|
export type RotationDivProps = TwcComponentProps<'div'> & {
|
||||||
$rotation: number;
|
$rotation?: number;
|
||||||
}>`
|
};
|
||||||
display: flex;
|
|
||||||
flex-direction: row;
|
|
||||||
flex-grow: 1;
|
|
||||||
width: 100%;
|
|
||||||
|
|
||||||
${(props) => {
|
export type RotationSpanProps = TwcComponentProps<'span'> & {
|
||||||
if (
|
$rotation?: number;
|
||||||
props.$rotation === Rotation.SideFlipped ||
|
};
|
||||||
props.$rotation === Rotation.Side
|
|
||||||
) {
|
|
||||||
return css`
|
|
||||||
flex-direction: column;
|
|
||||||
`;
|
|
||||||
}
|
|
||||||
}}
|
|
||||||
`;
|
|
||||||
|
|
||||||
const CommanderDamageButton = styled.button<{
|
export type RotationButtonProps = TwcComponentProps<'button'> & {
|
||||||
$backgroundColor?: string;
|
$rotation?: number;
|
||||||
$rotation: number;
|
};
|
||||||
}>`
|
|
||||||
display: flex;
|
|
||||||
flex-grow: 1;
|
|
||||||
border: none;
|
|
||||||
height: 10vmin;
|
|
||||||
width: 50%;
|
|
||||||
outline: none;
|
|
||||||
cursor: pointer;
|
|
||||||
background-color: ${(props) => props.$backgroundColor || 'antiquewhite'};
|
|
||||||
margin: 0;
|
|
||||||
user-select: none;
|
|
||||||
-webkit-touch-callout: none;
|
|
||||||
-webkit-tap-highlight-color: transparent;
|
|
||||||
-moz-user-select: -moz-none;
|
|
||||||
-webkit-user-select: none;
|
|
||||||
-ms-user-select: none;
|
|
||||||
padding: 0;
|
|
||||||
${(props) => {
|
|
||||||
if (
|
|
||||||
props.$rotation === Rotation.SideFlipped ||
|
|
||||||
props.$rotation === Rotation.Side
|
|
||||||
) {
|
|
||||||
return css`
|
|
||||||
width: 6vmax;
|
|
||||||
height: auto;
|
|
||||||
`;
|
|
||||||
}
|
|
||||||
}}
|
|
||||||
`;
|
|
||||||
|
|
||||||
const CommanderDamageTextContainer = styled.div<{
|
export const MAX_TAP_MOVE_DISTANCE = 20;
|
||||||
$rotation: number;
|
|
||||||
}>`
|
|
||||||
position: relative;
|
|
||||||
top: 50%;
|
|
||||||
left: 50%;
|
|
||||||
transform: translate(-50%, -50%);
|
|
||||||
font-variant-numeric: tabular-nums;
|
|
||||||
pointer-events: none;
|
|
||||||
user-select: none;
|
|
||||||
-webkit-touch-callout: none;
|
|
||||||
-webkit-tap-highlight-color: transparent;
|
|
||||||
-moz-user-select: -moz-none;
|
|
||||||
-webkit-user-select: none;
|
|
||||||
-ms-user-select: none;
|
|
||||||
|
|
||||||
${(props) => {
|
const CommanderDamageContainer = twc.div<RotationDivProps>((props) => [
|
||||||
if (
|
'flex flex-grow',
|
||||||
props.$rotation === Rotation.SideFlipped ||
|
props.$rotation === Rotation.SideFlipped || props.$rotation === Rotation.Side
|
||||||
props.$rotation === Rotation.Side
|
? 'flex-col'
|
||||||
) {
|
: 'flex-row',
|
||||||
return css`
|
]);
|
||||||
rotate: 270deg;
|
|
||||||
`;
|
|
||||||
}
|
|
||||||
}}
|
|
||||||
`;
|
|
||||||
|
|
||||||
const PartnerDamageSeperator = styled.div<{
|
const CommanderDamageButton = twc.button<RotationButtonProps>((props) => [
|
||||||
$rotation: number;
|
'flex flex-grow border-none outline-none cursor-pointer m-0 p-0 webkit-user-select-none',
|
||||||
}>`
|
props.$rotation === Rotation.SideFlipped || props.$rotation === Rotation.Side
|
||||||
width: 1px;
|
? 'w-[6vmax] h-auto'
|
||||||
background-color: rgba(0, 0, 0, 1);
|
: 'h-[10vmin] w-1/2',
|
||||||
|
]);
|
||||||
|
|
||||||
${(props) => {
|
const CommanderDamageTextContainer = twc.div<RotationDivProps>((props) => [
|
||||||
if (
|
'relative top-1/2 left-1/2 tabular-nums pointer-events-none select-none webkit-user-select-none',
|
||||||
props.$rotation === Rotation.SideFlipped ||
|
props.$rotation === Rotation.SideFlipped || props.$rotation === Rotation.Side
|
||||||
props.$rotation === Rotation.Side
|
? 'rotate-[270deg]'
|
||||||
) {
|
: '',
|
||||||
return css`
|
]);
|
||||||
width: auto;
|
|
||||||
height: 1px;
|
const PartnerDamageSeparator = twc.div<RotationDivProps>((props) => [
|
||||||
`;
|
'bg-black',
|
||||||
}
|
props.$rotation === Rotation.SideFlipped || props.$rotation === Rotation.Side
|
||||||
}}
|
? 'w-full h-px'
|
||||||
`;
|
: 'w-px',
|
||||||
|
]);
|
||||||
|
|
||||||
type CommanderDamageButtonComponentProps = {
|
type CommanderDamageButtonComponentProps = {
|
||||||
player: Player;
|
player: Player;
|
||||||
@@ -115,6 +56,7 @@ type CommanderDamageButtonComponentProps = {
|
|||||||
type InputProps = {
|
type InputProps = {
|
||||||
opponentIndex: number;
|
opponentIndex: number;
|
||||||
isPartner: boolean;
|
isPartner: boolean;
|
||||||
|
event: React.PointerEvent<HTMLButtonElement>;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const CommanderDamage = ({
|
export const CommanderDamage = ({
|
||||||
@@ -124,12 +66,8 @@ export const CommanderDamage = ({
|
|||||||
}: CommanderDamageButtonComponentProps) => {
|
}: CommanderDamageButtonComponentProps) => {
|
||||||
const { updatePlayer } = usePlayers();
|
const { updatePlayer } = usePlayers();
|
||||||
const timeoutRef = useRef<NodeJS.Timeout | undefined>(undefined);
|
const timeoutRef = useRef<NodeJS.Timeout | undefined>(undefined);
|
||||||
const [timeoutFinished, setTimeoutFinished] = useState(false);
|
const [downLongPressed, setDownLongPressed] = useState(false);
|
||||||
const [hasPressedDown, setHasPressedDown] = useState(false);
|
const downPositionRef = useRef({ x: 0, y: 0 });
|
||||||
|
|
||||||
const isSide =
|
|
||||||
player.settings.rotation === Rotation.Side ||
|
|
||||||
player.settings.rotation === Rotation.SideFlipped;
|
|
||||||
|
|
||||||
const handleCommanderDamageChange = (
|
const handleCommanderDamageChange = (
|
||||||
index: number,
|
index: number,
|
||||||
@@ -168,34 +106,47 @@ export const CommanderDamage = ({
|
|||||||
handleLifeChange(player.lifeTotal - increment);
|
handleLifeChange(player.lifeTotal - increment);
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleDownInput = ({ opponentIndex, isPartner }: InputProps) => {
|
const handleDownInput = ({ opponentIndex, isPartner, event }: InputProps) => {
|
||||||
setTimeoutFinished(false);
|
downPositionRef.current = { x: event.clientX, y: event.clientY };
|
||||||
setHasPressedDown(true);
|
setDownLongPressed(false);
|
||||||
|
|
||||||
timeoutRef.current = setTimeout(() => {
|
timeoutRef.current = setTimeout(() => {
|
||||||
setTimeoutFinished(true);
|
setDownLongPressed(true);
|
||||||
handleCommanderDamageChange(opponentIndex, -1, isPartner);
|
handleCommanderDamageChange(opponentIndex, -1, isPartner);
|
||||||
}, decrementTimeoutMs);
|
}, decrementTimeoutMs);
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleUpInput = ({ opponentIndex, isPartner }: InputProps) => {
|
const handleUpInput = ({ opponentIndex, isPartner, event }: InputProps) => {
|
||||||
if (!(hasPressedDown && !timeoutFinished)) {
|
if (downLongPressed) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const upPosition = { x: event.clientX, y: event.clientY };
|
||||||
|
|
||||||
|
const hasMoved =
|
||||||
|
Math.abs(upPosition.x - downPositionRef.current.x) >
|
||||||
|
MAX_TAP_MOVE_DISTANCE ||
|
||||||
|
Math.abs(upPosition.y - downPositionRef.current.y) >
|
||||||
|
MAX_TAP_MOVE_DISTANCE;
|
||||||
|
|
||||||
|
if (hasMoved) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
clearTimeout(timeoutRef.current);
|
clearTimeout(timeoutRef.current);
|
||||||
|
|
||||||
handleCommanderDamageChange(opponentIndex, 1, isPartner);
|
handleCommanderDamageChange(opponentIndex, 1, isPartner);
|
||||||
setHasPressedDown(false);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleLeaveInput = () => {
|
const handleLeaveInput = () => {
|
||||||
setTimeoutFinished(true);
|
setDownLongPressed(true);
|
||||||
clearTimeout(timeoutRef.current);
|
clearTimeout(timeoutRef.current);
|
||||||
setHasPressedDown(false);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const opponentIndex = opponent.index;
|
const opponentIndex = opponent.index;
|
||||||
const fontSize = isSide ? '4vmax' : '7vmin';
|
const fontSize = player.isSide ? '4vmax' : '7vmin';
|
||||||
const fontWeight = 'bold';
|
const fontWeight = 'bold';
|
||||||
const strokeWidth = isSide ? '0.4vmax' : '0.7vmin';
|
const strokeWidth = player.isSide ? '0.4vmax' : '0.7vmin';
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<CommanderDamageContainer
|
<CommanderDamageContainer
|
||||||
@@ -206,16 +157,18 @@ export const CommanderDamage = ({
|
|||||||
<CommanderDamageButton
|
<CommanderDamageButton
|
||||||
key={opponentIndex}
|
key={opponentIndex}
|
||||||
$rotation={player.settings.rotation}
|
$rotation={player.settings.rotation}
|
||||||
onPointerDown={() =>
|
onPointerDown={(e) =>
|
||||||
handleDownInput({ opponentIndex, isPartner: false })
|
handleDownInput({ opponentIndex, isPartner: false, event: e })
|
||||||
|
}
|
||||||
|
onPointerUp={(e) =>
|
||||||
|
handleUpInput({ opponentIndex, isPartner: false, event: e })
|
||||||
}
|
}
|
||||||
onPointerUp={() => handleUpInput({ opponentIndex, isPartner: false })}
|
|
||||||
onPointerLeave={handleLeaveInput}
|
onPointerLeave={handleLeaveInput}
|
||||||
onContextMenu={(e: React.MouseEvent<HTMLButtonElement, MouseEvent>) => {
|
onContextMenu={(e: React.MouseEvent<HTMLButtonElement, MouseEvent>) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
}}
|
}}
|
||||||
$backgroundColor={opponent.color}
|
|
||||||
aria-label={`Commander damage. Player ${player.index}, opponent ${opponent.index}`}
|
aria-label={`Commander damage. Player ${player.index}, opponent ${opponent.index}`}
|
||||||
|
style={{ background: opponent.color }}
|
||||||
>
|
>
|
||||||
<CommanderDamageTextContainer $rotation={player.settings.rotation}>
|
<CommanderDamageTextContainer $rotation={player.settings.rotation}>
|
||||||
<OutlinedText
|
<OutlinedText
|
||||||
@@ -232,15 +185,15 @@ export const CommanderDamage = ({
|
|||||||
|
|
||||||
{opponent.settings.usePartner && (
|
{opponent.settings.usePartner && (
|
||||||
<>
|
<>
|
||||||
<PartnerDamageSeperator $rotation={player.settings.rotation} />
|
<PartnerDamageSeparator $rotation={player.settings.rotation} />
|
||||||
<CommanderDamageButton
|
<CommanderDamageButton
|
||||||
key={opponentIndex}
|
key={opponentIndex}
|
||||||
$rotation={player.settings.rotation}
|
$rotation={player.settings.rotation}
|
||||||
onPointerDown={() =>
|
onPointerDown={(e) =>
|
||||||
handleDownInput({ opponentIndex, isPartner: true })
|
handleDownInput({ opponentIndex, isPartner: true, event: e })
|
||||||
}
|
}
|
||||||
onPointerUp={() =>
|
onPointerUp={(e) =>
|
||||||
handleUpInput({ opponentIndex, isPartner: true })
|
handleUpInput({ opponentIndex, isPartner: true, event: e })
|
||||||
}
|
}
|
||||||
onPointerLeave={handleLeaveInput}
|
onPointerLeave={handleLeaveInput}
|
||||||
onContextMenu={(
|
onContextMenu={(
|
||||||
@@ -248,8 +201,8 @@ export const CommanderDamage = ({
|
|||||||
) => {
|
) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
}}
|
}}
|
||||||
$backgroundColor={opponent.color}
|
|
||||||
aria-label={`Partner Commander damage. Player ${player.index}, opponent ${opponent.index}`}
|
aria-label={`Partner Commander damage. Player ${player.index}, opponent ${opponent.index}`}
|
||||||
|
style={{ background: opponent.color }}
|
||||||
>
|
>
|
||||||
<CommanderDamageTextContainer $rotation={player.settings.rotation}>
|
<CommanderDamageTextContainer $rotation={player.settings.rotation}>
|
||||||
<OutlinedText
|
<OutlinedText
|
||||||
|
|||||||
@@ -1,60 +1,45 @@
|
|||||||
import { ReactNode, useRef, useState } from 'react';
|
import { ReactNode, useRef, useState } from 'react';
|
||||||
import styled from 'styled-components';
|
import { twc } from 'react-twc';
|
||||||
import { css } from 'styled-components';
|
|
||||||
import { decrementTimeoutMs } from '../../Data/constants';
|
import { decrementTimeoutMs } from '../../Data/constants';
|
||||||
import { CounterType, Rotation } from '../../Types/Player';
|
import { CounterType, Rotation } from '../../Types/Player';
|
||||||
import { OutlinedText } from '../Misc/OutlinedText';
|
import { OutlinedText } from '../Misc/OutlinedText';
|
||||||
|
import { MAX_TAP_MOVE_DISTANCE, RotationDivProps } from './CommanderDamage';
|
||||||
|
|
||||||
const ExtraCounterContainer = styled.div`
|
const ExtraCounterContainer = twc.div`
|
||||||
display: flex;
|
flex
|
||||||
justify-content: center;
|
justify-center
|
||||||
align-items: center;
|
items-center
|
||||||
pointer-events: all;
|
pointer-events-all
|
||||||
flex-grow: 1;
|
flex-grow
|
||||||
`;
|
`;
|
||||||
|
|
||||||
export const StyledExtraCounterButton = styled.button`
|
const ExtraCounterButton = twc.button`
|
||||||
display: flex;
|
flex
|
||||||
justify-content: center;
|
justify-center
|
||||||
align-items: center;
|
items-center
|
||||||
position: relative;
|
relative
|
||||||
flex-grow: 1;
|
flex-grow
|
||||||
border: none;
|
border-none
|
||||||
outline: none;
|
outline-none
|
||||||
cursor: pointer;
|
cursor-pointer
|
||||||
background-color: transparent;
|
bg-transparent
|
||||||
user-select: none;
|
select-none
|
||||||
-webkit-touch-callout: none;
|
h-full
|
||||||
-webkit-tap-highlight-color: transparent;
|
webkit-user-select-none
|
||||||
-moz-user-select: -moz-none;
|
`;
|
||||||
-webkit-user-select: none;
|
|
||||||
-ms-user-select: none;
|
|
||||||
height: 100%;
|
|
||||||
`;
|
|
||||||
|
|
||||||
const IconContainer = styled.div<{
|
const IconContainer = twc.div<RotationDivProps>((props) => [
|
||||||
$rotation: number;
|
'w-auto',
|
||||||
}>`
|
props.$rotation === Rotation.SideFlipped || props.$rotation === Rotation.Side
|
||||||
width: auto;
|
? 'rotate-[-90deg]'
|
||||||
|
: '',
|
||||||
|
]);
|
||||||
|
|
||||||
${(props) => {
|
const TextContainer = twc.div`
|
||||||
if (
|
absolute
|
||||||
props.$rotation === Rotation.SideFlipped ||
|
top-1/2
|
||||||
props.$rotation === Rotation.Side
|
left-1/2
|
||||||
) {
|
`;
|
||||||
return css`
|
|
||||||
rotate: -90deg;
|
|
||||||
`;
|
|
||||||
}
|
|
||||||
}}
|
|
||||||
`;
|
|
||||||
|
|
||||||
const TextContainer = styled.div`
|
|
||||||
position: absolute;
|
|
||||||
translate: -50%;
|
|
||||||
top: 50%;
|
|
||||||
left: 50%;
|
|
||||||
`;
|
|
||||||
|
|
||||||
type ExtraCounterProps = {
|
type ExtraCounterProps = {
|
||||||
Icon: ReactNode;
|
Icon: ReactNode;
|
||||||
@@ -62,6 +47,7 @@ type ExtraCounterProps = {
|
|||||||
type: CounterType;
|
type: CounterType;
|
||||||
setCounterTotal: (updatedCounterTotal: number, type: CounterType) => void;
|
setCounterTotal: (updatedCounterTotal: number, type: CounterType) => void;
|
||||||
rotation: number;
|
rotation: number;
|
||||||
|
isSide: boolean;
|
||||||
playerIndex: number;
|
playerIndex: number;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -71,14 +57,13 @@ const ExtraCounter = ({
|
|||||||
setCounterTotal,
|
setCounterTotal,
|
||||||
type,
|
type,
|
||||||
rotation,
|
rotation,
|
||||||
|
isSide,
|
||||||
playerIndex,
|
playerIndex,
|
||||||
}: ExtraCounterProps) => {
|
}: ExtraCounterProps) => {
|
||||||
const timeoutRef = useRef<NodeJS.Timeout | undefined>(undefined);
|
const timeoutRef = useRef<NodeJS.Timeout | undefined>(undefined);
|
||||||
const [timeoutFinished, setTimeoutFinished] = useState(false);
|
const [timeoutFinished, setTimeoutFinished] = useState(false);
|
||||||
const [hasPressedDown, setHasPressedDown] = useState(false);
|
const [hasPressedDown, setHasPressedDown] = useState(false);
|
||||||
|
const downPositionRef = useRef({ x: 0, y: 0 });
|
||||||
const isSide =
|
|
||||||
rotation === Rotation.Side || rotation === Rotation.SideFlipped;
|
|
||||||
|
|
||||||
const handleCountChange = (increment: number) => {
|
const handleCountChange = (increment: number) => {
|
||||||
if (!counterTotal) {
|
if (!counterTotal) {
|
||||||
@@ -88,7 +73,8 @@ const ExtraCounter = ({
|
|||||||
setCounterTotal(counterTotal + increment, type);
|
setCounterTotal(counterTotal + increment, type);
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleDownInput = () => {
|
const handleDownInput = (event: React.PointerEvent<HTMLButtonElement>) => {
|
||||||
|
downPositionRef.current = { x: event.clientX, y: event.clientY };
|
||||||
setTimeoutFinished(false);
|
setTimeoutFinished(false);
|
||||||
setHasPressedDown(true);
|
setHasPressedDown(true);
|
||||||
timeoutRef.current = setTimeout(() => {
|
timeoutRef.current = setTimeout(() => {
|
||||||
@@ -97,10 +83,23 @@ const ExtraCounter = ({
|
|||||||
}, decrementTimeoutMs);
|
}, decrementTimeoutMs);
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleUpInput = () => {
|
const handleUpInput = (event: React.PointerEvent<HTMLButtonElement>) => {
|
||||||
if (!(hasPressedDown && !timeoutFinished)) {
|
if (!(hasPressedDown && !timeoutFinished)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const upPosition = { x: event.clientX, y: event.clientY };
|
||||||
|
|
||||||
|
const hasMoved =
|
||||||
|
Math.abs(upPosition.x - downPositionRef.current.x) >
|
||||||
|
MAX_TAP_MOVE_DISTANCE ||
|
||||||
|
Math.abs(upPosition.y - downPositionRef.current.y) >
|
||||||
|
MAX_TAP_MOVE_DISTANCE;
|
||||||
|
|
||||||
|
if (hasMoved) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
clearTimeout(timeoutRef.current);
|
clearTimeout(timeoutRef.current);
|
||||||
handleCountChange(1);
|
handleCountChange(1);
|
||||||
setHasPressedDown(false);
|
setHasPressedDown(false);
|
||||||
@@ -118,7 +117,7 @@ const ExtraCounter = ({
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<ExtraCounterContainer>
|
<ExtraCounterContainer>
|
||||||
<StyledExtraCounterButton
|
<ExtraCounterButton
|
||||||
onPointerDown={handleDownInput}
|
onPointerDown={handleDownInput}
|
||||||
onPointerUp={handleUpInput}
|
onPointerUp={handleUpInput}
|
||||||
onPointerLeave={handleLeaveInput}
|
onPointerLeave={handleLeaveInput}
|
||||||
@@ -139,7 +138,7 @@ const ExtraCounter = ({
|
|||||||
</OutlinedText>
|
</OutlinedText>
|
||||||
</TextContainer>
|
</TextContainer>
|
||||||
</IconContainer>
|
</IconContainer>
|
||||||
</StyledExtraCounterButton>
|
</ExtraCounterButton>
|
||||||
</ExtraCounterContainer>
|
</ExtraCounterContainer>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,89 +1,80 @@
|
|||||||
import { useRef, useState } from 'react';
|
import { useEffect, useRef, useState } from 'react';
|
||||||
import styled from 'styled-components';
|
import { TwcComponentProps, twc } from 'react-twc';
|
||||||
import { css } from 'styled-components';
|
|
||||||
import { lifeLongPressMultiplier } from '../../Data/constants';
|
import { lifeLongPressMultiplier } from '../../Data/constants';
|
||||||
|
import { Player, Rotation } from '../../Types/Player';
|
||||||
|
import { MAX_TAP_MOVE_DISTANCE } from './CommanderDamage';
|
||||||
|
import { checkContrast } from '../../Utils/checkContrast';
|
||||||
|
|
||||||
import { Rotation } from '../../Types/Player';
|
type RotationButtonProps = TwcComponentProps<'div'> & {
|
||||||
|
|
||||||
export const StyledLifeCounterButton = styled.button`
|
|
||||||
width: 100%;
|
|
||||||
height: 100%;
|
|
||||||
color: rgba(0, 0, 0, 0.4);
|
|
||||||
font-weight: 600;
|
|
||||||
background-color: transparent;
|
|
||||||
border: none;
|
|
||||||
outline: none;
|
|
||||||
cursor: pointer;
|
|
||||||
display: flex;
|
|
||||||
justify-content: center;
|
|
||||||
align-items: center;
|
|
||||||
user-select: none;
|
|
||||||
-webkit-touch-callout: none;
|
|
||||||
-webkit-tap-highlight-color: transparent;
|
|
||||||
-moz-user-select: -moz-none;
|
|
||||||
-webkit-user-select: none;
|
|
||||||
-ms-user-select: none;
|
|
||||||
`;
|
|
||||||
|
|
||||||
const TextContainer = styled.div<{
|
|
||||||
$align?: string;
|
$align?: string;
|
||||||
$rotation: number;
|
$rotation?: number;
|
||||||
}>`
|
};
|
||||||
position: relative;
|
|
||||||
|
|
||||||
${(props) => {
|
const LifeCounterButtonTwc = twc.button`
|
||||||
if (
|
h-full
|
||||||
props.$rotation === Rotation.SideFlipped ||
|
w-full
|
||||||
props.$rotation === Rotation.Side
|
flex
|
||||||
) {
|
font-semibold
|
||||||
if (props.$align === 'right') {
|
bg-transparent
|
||||||
return css`
|
border-none
|
||||||
rotate: -90deg;
|
outline-none
|
||||||
bottom: 25%;
|
cursor-pointer
|
||||||
top: auto;
|
justify-center
|
||||||
`;
|
items-center
|
||||||
}
|
select-none
|
||||||
return css`
|
webkit-user-select-none
|
||||||
rotate: -90deg;
|
`;
|
||||||
top: 25%;
|
|
||||||
`;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (props.$align === 'right') {
|
const TextContainer = twc.div<RotationButtonProps>((props) => [
|
||||||
return css`
|
'relative',
|
||||||
left: 25%;
|
props.$rotation === Rotation.SideFlipped || props.$rotation === Rotation.Side
|
||||||
`;
|
? props.$align === 'right'
|
||||||
}
|
? '-rotate-90 bottom-1/4 top-auto'
|
||||||
return css`
|
: '-rotate-90 top-1/4'
|
||||||
right: 25%;
|
: 'top-auto',
|
||||||
`;
|
props.$rotation === Rotation.Flipped || props.$rotation === Rotation.Normal
|
||||||
}}
|
? props.$align === 'right'
|
||||||
`;
|
? 'left-1/4'
|
||||||
|
: 'right-1/4'
|
||||||
|
: '',
|
||||||
|
]);
|
||||||
|
|
||||||
type LifeCounterButtonProps = {
|
type LifeCounterButtonProps = {
|
||||||
lifeTotal: number;
|
player: Player;
|
||||||
setLifeTotal: (lifeTotal: number) => void;
|
setLifeTotal: (lifeTotal: number) => void;
|
||||||
rotation: number;
|
|
||||||
operation: 'add' | 'subtract';
|
operation: 'add' | 'subtract';
|
||||||
increment: number;
|
increment: number;
|
||||||
};
|
};
|
||||||
|
|
||||||
const LifeCounterButton = ({
|
const LifeCounterButton = ({
|
||||||
lifeTotal,
|
player,
|
||||||
setLifeTotal,
|
setLifeTotal,
|
||||||
rotation,
|
|
||||||
operation,
|
operation,
|
||||||
increment,
|
increment,
|
||||||
}: LifeCounterButtonProps) => {
|
}: LifeCounterButtonProps) => {
|
||||||
const timeoutRef = useRef<NodeJS.Timeout | undefined>(undefined);
|
const timeoutRef = useRef<NodeJS.Timeout | undefined>(undefined);
|
||||||
const [timeoutFinished, setTimeoutFinished] = useState(false);
|
const [timeoutFinished, setTimeoutFinished] = useState(false);
|
||||||
const [hasPressedDown, setHasPressedDown] = useState(false);
|
const [hasPressedDown, setHasPressedDown] = useState(false);
|
||||||
|
const downPositionRef = useRef({ x: 0, y: 0 });
|
||||||
|
|
||||||
|
const [iconColor, setIconColor] = useState<'dark' | 'light'>('dark');
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const contrast = checkContrast(player.color, '#00000080');
|
||||||
|
|
||||||
|
if (contrast === 'Fail') {
|
||||||
|
setIconColor('light');
|
||||||
|
} else {
|
||||||
|
setIconColor('dark');
|
||||||
|
}
|
||||||
|
}, [player.color]);
|
||||||
|
|
||||||
const handleLifeChange = (increment: number) => {
|
const handleLifeChange = (increment: number) => {
|
||||||
setLifeTotal(lifeTotal + increment);
|
setLifeTotal(player.lifeTotal + increment);
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleDownInput = () => {
|
const handleDownInput = (event: React.PointerEvent<HTMLButtonElement>) => {
|
||||||
|
downPositionRef.current = { x: event.clientX, y: event.clientY };
|
||||||
setTimeoutFinished(false);
|
setTimeoutFinished(false);
|
||||||
setHasPressedDown(true);
|
setHasPressedDown(true);
|
||||||
timeoutRef.current = setTimeout(() => {
|
timeoutRef.current = setTimeout(() => {
|
||||||
@@ -92,10 +83,23 @@ const LifeCounterButton = ({
|
|||||||
}, 500);
|
}, 500);
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleUpInput = () => {
|
const handleUpInput = (event: React.PointerEvent<HTMLButtonElement>) => {
|
||||||
if (!(hasPressedDown && !timeoutFinished)) {
|
if (!(hasPressedDown && !timeoutFinished)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const upPosition = { x: event.clientX, y: event.clientY };
|
||||||
|
|
||||||
|
const hasMoved =
|
||||||
|
Math.abs(upPosition.x - downPositionRef.current.x) >
|
||||||
|
MAX_TAP_MOVE_DISTANCE ||
|
||||||
|
Math.abs(upPosition.y - downPositionRef.current.y) >
|
||||||
|
MAX_TAP_MOVE_DISTANCE;
|
||||||
|
|
||||||
|
if (hasMoved) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
clearTimeout(timeoutRef.current);
|
clearTimeout(timeoutRef.current);
|
||||||
handleLifeChange(operation === 'add' ? 1 : -1);
|
handleLifeChange(operation === 'add' ? 1 : -1);
|
||||||
setHasPressedDown(false);
|
setHasPressedDown(false);
|
||||||
@@ -108,12 +112,13 @@ const LifeCounterButton = ({
|
|||||||
};
|
};
|
||||||
|
|
||||||
const fontSize =
|
const fontSize =
|
||||||
rotation === Rotation.SideFlipped || rotation === Rotation.Side
|
player.settings.rotation === Rotation.SideFlipped ||
|
||||||
|
player.settings.rotation === Rotation.Side
|
||||||
? '8vmax'
|
? '8vmax'
|
||||||
: '12vmin';
|
: '12vmin';
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<StyledLifeCounterButton
|
<LifeCounterButtonTwc
|
||||||
onPointerDown={handleDownInput}
|
onPointerDown={handleDownInput}
|
||||||
onPointerUp={handleUpInput}
|
onPointerUp={handleUpInput}
|
||||||
onPointerLeave={handleLeaveInput}
|
onPointerLeave={handleLeaveInput}
|
||||||
@@ -124,12 +129,15 @@ const LifeCounterButton = ({
|
|||||||
aria-label={`${operation === 'add' ? 'Add' : 'Subtract'} life`}
|
aria-label={`${operation === 'add' ? 'Add' : 'Subtract'} life`}
|
||||||
>
|
>
|
||||||
<TextContainer
|
<TextContainer
|
||||||
$rotation={rotation}
|
$rotation={player.settings.rotation}
|
||||||
$align={operation === 'add' ? 'right' : 'left'}
|
$align={operation === 'add' ? 'right' : 'left'}
|
||||||
|
data-contrast={iconColor}
|
||||||
|
className="data-[contrast=dark]:text-icons-dark
|
||||||
|
data-[contrast=light]:text-icons-light"
|
||||||
>
|
>
|
||||||
{operation === 'add' ? '\u002B' : '\u2212'}
|
{operation === 'add' ? '\u002B' : '\u2212'}
|
||||||
</TextContainer>
|
</TextContainer>
|
||||||
</StyledLifeCounterButton>
|
</LifeCounterButtonTwc>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -1,43 +1,15 @@
|
|||||||
import styled, { css } from 'styled-components';
|
import { twc } from 'react-twc';
|
||||||
import { Skull } from '../../Icons/generated';
|
import { Skull } from '../../Icons/generated';
|
||||||
import { Rotation } from '../../Types/Player';
|
import { Rotation } from '../../Types/Player';
|
||||||
|
import { RotationDivProps } from './CommanderDamage';
|
||||||
|
|
||||||
export const LoseButton = styled.button<{ $rotation: Rotation }>`
|
const LoseButton = twc.div<RotationDivProps>((props) => [
|
||||||
position: absolute;
|
'absolute flex-grow border-none outline-none cursor-pointer bg-interface-loseButton-background rounded-lg select-none z-[1] webkit-user-select-none py-2 px-4 ',
|
||||||
flex-grow: 1;
|
|
||||||
border: none;
|
|
||||||
outline: none;
|
|
||||||
cursor: pointer;
|
|
||||||
top: 25%;
|
|
||||||
right: 15%;
|
|
||||||
background-color: #43434380;
|
|
||||||
border-radius: 8px;
|
|
||||||
-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;
|
|
||||||
z-index: 1;
|
|
||||||
|
|
||||||
${(props) => {
|
props.$rotation === Rotation.SideFlipped || props.$rotation === Rotation.Side
|
||||||
if (props.$rotation === Rotation.SideFlipped) {
|
? `left-[21%]`
|
||||||
return css`
|
: 'top-[21%]',
|
||||||
right: auto;
|
]);
|
||||||
top: 15%;
|
|
||||||
left: 27%;
|
|
||||||
rotate: ${props.$rotation}deg;
|
|
||||||
`;
|
|
||||||
} else if (props.$rotation === Rotation.Side) {
|
|
||||||
return css`
|
|
||||||
right: auto;
|
|
||||||
top: 15%;
|
|
||||||
left: 27%;
|
|
||||||
rotate: ${props.$rotation - 180}deg;
|
|
||||||
`;
|
|
||||||
}
|
|
||||||
}}
|
|
||||||
`;
|
|
||||||
|
|
||||||
type LoseButtonProps = {
|
type LoseButtonProps = {
|
||||||
onClick: () => void;
|
onClick: () => void;
|
||||||
@@ -45,9 +17,23 @@ type LoseButtonProps = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const LoseGameButton = ({ rotation, onClick }: LoseButtonProps) => {
|
export const LoseGameButton = ({ rotation, onClick }: LoseButtonProps) => {
|
||||||
|
const calcRotation =
|
||||||
|
rotation === Rotation.SideFlipped
|
||||||
|
? rotation
|
||||||
|
: rotation === Rotation.Side
|
||||||
|
? rotation - 180
|
||||||
|
: rotation === Rotation.Flipped
|
||||||
|
? rotation - 180
|
||||||
|
: rotation;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<LoseButton $rotation={rotation} onClick={onClick} aria-label={`Lose Game`}>
|
<LoseButton
|
||||||
<Skull size="5vmin" color="black" opacity={0.5} />
|
$rotation={rotation}
|
||||||
|
onClick={onClick}
|
||||||
|
aria-label={`Lose Game`}
|
||||||
|
style={{ rotate: `${calcRotation}deg` }}
|
||||||
|
>
|
||||||
|
<Skull size="8vmin" color="black" opacity={0.5} />
|
||||||
</LoseButton>
|
</LoseButton>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,53 +0,0 @@
|
|||||||
import styled from 'styled-components';
|
|
||||||
import { css } from 'styled-components';
|
|
||||||
import { Rotation } from '../../Types/Player';
|
|
||||||
import { Cog } from '../../Icons/generated';
|
|
||||||
|
|
||||||
export const StyledSettingsButton = styled.button<{ $rotation: Rotation }>`
|
|
||||||
position: absolute;
|
|
||||||
flex-grow: 1;
|
|
||||||
border: none;
|
|
||||||
outline: none;
|
|
||||||
cursor: pointer;
|
|
||||||
top: 25%;
|
|
||||||
right: 1vmax;
|
|
||||||
background-color: transparent;
|
|
||||||
user-select: none;
|
|
||||||
-webkit-touch-callout: none;
|
|
||||||
-webkit-tap-highlight-color: transparent;
|
|
||||||
-moz-user-select: -moz-none;
|
|
||||||
-webkit-user-select: none;
|
|
||||||
-ms-user-select: none;
|
|
||||||
z-index: 1;
|
|
||||||
${(props) => {
|
|
||||||
if (
|
|
||||||
props.$rotation === Rotation.Side ||
|
|
||||||
props.$rotation === Rotation.SideFlipped
|
|
||||||
) {
|
|
||||||
return css`
|
|
||||||
right: auto;
|
|
||||||
top: 1vmax;
|
|
||||||
left: 27%;
|
|
||||||
`;
|
|
||||||
}
|
|
||||||
}}
|
|
||||||
`;
|
|
||||||
|
|
||||||
type SettingsButtonProps = {
|
|
||||||
onClick: () => void;
|
|
||||||
rotation: Rotation;
|
|
||||||
};
|
|
||||||
|
|
||||||
const SettingsButton = ({ onClick, rotation }: SettingsButtonProps) => {
|
|
||||||
return (
|
|
||||||
<StyledSettingsButton
|
|
||||||
onClick={onClick}
|
|
||||||
$rotation={rotation}
|
|
||||||
aria-label={`Settings`}
|
|
||||||
>
|
|
||||||
<Cog size="5vmin" color="black" opacity="0.3" />
|
|
||||||
</StyledSettingsButton>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
export default SettingsButton;
|
|
||||||
@@ -1,27 +1,13 @@
|
|||||||
|
import { twc } from 'react-twc';
|
||||||
import { Player, Rotation } from '../../Types/Player';
|
import { Player, Rotation } from '../../Types/Player';
|
||||||
import styled from 'styled-components';
|
import { CommanderDamage, RotationDivProps } from '../Buttons/CommanderDamage';
|
||||||
import { css } from 'styled-components';
|
|
||||||
import { CommanderDamage } from '../Buttons/CommanderDamage';
|
|
||||||
|
|
||||||
const CommanderDamageGrid = styled.div<{ $rotation: number }>`
|
const CommanderDamageGrid = twc.div<RotationDivProps>((props) => [
|
||||||
display: flex;
|
'flex flex-grow',
|
||||||
flex-direction: row;
|
props.$rotation === Rotation.SideFlipped || props.$rotation === Rotation.Side
|
||||||
flex-grow: 1;
|
? 'flex-col h-full w-auto'
|
||||||
width: 100%;
|
: 'flex-row w-full',
|
||||||
|
]);
|
||||||
${(props) => {
|
|
||||||
if (
|
|
||||||
props.$rotation === Rotation.SideFlipped ||
|
|
||||||
props.$rotation === Rotation.Side
|
|
||||||
) {
|
|
||||||
return css`
|
|
||||||
flex-direction: column;
|
|
||||||
height: 100%;
|
|
||||||
width: auto;
|
|
||||||
`;
|
|
||||||
}
|
|
||||||
}}
|
|
||||||
`;
|
|
||||||
|
|
||||||
type CommanderDamageBarProps = {
|
type CommanderDamageBarProps = {
|
||||||
opponents: Player[];
|
opponents: Player[];
|
||||||
|
|||||||
@@ -1,59 +0,0 @@
|
|||||||
import styled from 'styled-components';
|
|
||||||
import { usePlayers } from '../../Hooks/usePlayers';
|
|
||||||
import LifeCounter from '../LifeCounter/LifeCounter';
|
|
||||||
|
|
||||||
export const CountersWrapper = styled.div`
|
|
||||||
width: 100%;
|
|
||||||
height: 100%;
|
|
||||||
background-color: black;
|
|
||||||
`;
|
|
||||||
|
|
||||||
export const CountersGrid = styled.div<{ $gridTemplateAreas: string }>`
|
|
||||||
display: grid;
|
|
||||||
gap: 4px;
|
|
||||||
-webkit-box-sizing: border-box;
|
|
||||||
-moz-box-sizing: border-box;
|
|
||||||
box-sizing: border-box;
|
|
||||||
height: 100%;
|
|
||||||
grid-template-areas: ${({ $gridTemplateAreas }) => $gridTemplateAreas};
|
|
||||||
`;
|
|
||||||
|
|
||||||
export const GridItemContainer = styled.div<{
|
|
||||||
$gridArea: string;
|
|
||||||
}>`
|
|
||||||
display: flex;
|
|
||||||
justify-content: center;
|
|
||||||
align-items: center;
|
|
||||||
grid-area: ${(props) => props.$gridArea};
|
|
||||||
`;
|
|
||||||
|
|
||||||
type CountersProps = {
|
|
||||||
gridAreas: string;
|
|
||||||
};
|
|
||||||
|
|
||||||
const Counters = ({ gridAreas }: CountersProps) => {
|
|
||||||
const { players } = usePlayers();
|
|
||||||
return (
|
|
||||||
<CountersWrapper>
|
|
||||||
<CountersGrid $gridTemplateAreas={gridAreas}>
|
|
||||||
{players.map((player) => {
|
|
||||||
return (
|
|
||||||
<GridItemContainer
|
|
||||||
key={player.index}
|
|
||||||
$gridArea={`player${player.index}`}
|
|
||||||
>
|
|
||||||
<LifeCounter
|
|
||||||
player={player}
|
|
||||||
opponents={players.filter(
|
|
||||||
(opponent) => opponent.index !== player.index
|
|
||||||
)}
|
|
||||||
/>
|
|
||||||
</GridItemContainer>
|
|
||||||
);
|
|
||||||
})}
|
|
||||||
</CountersGrid>
|
|
||||||
</CountersWrapper>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
export default Counters;
|
|
||||||
@@ -1,8 +1,5 @@
|
|||||||
import { CounterType, Player } from '../../Types/Player';
|
import { twc } from 'react-twc';
|
||||||
import ExtraCounter from '../Buttons/ExtraCounter';
|
import { usePlayers } from '../../Hooks/usePlayers';
|
||||||
import styled from 'styled-components';
|
|
||||||
import { css } from 'styled-components';
|
|
||||||
import { Rotation } from '../../Types/Player';
|
|
||||||
import {
|
import {
|
||||||
CommanderTax,
|
CommanderTax,
|
||||||
Energy,
|
Energy,
|
||||||
@@ -10,49 +7,25 @@ import {
|
|||||||
PartnerTax,
|
PartnerTax,
|
||||||
Poison,
|
Poison,
|
||||||
} from '../../Icons/generated';
|
} from '../../Icons/generated';
|
||||||
import { usePlayers } from '../../Hooks/usePlayers';
|
import { CounterType, Player, Rotation } from '../../Types/Player';
|
||||||
|
import { RotationDivProps } from '../Buttons/CommanderDamage';
|
||||||
|
import ExtraCounter from '../Buttons/ExtraCounter';
|
||||||
|
import { useEffect, useState } from 'react';
|
||||||
|
import { checkContrast } from '../../Utils/checkContrast';
|
||||||
|
|
||||||
const Container = styled.div<{ $rotation: Rotation }>`
|
const Container = twc.div<RotationDivProps>((props) => [
|
||||||
width: 100%;
|
'flex',
|
||||||
height: 20vmin;
|
props.$rotation === Rotation.SideFlipped || props.$rotation === Rotation.Side
|
||||||
display: flex;
|
? 'h-full w-[8vmax]'
|
||||||
|
: 'h-[20vmin] w-full',
|
||||||
|
]);
|
||||||
|
|
||||||
${(props) => {
|
export const ExtraCountersGrid = twc.div<RotationDivProps>((props) => [
|
||||||
if (
|
'flex absolute flex-row flex-grow pointer-events-none overflow-x-scroll overflow-y-hidden',
|
||||||
props.$rotation === Rotation.SideFlipped ||
|
props.$rotation === Rotation.SideFlipped || props.$rotation === Rotation.Side
|
||||||
props.$rotation === Rotation.Side
|
? 'flex-col-reverse h-full w-auto bottom-auto right-0'
|
||||||
) {
|
: 'w-full bottom-0',
|
||||||
return css`
|
]);
|
||||||
height: 100%;
|
|
||||||
width: 9.3vmax;
|
|
||||||
`;
|
|
||||||
}
|
|
||||||
}}
|
|
||||||
`;
|
|
||||||
|
|
||||||
export const ExtraCountersGrid = styled.div<{ $rotation: Rotation }>`
|
|
||||||
display: flex;
|
|
||||||
position: absolute;
|
|
||||||
width: 100%;
|
|
||||||
flex-direction: row;
|
|
||||||
flex-grow: 1;
|
|
||||||
bottom: 0;
|
|
||||||
pointer-events: none;
|
|
||||||
|
|
||||||
${(props) => {
|
|
||||||
if (
|
|
||||||
props.$rotation === Rotation.SideFlipped ||
|
|
||||||
props.$rotation === Rotation.Side
|
|
||||||
) {
|
|
||||||
return css`
|
|
||||||
flex-direction: column-reverse;
|
|
||||||
height: 100%;
|
|
||||||
width: auto;
|
|
||||||
bottom: auto;
|
|
||||||
`;
|
|
||||||
}
|
|
||||||
}}
|
|
||||||
`;
|
|
||||||
|
|
||||||
type ExtraCountersBarProps = {
|
type ExtraCountersBarProps = {
|
||||||
player: Player;
|
player: Player;
|
||||||
@@ -60,6 +33,17 @@ type ExtraCountersBarProps = {
|
|||||||
|
|
||||||
const ExtraCountersBar = ({ player }: ExtraCountersBarProps) => {
|
const ExtraCountersBar = ({ player }: ExtraCountersBarProps) => {
|
||||||
const { updatePlayer } = usePlayers();
|
const { updatePlayer } = usePlayers();
|
||||||
|
const [iconColor, setIconColor] = useState<'dark' | 'light'>('dark');
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const contrast = checkContrast(player.color, '#00000080');
|
||||||
|
|
||||||
|
if (contrast === 'Fail') {
|
||||||
|
setIconColor('light');
|
||||||
|
} else {
|
||||||
|
setIconColor('dark');
|
||||||
|
}
|
||||||
|
}, [player.color]);
|
||||||
|
|
||||||
const handleCounterChange = (
|
const handleCounterChange = (
|
||||||
updatedCounterTotal: number,
|
updatedCounterTotal: number,
|
||||||
@@ -122,13 +106,20 @@ const ExtraCountersBar = ({ player }: ExtraCountersBarProps) => {
|
|||||||
{useCommanderDamage && (
|
{useCommanderDamage && (
|
||||||
<ExtraCounter
|
<ExtraCounter
|
||||||
rotation={player.settings.rotation}
|
rotation={player.settings.rotation}
|
||||||
Icon={<CommanderTax size={iconSize} opacity="0.5" color="black" />}
|
Icon={
|
||||||
|
<CommanderTax
|
||||||
|
size={iconSize}
|
||||||
|
data-contrast={iconColor}
|
||||||
|
className="data-[contrast=dark]:text-icons-dark data-[contrast=light]:text-icons-light"
|
||||||
|
/>
|
||||||
|
}
|
||||||
type={CounterType.CommanderTax}
|
type={CounterType.CommanderTax}
|
||||||
counterTotal={
|
counterTotal={
|
||||||
player.extraCounters?.find(
|
player.extraCounters?.find(
|
||||||
(counter) => counter.type === 'commanderTax'
|
(counter) => counter.type === 'commanderTax'
|
||||||
)?.value
|
)?.value
|
||||||
}
|
}
|
||||||
|
isSide={player.isSide}
|
||||||
setCounterTotal={handleCounterChange}
|
setCounterTotal={handleCounterChange}
|
||||||
playerIndex={player.index}
|
playerIndex={player.index}
|
||||||
/>
|
/>
|
||||||
@@ -136,13 +127,20 @@ const ExtraCountersBar = ({ player }: ExtraCountersBarProps) => {
|
|||||||
{Boolean(useCommanderDamage && usePartner) && (
|
{Boolean(useCommanderDamage && usePartner) && (
|
||||||
<ExtraCounter
|
<ExtraCounter
|
||||||
rotation={player.settings.rotation}
|
rotation={player.settings.rotation}
|
||||||
Icon={<PartnerTax size={iconSize} opacity="0.5" color="black" />}
|
Icon={
|
||||||
|
<PartnerTax
|
||||||
|
size={iconSize}
|
||||||
|
data-contrast={iconColor}
|
||||||
|
className="data-[contrast=dark]:text-icons-dark data-[contrast=light]:text-icons-light"
|
||||||
|
/>
|
||||||
|
}
|
||||||
type={CounterType.PartnerTax}
|
type={CounterType.PartnerTax}
|
||||||
counterTotal={
|
counterTotal={
|
||||||
player.extraCounters?.find(
|
player.extraCounters?.find(
|
||||||
(counter) => counter.type === 'partnerTax'
|
(counter) => counter.type === 'partnerTax'
|
||||||
)?.value
|
)?.value
|
||||||
}
|
}
|
||||||
|
isSide={player.isSide}
|
||||||
setCounterTotal={handleCounterChange}
|
setCounterTotal={handleCounterChange}
|
||||||
playerIndex={player.index}
|
playerIndex={player.index}
|
||||||
/>
|
/>
|
||||||
@@ -150,12 +148,19 @@ const ExtraCountersBar = ({ player }: ExtraCountersBarProps) => {
|
|||||||
{usePoison && (
|
{usePoison && (
|
||||||
<ExtraCounter
|
<ExtraCounter
|
||||||
rotation={player.settings.rotation}
|
rotation={player.settings.rotation}
|
||||||
Icon={<Poison size={iconSize} opacity="0.5" color="black" />}
|
Icon={
|
||||||
|
<Poison
|
||||||
|
size={iconSize}
|
||||||
|
data-contrast={iconColor}
|
||||||
|
className="data-[contrast=dark]:text-icons-dark data-[contrast=light]:text-icons-light"
|
||||||
|
/>
|
||||||
|
}
|
||||||
type={CounterType.Poison}
|
type={CounterType.Poison}
|
||||||
counterTotal={
|
counterTotal={
|
||||||
player.extraCounters?.find((counter) => counter.type === 'poison')
|
player.extraCounters?.find((counter) => counter.type === 'poison')
|
||||||
?.value
|
?.value
|
||||||
}
|
}
|
||||||
|
isSide={player.isSide}
|
||||||
setCounterTotal={handleCounterChange}
|
setCounterTotal={handleCounterChange}
|
||||||
playerIndex={player.index}
|
playerIndex={player.index}
|
||||||
/>
|
/>
|
||||||
@@ -163,12 +168,19 @@ const ExtraCountersBar = ({ player }: ExtraCountersBarProps) => {
|
|||||||
{useEnergy && (
|
{useEnergy && (
|
||||||
<ExtraCounter
|
<ExtraCounter
|
||||||
rotation={player.settings.rotation}
|
rotation={player.settings.rotation}
|
||||||
Icon={<Energy size={iconSize} opacity="0.5" color="black" />}
|
Icon={
|
||||||
|
<Energy
|
||||||
|
size={iconSize}
|
||||||
|
data-contrast={iconColor}
|
||||||
|
className="data-[contrast=dark]:text-icons-dark data-[contrast=light]:text-icons-light"
|
||||||
|
/>
|
||||||
|
}
|
||||||
type={CounterType.Energy}
|
type={CounterType.Energy}
|
||||||
counterTotal={
|
counterTotal={
|
||||||
player.extraCounters?.find((counter) => counter.type === 'energy')
|
player.extraCounters?.find((counter) => counter.type === 'energy')
|
||||||
?.value
|
?.value
|
||||||
}
|
}
|
||||||
|
isSide={player.isSide}
|
||||||
setCounterTotal={handleCounterChange}
|
setCounterTotal={handleCounterChange}
|
||||||
playerIndex={player.index}
|
playerIndex={player.index}
|
||||||
/>
|
/>
|
||||||
@@ -176,13 +188,20 @@ const ExtraCountersBar = ({ player }: ExtraCountersBarProps) => {
|
|||||||
{useExperience && (
|
{useExperience && (
|
||||||
<ExtraCounter
|
<ExtraCounter
|
||||||
rotation={player.settings.rotation}
|
rotation={player.settings.rotation}
|
||||||
Icon={<Experience size={iconSize} opacity="0.5" color="black" />}
|
Icon={
|
||||||
|
<Experience
|
||||||
|
size={iconSize}
|
||||||
|
data-contrast={iconColor}
|
||||||
|
className="data-[contrast=dark]:text-icons-dark data-[contrast=light]:text-icons-light"
|
||||||
|
/>
|
||||||
|
}
|
||||||
type={CounterType.Experience}
|
type={CounterType.Experience}
|
||||||
counterTotal={
|
counterTotal={
|
||||||
player.extraCounters?.find(
|
player.extraCounters?.find(
|
||||||
(counter) => counter.type === 'experience'
|
(counter) => counter.type === 'experience'
|
||||||
)?.value
|
)?.value
|
||||||
}
|
}
|
||||||
|
isSide={player.isSide}
|
||||||
setCounterTotal={handleCounterChange}
|
setCounterTotal={handleCounterChange}
|
||||||
playerIndex={player.index}
|
playerIndex={player.index}
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -1,115 +1,43 @@
|
|||||||
import { useEffect, useRef, useState } from 'react';
|
import { useEffect, useRef, useState } from 'react';
|
||||||
import styled, { css, keyframes } from 'styled-components';
|
import { twc } from 'react-twc';
|
||||||
import { Player, Rotation } from '../../Types/Player';
|
import { Player, Rotation } from '../../Types/Player';
|
||||||
|
import {
|
||||||
|
RotationDivProps,
|
||||||
|
RotationSpanProps,
|
||||||
|
} from '../Buttons/CommanderDamage';
|
||||||
import LifeCounterButton from '../Buttons/LifeCounterButton';
|
import LifeCounterButton from '../Buttons/LifeCounterButton';
|
||||||
import { OutlinedText } from '../Misc/OutlinedText';
|
import { OutlinedText } from '../Misc/OutlinedText';
|
||||||
|
|
||||||
const LifeCountainer = styled.div<{
|
const LifeContainer = twc.div<RotationDivProps>((props) => [
|
||||||
$rotation: Rotation;
|
'flex flex-grow relative w-full h-full justify-between items-center',
|
||||||
}>`
|
props.$rotation === Rotation.SideFlipped || props.$rotation === Rotation.Side
|
||||||
position: relative;
|
? 'flex-col-reverse'
|
||||||
display: flex;
|
: 'flex-row',
|
||||||
flex-direction: row;
|
]);
|
||||||
flex-grow: 1;
|
|
||||||
width: 100%;
|
|
||||||
height: 100%;
|
|
||||||
justify-content: space-between;
|
|
||||||
align-items: center;
|
|
||||||
|
|
||||||
${(props) => {
|
const LifeCounterTextContainer = twc.div<RotationDivProps>((props) => [
|
||||||
if (
|
'absolute m-0 p-0 pointer-events-none select-none webkit-user-select-none',
|
||||||
props.$rotation === Rotation.SideFlipped ||
|
props.$rotation === Rotation.SideFlipped || props.$rotation === Rotation.Side
|
||||||
props.$rotation === Rotation.Side
|
? 'w-full h-2/3'
|
||||||
) {
|
: 'w-2/3 h-full',
|
||||||
return css`
|
]);
|
||||||
flex-direction: column-reverse;
|
|
||||||
`;
|
const TextWrapper = twc.div`
|
||||||
}
|
flex
|
||||||
}}
|
absolute
|
||||||
|
justify-center
|
||||||
|
items-center
|
||||||
|
w-full
|
||||||
|
h-full
|
||||||
|
z-[-1]
|
||||||
`;
|
`;
|
||||||
|
|
||||||
const LifeCounterTextContainer = styled.div<{
|
const RecentDifference = twc.div<RotationSpanProps>((props) => [
|
||||||
$rotation: Rotation;
|
'absolute min-w-[20vmin] drop-shadow-none text-center bg-interface-recentDifference-background tabular-nums rounded-full p-[6px 12px] text-[8vmin] text-interface-recentDifference-text animate-fadeOut',
|
||||||
}>`
|
props.$rotation === Rotation.SideFlipped || props.$rotation === Rotation.Side
|
||||||
position: absolute;
|
? 'top-1/3 translate-x-1/4 translate-y-1/2 rotate-[270deg]'
|
||||||
width: 60%;
|
: 'top-1/4 left-[50%] -translate-x-1/2',
|
||||||
height: 100%;
|
]);
|
||||||
margin: 0;
|
|
||||||
padding: 0;
|
|
||||||
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`
|
|
||||||
width: 100%;
|
|
||||||
height: 60%;
|
|
||||||
`;
|
|
||||||
}
|
|
||||||
}}
|
|
||||||
`;
|
|
||||||
|
|
||||||
const TextWrapper = styled.div`
|
|
||||||
display: flex;
|
|
||||||
position: absolute;
|
|
||||||
justify-content: center;
|
|
||||||
align-items: center;
|
|
||||||
width: 100%;
|
|
||||||
height: 100%;
|
|
||||||
z-index: -1;
|
|
||||||
`;
|
|
||||||
|
|
||||||
const fadeOut = keyframes`
|
|
||||||
0% {
|
|
||||||
opacity: 1;
|
|
||||||
}
|
|
||||||
33% {
|
|
||||||
opacity: 0.6;
|
|
||||||
}
|
|
||||||
100% {
|
|
||||||
opacity: 0;
|
|
||||||
}
|
|
||||||
`;
|
|
||||||
|
|
||||||
export const RecentDifference = styled.span<{ $rotation: Rotation }>`
|
|
||||||
position: absolute;
|
|
||||||
top: 40%;
|
|
||||||
left: 50%;
|
|
||||||
transform: translate(-50%, -50%);
|
|
||||||
min-width: 15vmin;
|
|
||||||
text-shadow: none;
|
|
||||||
text-align: center;
|
|
||||||
|
|
||||||
background-color: rgba(255, 255, 255, 0.6);
|
|
||||||
font-variant-numeric: tabular-nums;
|
|
||||||
border-radius: 10vmin;
|
|
||||||
padding: 5px 10px;
|
|
||||||
font-size: 8vmin;
|
|
||||||
color: #333333;
|
|
||||||
animation: ${fadeOut} 3s 1s ease-out forwards;
|
|
||||||
|
|
||||||
${(props) => {
|
|
||||||
if (
|
|
||||||
props.$rotation === Rotation.SideFlipped ||
|
|
||||||
props.$rotation === Rotation.Side
|
|
||||||
) {
|
|
||||||
return css`
|
|
||||||
top: 27%;
|
|
||||||
left: 30%;
|
|
||||||
transform: translate(-50%, -50%);
|
|
||||||
rotate: 270deg;
|
|
||||||
`;
|
|
||||||
}
|
|
||||||
}}
|
|
||||||
`;
|
|
||||||
|
|
||||||
type HealthProps = {
|
type HealthProps = {
|
||||||
player: Player;
|
player: Player;
|
||||||
@@ -121,28 +49,13 @@ type HealthProps = {
|
|||||||
|
|
||||||
const Health = ({
|
const Health = ({
|
||||||
player,
|
player,
|
||||||
rotation,
|
|
||||||
handleLifeChange,
|
handleLifeChange,
|
||||||
differenceKey,
|
differenceKey,
|
||||||
recentDifference,
|
recentDifference,
|
||||||
}: HealthProps) => {
|
}: HealthProps) => {
|
||||||
const [showStartingPlayer, setShowStartingPlayer] = useState(
|
|
||||||
localStorage.getItem('playing') === 'true'
|
|
||||||
);
|
|
||||||
const [fontSize, setFontSize] = useState(16);
|
const [fontSize, setFontSize] = useState(16);
|
||||||
const textContainerRef = useRef<HTMLDivElement | null>(null);
|
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(() => {
|
useEffect(() => {
|
||||||
if (!textContainerRef.current) {
|
if (!textContainerRef.current) {
|
||||||
return;
|
return;
|
||||||
@@ -151,7 +64,6 @@ const Health = ({
|
|||||||
const textContainer = textContainerRef.current;
|
const textContainer = textContainerRef.current;
|
||||||
const resizeObserver = new ResizeObserver(() => {
|
const resizeObserver = new ResizeObserver(() => {
|
||||||
const calcFontSize = calculateFontSize(textContainer);
|
const calcFontSize = calculateFontSize(textContainer);
|
||||||
console.log(calcFontSize);
|
|
||||||
setFontSize(calcFontSize);
|
setFontSize(calcFontSize);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -172,12 +84,13 @@ const Health = ({
|
|||||||
}, [textContainerRef]);
|
}, [textContainerRef]);
|
||||||
|
|
||||||
const calculateFontSize = (container: HTMLDivElement) => {
|
const calculateFontSize = (container: HTMLDivElement) => {
|
||||||
const isSide =
|
const widthRatio = player.isSide
|
||||||
rotation === Rotation.SideFlipped || rotation === Rotation.Side;
|
? container.clientHeight
|
||||||
|
: container.clientWidth;
|
||||||
|
|
||||||
const widthRatio = isSide ? container.clientHeight : container.clientWidth;
|
const heightRatio = player.isSide
|
||||||
|
? container.clientWidth
|
||||||
const heightRatio = isSide ? container.clientWidth : container.clientHeight;
|
: container.clientHeight;
|
||||||
|
|
||||||
const minRatio = Math.min(widthRatio, heightRatio);
|
const minRatio = Math.min(widthRatio, heightRatio);
|
||||||
|
|
||||||
@@ -189,11 +102,10 @@ const Health = ({
|
|||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<LifeCountainer $rotation={player.settings.rotation}>
|
<LifeContainer $rotation={player.settings.rotation}>
|
||||||
<LifeCounterButton
|
<LifeCounterButton
|
||||||
lifeTotal={player.lifeTotal}
|
player={player}
|
||||||
setLifeTotal={handleLifeChange}
|
setLifeTotal={handleLifeChange}
|
||||||
rotation={player.settings.rotation}
|
|
||||||
operation="subtract"
|
operation="subtract"
|
||||||
increment={-1}
|
increment={-1}
|
||||||
/>
|
/>
|
||||||
@@ -221,13 +133,12 @@ const Health = ({
|
|||||||
</LifeCounterTextContainer>
|
</LifeCounterTextContainer>
|
||||||
</TextWrapper>
|
</TextWrapper>
|
||||||
<LifeCounterButton
|
<LifeCounterButton
|
||||||
lifeTotal={player.lifeTotal}
|
player={player}
|
||||||
setLifeTotal={handleLifeChange}
|
setLifeTotal={handleLifeChange}
|
||||||
rotation={player.settings.rotation}
|
|
||||||
operation="add"
|
operation="add"
|
||||||
increment={1}
|
increment={1}
|
||||||
/>
|
/>
|
||||||
</LifeCountainer>
|
</LifeContainer>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -1,137 +1,80 @@
|
|||||||
import { useEffect, useState } from 'react';
|
import { useEffect, useRef, useState } from 'react';
|
||||||
import styled, { css, keyframes } from 'styled-components';
|
import { useSwipeable } from 'react-swipeable';
|
||||||
import { theme } from '../../Data/theme';
|
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 { Player, Rotation } from '../../Types/Player';
|
||||||
|
import { checkContrast } from '../../Utils/checkContrast';
|
||||||
|
import {
|
||||||
|
RotationButtonProps,
|
||||||
|
RotationDivProps,
|
||||||
|
} from '../Buttons/CommanderDamage';
|
||||||
import { LoseGameButton } from '../Buttons/LoseButton';
|
import { LoseGameButton } from '../Buttons/LoseButton';
|
||||||
import SettingsButton from '../Buttons/SettingsButton';
|
|
||||||
import CommanderDamageBar from '../Counters/CommanderDamageBar';
|
import CommanderDamageBar from '../Counters/CommanderDamageBar';
|
||||||
import ExtraCountersBar from '../Counters/ExtraCountersBar';
|
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 Health from './Health';
|
||||||
import { usePlayers } from '../../Hooks/usePlayers';
|
|
||||||
import { useGlobalSettings } from '../../Hooks/useGlobalSettings';
|
|
||||||
|
|
||||||
const LifeCounterContentWrapper = styled.div<{
|
const SettingsButtonTwc = twc.button<RotationButtonProps>((props) => [
|
||||||
$backgroundColor: string;
|
'absolute flex-grow border-none outline-none cursor-pointer bg-transparent z-[1] select-none webkit-user-select-none',
|
||||||
}>`
|
props.$rotation === Rotation.Side || props.$rotation === Rotation.SideFlipped
|
||||||
position: relative;
|
? `right-auto top-[1vmax] left-[27%]`
|
||||||
display: flex;
|
: 'top-1/4 right-[1vmax]',
|
||||||
flex-grow: 1;
|
]);
|
||||||
flex-direction: column;
|
|
||||||
align-items: center;
|
|
||||||
height: 100%;
|
|
||||||
width: 100%;
|
|
||||||
background-color: ${(props) => props.$backgroundColor || 'antiquewhite'};
|
|
||||||
@media (orientation: landscape) {
|
|
||||||
max-width: 100vmax;
|
|
||||||
max-height: 100vmin;
|
|
||||||
}
|
|
||||||
|
|
||||||
overflow: hidden;
|
type SettingsButtonProps = {
|
||||||
`;
|
onClick: () => void;
|
||||||
|
rotation: Rotation;
|
||||||
|
color: string;
|
||||||
|
};
|
||||||
|
|
||||||
const LifeCounterWrapper = styled.div<{
|
const SettingsButton = ({ onClick, rotation, color }: SettingsButtonProps) => {
|
||||||
$rotation: Rotation;
|
const [iconColor, setIconColor] = useState<'dark' | 'light'>('dark');
|
||||||
}>`
|
|
||||||
position: relative;
|
|
||||||
display: flex;
|
|
||||||
flex-direction: column;
|
|
||||||
align-items: center;
|
|
||||||
width: 100%;
|
|
||||||
height: 100%;
|
|
||||||
|
|
||||||
z-index: 1;
|
useEffect(() => {
|
||||||
|
const contrast = checkContrast(color, '#00000080');
|
||||||
|
|
||||||
${(props) => {
|
if (contrast === 'Fail') {
|
||||||
if (
|
setIconColor('light');
|
||||||
props.$rotation === Rotation.SideFlipped ||
|
} else {
|
||||||
props.$rotation === Rotation.Side
|
setIconColor('dark');
|
||||||
) {
|
|
||||||
return css`
|
|
||||||
flex-direction: row;
|
|
||||||
rotate: ${props.$rotation - 90}deg;
|
|
||||||
`;
|
|
||||||
}
|
}
|
||||||
|
}, [color]);
|
||||||
|
|
||||||
return css`
|
return (
|
||||||
flex-direction: column;
|
<SettingsButtonTwc
|
||||||
rotate: ${props.$rotation}deg;
|
onClick={onClick}
|
||||||
`;
|
$rotation={rotation}
|
||||||
}}
|
aria-label={`Settings`}
|
||||||
`;
|
>
|
||||||
|
<Cog
|
||||||
|
size="5vmin"
|
||||||
|
data-contrast={iconColor}
|
||||||
|
className="data-[contrast=dark]:text-icons-dark data-[contrast=light]:text-icons-light"
|
||||||
|
/>
|
||||||
|
</SettingsButtonTwc>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
const PlayerNoticeWrapper = styled.div<{
|
const LifeCounterContentWrapper = twc.div`
|
||||||
$rotation: Rotation;
|
relative flex flex-grow flex-col items-center w-full h-full overflow-hidden`;
|
||||||
$backgroundColor: string;
|
|
||||||
}>`
|
|
||||||
z-index: 1;
|
|
||||||
display: flex;
|
|
||||||
position: absolute;
|
|
||||||
width: 100%;
|
|
||||||
height: 100%;
|
|
||||||
justify-content: center;
|
|
||||||
align-items: center;
|
|
||||||
background: ${(props) => props.$backgroundColor};
|
|
||||||
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) => {
|
const LifeCounterWrapper = twc.div<RotationDivProps>((props) => [
|
||||||
if (
|
'relative flex items-center w-full h-full z-[1]',
|
||||||
props.$rotation === Rotation.SideFlipped ||
|
props.$rotation === Rotation.SideFlipped || props.$rotation === Rotation.Side
|
||||||
props.$rotation === Rotation.Side
|
? `flex-row`
|
||||||
) {
|
: `flex-col`,
|
||||||
return css`
|
]);
|
||||||
rotate: ${props.$rotation - 90}deg;
|
|
||||||
`;
|
|
||||||
}
|
|
||||||
}}
|
|
||||||
`;
|
|
||||||
|
|
||||||
const DynamicText = styled.div<{ $rotation: Rotation }>`
|
const PlayerLostWrapper = twc.div<RotationDivProps>((props) => [
|
||||||
font-size: 8vmin;
|
'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) => {
|
props.$rotation === Rotation.SideFlipped || props.$rotation === Rotation.Side
|
||||||
if (
|
? `rotate-[${props.$rotation - 90}deg]`
|
||||||
props.$rotation === Rotation.SideFlipped ||
|
: '',
|
||||||
props.$rotation === Rotation.Side
|
]);
|
||||||
) {
|
|
||||||
return css`
|
|
||||||
rotate: ${props.$rotation - 180}deg;
|
|
||||||
`;
|
|
||||||
}
|
|
||||||
}}
|
|
||||||
`;
|
|
||||||
|
|
||||||
const fadeOut = keyframes`
|
|
||||||
0% {
|
|
||||||
opacity: 1;
|
|
||||||
}
|
|
||||||
33% {
|
|
||||||
opacity: 0.6;
|
|
||||||
}
|
|
||||||
100% {
|
|
||||||
opacity: 0;
|
|
||||||
}
|
|
||||||
`;
|
|
||||||
|
|
||||||
export const RecentDifference = styled.span`
|
|
||||||
position: absolute;
|
|
||||||
top: 40%;
|
|
||||||
left: 50%;
|
|
||||||
transform: translate(-50%, -50%);
|
|
||||||
text-shadow: none;
|
|
||||||
background-color: rgba(255, 255, 255, 0.6);
|
|
||||||
font-variant-numeric: tabular-nums;
|
|
||||||
border-radius: 50%;
|
|
||||||
padding: 5px 10px;
|
|
||||||
font-size: 8vmin;
|
|
||||||
color: #333333;
|
|
||||||
animation: ${fadeOut} 3s 1s ease-out forwards;
|
|
||||||
`;
|
|
||||||
|
|
||||||
const hasCommanderDamageReached21 = (player: Player) => {
|
const hasCommanderDamageReached21 = (player: Player) => {
|
||||||
const commanderDamageTotals = player.commanderDamage.map(
|
const commanderDamageTotals = player.commanderDamage.map(
|
||||||
@@ -163,36 +106,81 @@ const playerCanLose = (player: Player) => {
|
|||||||
type LifeCounterProps = {
|
type LifeCounterProps = {
|
||||||
player: Player;
|
player: Player;
|
||||||
opponents: Player[];
|
opponents: Player[];
|
||||||
|
isStartingPlayer?: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const RECENT_DIFFERENCE_TTL = 3_000;
|
||||||
|
|
||||||
const LifeCounter = ({ player, opponents }: LifeCounterProps) => {
|
const LifeCounter = ({ player, opponents }: LifeCounterProps) => {
|
||||||
const { updatePlayer, updateLifeTotal } = usePlayers();
|
const { updatePlayer, updateLifeTotal } = usePlayers();
|
||||||
const { settings } = useGlobalSettings();
|
const { settings, playing } = useGlobalSettings();
|
||||||
|
const recentDifferenceTimerRef = useRef<NodeJS.Timeout | undefined>(
|
||||||
|
undefined
|
||||||
|
);
|
||||||
|
|
||||||
const [showPlayerMenu, setShowPlayerMenu] = useState(false);
|
const [showPlayerMenu, setShowPlayerMenu] = useState(false);
|
||||||
const [recentDifference, setRecentDifference] = useState(0);
|
const [recentDifference, setRecentDifference] = useState(0);
|
||||||
const [differenceKey, setDifferenceKey] = useState(Date.now());
|
const [differenceKey, setDifferenceKey] = useState(Date.now());
|
||||||
|
const [isLandscape, setIsLandscape] = useState(false);
|
||||||
|
|
||||||
|
const calcRot = player.isSide
|
||||||
|
? player.settings.rotation - 180
|
||||||
|
: player.settings.rotation;
|
||||||
|
|
||||||
|
const rotationAngle = isLandscape ? calcRot : calcRot + 90;
|
||||||
|
|
||||||
|
const handlers = useSwipeable({
|
||||||
|
trackMouse: true,
|
||||||
|
onSwipedDown: (e) => {
|
||||||
|
e.event.stopPropagation();
|
||||||
|
analytics.trackEvent('open_player_menu_swipe');
|
||||||
|
setShowPlayerMenu(true);
|
||||||
|
},
|
||||||
|
onSwipedUp: (e) => {
|
||||||
|
e.event.stopPropagation();
|
||||||
|
analytics.trackEvent('close_player_menu_swipe');
|
||||||
|
setShowPlayerMenu(false);
|
||||||
|
},
|
||||||
|
|
||||||
|
swipeDuration: 500,
|
||||||
|
onSwiping: (e) => e.event.stopPropagation(),
|
||||||
|
rotationAngle,
|
||||||
|
});
|
||||||
|
const analytics = useAnalytics();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const timer = setTimeout(() => {
|
if (recentDifference === 0) {
|
||||||
setRecentDifference(0);
|
clearTimeout(recentDifferenceTimerRef.current);
|
||||||
}, 3_000);
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
return () => clearTimeout(timer);
|
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]);
|
}, [recentDifference]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (player.showStartingPlayer) {
|
const resizeObserver = new ResizeObserver(() => {
|
||||||
const playingTimer = setTimeout(() => {
|
if (document.body.clientWidth > document.body.clientHeight)
|
||||||
localStorage.setItem('playing', 'true');
|
setIsLandscape(true);
|
||||||
player.showStartingPlayer = false;
|
else setIsLandscape(false);
|
||||||
updatePlayer(player);
|
return () => {
|
||||||
}, 3_000);
|
// Cleanup: disconnect the ResizeObserver when the component unmounts.
|
||||||
|
resizeObserver.disconnect();
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
return () => clearTimeout(playingTimer);
|
resizeObserver.observe(document.body);
|
||||||
}
|
|
||||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
// 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.SideFlipped ||
|
||||||
player.settings.rotation === Rotation.Side;
|
player.settings.rotation === Rotation.Side;
|
||||||
@@ -208,40 +196,46 @@ const LifeCounter = ({ player, opponents }: LifeCounterProps) => {
|
|||||||
updatePlayer(updatedPlayer);
|
updatePlayer(updatedPlayer);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const calcRotation =
|
||||||
|
player.settings.rotation === Rotation.SideFlipped ||
|
||||||
|
player.settings.rotation === Rotation.Side
|
||||||
|
? player.settings.rotation - 90
|
||||||
|
: player.settings.rotation;
|
||||||
|
|
||||||
|
const amountOfPlayers = opponents.length + 1;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<LifeCounterContentWrapper $backgroundColor={player.color}>
|
<LifeCounterContentWrapper style={{ background: player.color }}>
|
||||||
<LifeCounterWrapper $rotation={player.settings.rotation}>
|
<LifeCounterWrapper
|
||||||
{settings.showStartingPlayer &&
|
$rotation={player.settings.rotation}
|
||||||
player.isStartingPlayer &&
|
style={{ rotate: `${calcRotation}deg` }}
|
||||||
player.showStartingPlayer && (
|
{...handlers}
|
||||||
<PlayerNoticeWrapper
|
>
|
||||||
$rotation={player.settings.rotation}
|
{amountOfPlayers > 1 &&
|
||||||
$backgroundColor={theme.palette.primary.main}
|
!playing &&
|
||||||
>
|
settings.showStartingPlayer &&
|
||||||
<DynamicText $rotation={player.settings.rotation}>
|
player.isStartingPlayer && <StartingPlayerCard player={player} />}
|
||||||
You start!
|
|
||||||
</DynamicText>
|
|
||||||
</PlayerNoticeWrapper>
|
|
||||||
)}
|
|
||||||
|
|
||||||
{player.hasLost && (
|
{player.hasLost && (
|
||||||
<PlayerNoticeWrapper
|
<PlayerLostWrapper $rotation={player.settings.rotation} />
|
||||||
$rotation={player.settings.rotation}
|
|
||||||
$backgroundColor={'#00000070'}
|
|
||||||
/>
|
|
||||||
)}
|
)}
|
||||||
|
|
||||||
<CommanderDamageBar
|
<CommanderDamageBar
|
||||||
opponents={opponents}
|
opponents={opponents}
|
||||||
player={player}
|
player={player}
|
||||||
key={player.index}
|
key={player.index}
|
||||||
handleLifeChange={handleLifeChange}
|
handleLifeChange={handleLifeChange}
|
||||||
/>
|
/>
|
||||||
<SettingsButton
|
{settings.showPlayerMenuCog && (
|
||||||
onClick={() => {
|
<SettingsButton
|
||||||
setShowPlayerMenu(!showPlayerMenu);
|
onClick={() => {
|
||||||
}}
|
analytics.trackEvent('open_player_menu_button');
|
||||||
rotation={player.settings.rotation}
|
setShowPlayerMenu(!showPlayerMenu);
|
||||||
/>
|
}}
|
||||||
|
rotation={player.settings.rotation}
|
||||||
|
color={player.color}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
{playerCanLose(player) && (
|
{playerCanLose(player) && (
|
||||||
<LoseGameButton
|
<LoseGameButton
|
||||||
rotation={player.settings.rotation}
|
rotation={player.settings.rotation}
|
||||||
@@ -256,11 +250,13 @@ const LifeCounter = ({ player, opponents }: LifeCounterProps) => {
|
|||||||
handleLifeChange={handleLifeChange}
|
handleLifeChange={handleLifeChange}
|
||||||
/>
|
/>
|
||||||
<ExtraCountersBar player={player} />
|
<ExtraCountersBar player={player} />
|
||||||
</LifeCounterWrapper>
|
|
||||||
|
|
||||||
{showPlayerMenu && (
|
<PlayerMenu
|
||||||
<PlayerMenu player={player} setShowPlayerMenu={setShowPlayerMenu} />
|
isShown={showPlayerMenu}
|
||||||
)}
|
player={player}
|
||||||
|
setShowPlayerMenu={setShowPlayerMenu}
|
||||||
|
/>
|
||||||
|
</LifeCounterWrapper>
|
||||||
</LifeCounterContentWrapper>
|
</LifeCounterContentWrapper>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,47 +1,37 @@
|
|||||||
import styled from 'styled-components';
|
import { twc } from 'react-twc';
|
||||||
import { useGlobalSettings } from '../Hooks/useGlobalSettings';
|
import { useGlobalSettings } from '../Hooks/useGlobalSettings';
|
||||||
import StartMenu from './Views/StartMenu/StartMenu';
|
|
||||||
import { Play } from './Views/Play';
|
import { Play } from './Views/Play';
|
||||||
|
import StartMenu from './Views/StartMenu/StartMenu';
|
||||||
|
|
||||||
const StartWrapper = styled.div`
|
const StartWrapper = twc.div`max-w-fit max-h-fit`;
|
||||||
max-width: fit-content;
|
|
||||||
max-height: fit-content;
|
|
||||||
`;
|
|
||||||
|
|
||||||
const PlayWrapper = styled.div`
|
const PlayWrapper = twc.div`relative z-0 max-w-fit max-h-fit portrait:rotate-90`;
|
||||||
position: relative;
|
|
||||||
z-index: 0;
|
|
||||||
max-width: fit-content;
|
|
||||||
max-height: fit-content;
|
|
||||||
@media (orientation: portrait) {
|
|
||||||
rotate: 90deg;
|
|
||||||
}
|
|
||||||
`;
|
|
||||||
|
|
||||||
const EmergencyResetButton = styled.button`
|
const EmergencyResetButton = () => {
|
||||||
width: 100vmax;
|
const { goToStart } = useGlobalSettings();
|
||||||
height: 100vmin;
|
|
||||||
font-size: 4vmax;
|
const EmergencyResetButton = twc.button`w-[100dvmax] h-[100dvmin] absolute top-0 z-[-1] bg-background-default`;
|
||||||
position: absolute;
|
const Paragraph = twc.p`text-[4vmax] text-text-secondary`;
|
||||||
top: 0;
|
|
||||||
z-index: -1;
|
return (
|
||||||
background-color: #4e6815;
|
<EmergencyResetButton onClick={goToStart}>
|
||||||
`;
|
<Paragraph>If you can see this, something is wrong.</Paragraph>
|
||||||
|
<Paragraph>Press screen to go to start.</Paragraph>
|
||||||
|
<br />
|
||||||
|
<Paragraph>If the issue persists, please inform me.</Paragraph>
|
||||||
|
</EmergencyResetButton>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
export const LifeTrinket = () => {
|
export const LifeTrinket = () => {
|
||||||
const { showPlay, goToStart, initialGameSettings } = useGlobalSettings();
|
const { showPlay, initialGameSettings } = useGlobalSettings();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
{showPlay && initialGameSettings ? (
|
{showPlay && initialGameSettings ? (
|
||||||
<PlayWrapper>
|
<PlayWrapper>
|
||||||
<Play />
|
<Play />
|
||||||
<EmergencyResetButton onClick={goToStart}>
|
<EmergencyResetButton />
|
||||||
<p>If you can see this, something is wrong.</p>
|
|
||||||
<p>Press screen to go to start.</p>
|
|
||||||
<br />
|
|
||||||
<p>If the issue persists, please inform me.</p>
|
|
||||||
</EmergencyResetButton>
|
|
||||||
</PlayWrapper>
|
</PlayWrapper>
|
||||||
) : (
|
) : (
|
||||||
<StartWrapper>
|
<StartWrapper>
|
||||||
|
|||||||
@@ -1,21 +1,12 @@
|
|||||||
import { Modal } from '@mui/material';
|
import { Modal } from '@mui/material';
|
||||||
import { theme } from '../../Data/theme';
|
import { twc } from 'react-twc';
|
||||||
import styled from 'styled-components';
|
import { Separator } from './Separator';
|
||||||
|
import { Paragraph } from './TextComponents';
|
||||||
|
import { Cross } from '../../Icons/generated';
|
||||||
|
import { useEffect } from 'react';
|
||||||
|
import { useAnalytics } from '../../Hooks/useAnalytics';
|
||||||
|
|
||||||
export const ModalWrapper = styled.div`
|
export const ModalWrapper = twc.div`absolute top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2 h-[85vh] bg-background-default p-4 overflow-scroll rounded-2xl border-none text-text-primary w-[95vw] max-w-[548px]`;
|
||||||
position: absolute;
|
|
||||||
top: 50%;
|
|
||||||
left: 50%;
|
|
||||||
transform: translate(-50%, -50%);
|
|
||||||
width: 80vw;
|
|
||||||
height: 85vh;
|
|
||||||
background-color: ${theme.palette.background.default};
|
|
||||||
padding: 1rem;
|
|
||||||
overflow: scroll;
|
|
||||||
border-radius: 1rem;
|
|
||||||
color: ${theme.palette.text.primary};
|
|
||||||
border: none;
|
|
||||||
`;
|
|
||||||
|
|
||||||
type InfoModalProps = {
|
type InfoModalProps = {
|
||||||
isOpen: boolean;
|
isOpen: boolean;
|
||||||
@@ -23,74 +14,98 @@ type InfoModalProps = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const InfoModal = ({ isOpen, closeModal }: InfoModalProps) => {
|
export const InfoModal = ({ isOpen, closeModal }: InfoModalProps) => {
|
||||||
|
const analytics = useAnalytics();
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (!isOpen) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
analytics.trackEvent('info_opened');
|
||||||
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
|
}, [isOpen]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Modal open={isOpen} onClose={closeModal}>
|
<Modal
|
||||||
<ModalWrapper>
|
open={isOpen}
|
||||||
<div>
|
onClose={closeModal}
|
||||||
<h2 style={{ textAlign: 'center' }}>📋 Usage Guide</h2>
|
style={{ display: 'flex', justifyContent: 'center' }}
|
||||||
<p>
|
>
|
||||||
There are some controls that you might not know about, so here's a
|
<>
|
||||||
short list of them.
|
<div className="flex justify-center items-center relative w-full max-w-[532px]">
|
||||||
</p>
|
<button
|
||||||
|
onClick={closeModal}
|
||||||
<h3>Life counter</h3>
|
className="flex absolute top-12 right-0 z-10 w-10 h-10 bg-primary-main items-center justify-center rounded-full border-solid border-primary-dark border-2"
|
||||||
<ul>
|
|
||||||
<li>
|
|
||||||
<strong>Tap</strong> on a player's + or - button to add or
|
|
||||||
subtract <strong>1 life</strong>.
|
|
||||||
</li>
|
|
||||||
<li>
|
|
||||||
<strong>Long press</strong> on a player's + or - button to add or
|
|
||||||
subtract <strong>10 life</strong>.
|
|
||||||
</li>
|
|
||||||
</ul>
|
|
||||||
|
|
||||||
<h3>Commander damage and other counters</h3>
|
|
||||||
<ul>
|
|
||||||
<li>
|
|
||||||
<strong>Tap</strong> on the counter to add{' '}
|
|
||||||
<strong>1 counter</strong>.
|
|
||||||
</li>
|
|
||||||
<li>
|
|
||||||
<strong>Long press</strong> on the counter to subtract{' '}
|
|
||||||
<strong>1 counter</strong>.
|
|
||||||
</li>
|
|
||||||
</ul>
|
|
||||||
|
|
||||||
<h3>Other</h3>
|
|
||||||
<p>
|
|
||||||
When a player is <strong>at or below 0 life</strong>, has taken{' '}
|
|
||||||
<strong>21 or more Commander Damage</strong> or has{' '}
|
|
||||||
<strong>10 or more poison counters</strong>, a button with a skull
|
|
||||||
will appear on that player's card.
|
|
||||||
</p>
|
|
||||||
<p>
|
|
||||||
Tap on the button to mark that player as lost, dimming their player
|
|
||||||
card.
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
<br />
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
textAlign: 'center',
|
|
||||||
marginTop: '1rem',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
Visit my
|
|
||||||
<a
|
|
||||||
href="https://github.com/Vikeo/LifeTrinket"
|
|
||||||
target="_blank"
|
|
||||||
style={{
|
|
||||||
textDecoration: 'none',
|
|
||||||
color: theme.palette.primary.light,
|
|
||||||
}}
|
|
||||||
>
|
>
|
||||||
{' '}
|
<Cross size="16px" className="text-text-primary " />
|
||||||
GitHub{' '}
|
</button>
|
||||||
</a>
|
|
||||||
for more info about this web app.
|
|
||||||
</div>
|
</div>
|
||||||
</ModalWrapper>
|
<ModalWrapper>
|
||||||
|
<div>
|
||||||
|
<h2 className="text-2xl text-center mb-4">📋 Usage Guide</h2>
|
||||||
|
<Separator height="1px" />
|
||||||
|
<Paragraph className="my-4">
|
||||||
|
There are some controls that you might not know about, so here's a
|
||||||
|
short list of them.
|
||||||
|
</Paragraph>
|
||||||
|
<h3 className="text-lg font-bold mb-2">Life counter</h3>
|
||||||
|
<ul className="list-disc ml-6 mb-4">
|
||||||
|
<li>
|
||||||
|
<strong>Tap</strong> on a player's + or - button to add or
|
||||||
|
subtract <strong>1 life</strong>.
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
<strong>Long press</strong> on a player's + or - button to add
|
||||||
|
or subtract <strong>10 life</strong>.
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
<h3 className="text-lg font-bold mb-2">
|
||||||
|
Commander damage and other counters
|
||||||
|
</h3>
|
||||||
|
<ul className="list-disc ml-6 mb-4">
|
||||||
|
<li>
|
||||||
|
<strong>Tap</strong> on the counter to add{' '}
|
||||||
|
<strong>1 counter</strong>.
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
<strong>Long press</strong> on the counter to subtract{' '}
|
||||||
|
<strong>1 counter</strong>.
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
<h3 className="text-lg font-bold mb-2">Other functionality</h3>
|
||||||
|
<ul className="list-disc ml-6">
|
||||||
|
<li>
|
||||||
|
<Paragraph className="mb-1">
|
||||||
|
When a player is <strong>at or below 0 life</strong>, has
|
||||||
|
taken <strong>21 or more Commander Damage</strong> or has{' '}
|
||||||
|
<strong>10 or more poison counters</strong>, a button with a
|
||||||
|
skull will appear on that player's card. Tapping it will dim
|
||||||
|
the player's card.
|
||||||
|
</Paragraph>
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
<Paragraph className="mb-4">
|
||||||
|
Swiping <strong>down</strong> on a player's card will show
|
||||||
|
that player's settings menu.
|
||||||
|
</Paragraph>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
<div className="text-center mt-4">
|
||||||
|
Visit my{' '}
|
||||||
|
<a
|
||||||
|
href="https://github.com/Vikeo/LifeTrinket"
|
||||||
|
target="_blank"
|
||||||
|
className="text-text-secondary underline"
|
||||||
|
>
|
||||||
|
GitHub
|
||||||
|
</a>{' '}
|
||||||
|
for more info about this web app.
|
||||||
|
</div>
|
||||||
|
</ModalWrapper>
|
||||||
|
</>
|
||||||
</Modal>
|
</Modal>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,58 +1,30 @@
|
|||||||
import styled, { css } from 'styled-components';
|
|
||||||
import { theme } from '../../Data/theme';
|
|
||||||
import { Rotation } from '../../Types/Player';
|
import { Rotation } from '../../Types/Player';
|
||||||
|
|
||||||
const Container = styled.div`
|
import { twc } from 'react-twc';
|
||||||
display: flex;
|
//TODO Create provider for this
|
||||||
position: relative;
|
import tailwindConfig from './../../../tailwind.config';
|
||||||
width: 100%;
|
import resolveConfig from 'tailwindcss/resolveConfig';
|
||||||
height: 100%;
|
|
||||||
align-items: center;
|
|
||||||
justify-content: center;
|
|
||||||
`;
|
|
||||||
|
|
||||||
const CenteredText = styled.div<{
|
const fullConfig = resolveConfig(tailwindConfig);
|
||||||
strokeWidth?: string;
|
|
||||||
strokeColor?: string;
|
|
||||||
fillColor?: string;
|
|
||||||
fontSize?: string;
|
|
||||||
fontWeight?: string;
|
|
||||||
$rotation?: Rotation;
|
|
||||||
}>`
|
|
||||||
position: absolute;
|
|
||||||
font-weight: ${(props) => props.fontWeight || ''};
|
|
||||||
font-variant-numeric: tabular-nums;
|
|
||||||
user-select: none;
|
|
||||||
-webkit-touch-callout: none;
|
|
||||||
-webkit-tap-highlight-color: transparent;
|
|
||||||
-moz-user-select: -moz-none;
|
|
||||||
-webkit-user-select: none;
|
|
||||||
-ms-user-select: none;
|
|
||||||
|
|
||||||
color: ${(props) => props.fillColor || theme.palette.common.black};
|
const Container = twc.div`
|
||||||
font-size: ${(props) => props.fontSize || '6vmin'};
|
flex
|
||||||
-webkit-text-stroke: ${(props) => props.strokeWidth || '1vmin'}${(props) => props.strokeColor || theme.palette.common.white};
|
relative
|
||||||
-webkit-text-fill-color: ${(props) =>
|
w-full
|
||||||
props.fillColor || theme.palette.common.black};
|
h-full
|
||||||
|
items-center
|
||||||
|
justify-center
|
||||||
|
`;
|
||||||
|
|
||||||
${(props) => {
|
const CenteredText = twc.div`absolute select-none text-common-black text-[6vmin] stroke-common-white
|
||||||
if (
|
webkit-user-select-none tabular-nums`;
|
||||||
props.$rotation === Rotation.SideFlipped ||
|
|
||||||
props.$rotation === Rotation.Side
|
|
||||||
) {
|
|
||||||
return css`
|
|
||||||
rotate: 270deg;
|
|
||||||
`;
|
|
||||||
}
|
|
||||||
}}
|
|
||||||
`;
|
|
||||||
|
|
||||||
const CenteredTextOutline = styled.span`
|
const CenteredTextOutline = twc.span`
|
||||||
position: absolute;
|
absolute
|
||||||
left: 0;
|
left-0
|
||||||
-webkit-text-stroke: 0;
|
stroke-none
|
||||||
pointer-events: none;
|
pointer-events-none
|
||||||
`;
|
`;
|
||||||
|
|
||||||
type OutlinedTextProps = {
|
type OutlinedTextProps = {
|
||||||
children?: React.ReactNode;
|
children?: React.ReactNode;
|
||||||
@@ -73,18 +45,33 @@ export const OutlinedText: React.FC<OutlinedTextProps> = ({
|
|||||||
fillColor,
|
fillColor,
|
||||||
rotation,
|
rotation,
|
||||||
}) => {
|
}) => {
|
||||||
|
const calcRotation =
|
||||||
|
rotation === Rotation.Side
|
||||||
|
? rotation - 180
|
||||||
|
: rotation === Rotation.SideFlipped
|
||||||
|
? rotation
|
||||||
|
: 0;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Container>
|
<Container>
|
||||||
<CenteredText
|
<CenteredText
|
||||||
fontSize={fontSize}
|
style={{
|
||||||
fontWeight={fontWeight}
|
fontSize,
|
||||||
strokeWidth={strokeWidth}
|
fontWeight,
|
||||||
strokeColor={strokeColor}
|
strokeWidth: strokeWidth || '1vmin',
|
||||||
fillColor={fillColor}
|
color: fillColor || fullConfig.theme.colors.common.black,
|
||||||
$rotation={rotation}
|
WebkitTextStroke: `${strokeWidth || '1vmin'} ${
|
||||||
|
strokeColor || fullConfig.theme.colors.common.white
|
||||||
|
}`,
|
||||||
|
WebkitTextFillColor:
|
||||||
|
fillColor || fullConfig.theme.colors.common.black,
|
||||||
|
rotate: `${calcRotation}deg`,
|
||||||
|
}}
|
||||||
>
|
>
|
||||||
{children}
|
{children}
|
||||||
<CenteredTextOutline aria-hidden>{children}</CenteredTextOutline>
|
<CenteredTextOutline aria-hidden style={{ WebkitTextStroke: 0 }}>
|
||||||
|
{children}
|
||||||
|
</CenteredTextOutline>
|
||||||
</CenteredText>
|
</CenteredText>
|
||||||
</Container>
|
</Container>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -1,13 +1,3 @@
|
|||||||
import styled from 'styled-components';
|
|
||||||
import { Spacer } from './Spacer';
|
|
||||||
|
|
||||||
const SeparatorContainer = styled.div<{ width?: string; height?: string }>`
|
|
||||||
width: ${(props) => props.width};
|
|
||||||
height: ${(props) => props.height};
|
|
||||||
background-color: #00000025;
|
|
||||||
border-radius: 50px;
|
|
||||||
`;
|
|
||||||
|
|
||||||
export const Separator = ({
|
export const Separator = ({
|
||||||
width = '100%',
|
width = '100%',
|
||||||
height = '100%',
|
height = '100%',
|
||||||
@@ -16,10 +6,9 @@ export const Separator = ({
|
|||||||
height?: string;
|
height?: string;
|
||||||
}) => {
|
}) => {
|
||||||
return (
|
return (
|
||||||
<>
|
<div
|
||||||
<Spacer height="0.5rem" />
|
className={`bg-common-white bg-opacity-30 rounded-full mt-2 mb-2`}
|
||||||
<SeparatorContainer width={width} height={height} />
|
style={{ width, height }}
|
||||||
<Spacer height="0.5rem" />
|
/>
|
||||||
</>
|
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,38 +1,24 @@
|
|||||||
import { Button, FormLabel, Modal, Switch } from '@mui/material';
|
import { Modal, Switch } from '@mui/material';
|
||||||
import { ModalWrapper } from './InfoModal';
|
import { useEffect } from 'react';
|
||||||
import styled from 'styled-components';
|
import { twc } from 'react-twc';
|
||||||
import { useGlobalSettings } from '../../Hooks/useGlobalSettings';
|
import { useGlobalSettings } from '../../Hooks/useGlobalSettings';
|
||||||
import { theme } from '../../Data/theme';
|
import { Cross } from '../../Icons/generated';
|
||||||
|
import { PreStartMode } from '../../Types/Settings';
|
||||||
|
import { ModalWrapper } from './InfoModal';
|
||||||
import { Separator } from './Separator';
|
import { Separator } from './Separator';
|
||||||
import { Paragraph } from './TextComponents';
|
import { Paragraph } from './TextComponents';
|
||||||
|
import { useAnalytics } from '../../Hooks/useAnalytics';
|
||||||
|
|
||||||
const SettingContainer = styled.div`
|
const SettingContainer = twc.div`w-full flex flex-col mb-2`;
|
||||||
width: 100%;
|
|
||||||
display: flex;
|
|
||||||
flex-direction: column;
|
|
||||||
`;
|
|
||||||
|
|
||||||
const ToggleContainer = styled.div`
|
const ToggleContainer = twc.div`flex flex-row justify-between items-center -mb-1`;
|
||||||
display: flex;
|
|
||||||
flex-direction: row;
|
|
||||||
align-items: center;
|
|
||||||
justify-content: space-between;
|
|
||||||
`;
|
|
||||||
|
|
||||||
const Container = styled.div`
|
const Container = twc.div`flex flex-col items-start w-full`;
|
||||||
display: flex;
|
|
||||||
flex-direction: column;
|
|
||||||
align-items: center;
|
|
||||||
width: 100%;
|
|
||||||
`;
|
|
||||||
|
|
||||||
const Description = styled.p`
|
const Description = twc.p`mr-16 text-xs text-left text-text-secondary`;
|
||||||
margin-top: -0.25rem;
|
|
||||||
margin-right: 3.5rem;
|
const baseGithubReleasesUrl =
|
||||||
font-size: 0.8rem;
|
'https://github.com/Vikeo/LifeTrinket/releases/tag/';
|
||||||
text-align: left;
|
|
||||||
color: ${theme.palette.text.secondary};
|
|
||||||
`;
|
|
||||||
|
|
||||||
type SettingsModalProps = {
|
type SettingsModalProps = {
|
||||||
isOpen: boolean;
|
isOpen: boolean;
|
||||||
@@ -40,94 +26,277 @@ type SettingsModalProps = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const SettingsModal = ({ isOpen, closeModal }: SettingsModalProps) => {
|
export const SettingsModal = ({ isOpen, closeModal }: SettingsModalProps) => {
|
||||||
const { settings, setSettings, isPWA } = useGlobalSettings();
|
const { settings, setSettings, isPWA, version } = useGlobalSettings();
|
||||||
|
const analytics = useAnalytics();
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (!isOpen) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
analytics.trackEvent('settings_opened');
|
||||||
|
version.checkForNewVersion('settings');
|
||||||
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
|
}, [isOpen]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Modal open={isOpen} onClose={closeModal}>
|
<Modal
|
||||||
<ModalWrapper>
|
open={isOpen}
|
||||||
<Container>
|
onClose={() => {
|
||||||
<h2 style={{ textAlign: 'center' }}>⚙️ Settings ⚙️</h2>
|
analytics.trackEvent('settings_outside_clicked');
|
||||||
<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>
|
|
||||||
</SettingContainer>
|
|
||||||
<SettingContainer>
|
|
||||||
<ToggleContainer>
|
|
||||||
<FormLabel>Keep Awake</FormLabel>
|
|
||||||
<Switch
|
|
||||||
checked={settings.keepAwake}
|
|
||||||
onChange={() => {
|
|
||||||
setSettings({ ...settings, keepAwake: !settings.keepAwake });
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
</ToggleContainer>
|
|
||||||
<Description>
|
|
||||||
Will prevent device from going to sleep while this app is open if
|
|
||||||
this is enabled.
|
|
||||||
</Description>
|
|
||||||
</SettingContainer>
|
|
||||||
<SettingContainer>
|
|
||||||
<ToggleContainer>
|
|
||||||
<FormLabel>Go fullscreen on start (Android only)</FormLabel>
|
|
||||||
<Switch
|
|
||||||
checked={settings.goFullscreenOnStart}
|
|
||||||
onChange={() => {
|
|
||||||
setSettings({
|
|
||||||
...settings,
|
|
||||||
goFullscreenOnStart: !settings.goFullscreenOnStart,
|
|
||||||
});
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
</ToggleContainer>
|
|
||||||
<Description>
|
|
||||||
Will enter fullscreen mode when starting a game if this is
|
|
||||||
enabled.
|
|
||||||
</Description>
|
|
||||||
</SettingContainer>
|
|
||||||
{!isPWA && (
|
|
||||||
<>
|
|
||||||
<Separator height="2px" />
|
|
||||||
<SettingContainer>
|
|
||||||
<ToggleContainer>
|
|
||||||
<Paragraph>
|
|
||||||
<b>Tip:</b> You can{' '}
|
|
||||||
<b>add this webapp to your home page on iOS</b> or{' '}
|
|
||||||
<b>install it on Android</b> to have it act just like a
|
|
||||||
normal app!
|
|
||||||
</Paragraph>
|
|
||||||
</ToggleContainer>
|
|
||||||
<Description>
|
|
||||||
If you do, this app will work offline and the toolbar will be
|
|
||||||
automatically hidden.
|
|
||||||
</Description>
|
|
||||||
</SettingContainer>
|
|
||||||
</>
|
|
||||||
)}
|
|
||||||
<Separator height="2px" />
|
|
||||||
<SettingContainer>
|
|
||||||
<Paragraph>Version: 0.4.0</Paragraph>
|
|
||||||
</SettingContainer>
|
|
||||||
<Separator height="2px" />
|
|
||||||
|
|
||||||
<Button variant="contained" onClick={closeModal}>
|
closeModal();
|
||||||
Save and Close
|
}}
|
||||||
</Button>
|
className="w-full flex justify-center"
|
||||||
</Container>
|
>
|
||||||
</ModalWrapper>
|
<>
|
||||||
|
<div className="flex justify-center items-center relative w-full max-w-[532px]">
|
||||||
|
<button
|
||||||
|
onClick={() => {
|
||||||
|
analytics.trackEvent('settings_cross_clicked');
|
||||||
|
closeModal();
|
||||||
|
}}
|
||||||
|
className="flex absolute top-12 right-0 z-10 w-10 h-10 bg-primary-main items-center justify-center rounded-full border-solid border-primary-dark border-2"
|
||||||
|
>
|
||||||
|
<Cross size="16px" className="text-text-primary " />
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
<ModalWrapper>
|
||||||
|
<Container>
|
||||||
|
<h2 className="text-center text-2xl mb-2 w-full">⚙️ Settings ⚙️</h2>
|
||||||
|
<div className="flex flex-col mb-2 w-full">
|
||||||
|
<div className="text-text-primary flex items-center gap-2">
|
||||||
|
Current version: {version.installedVersion}{' '}
|
||||||
|
{version.isLatest && (
|
||||||
|
<span className="text-sm text-text-secondary">(latest)</span>
|
||||||
|
)}
|
||||||
|
<div className="text-xs text-text-primary opacity-75">
|
||||||
|
(
|
||||||
|
<a
|
||||||
|
href={baseGithubReleasesUrl + version.installedVersion}
|
||||||
|
target="_blank"
|
||||||
|
className="underline"
|
||||||
|
onClick={() => {
|
||||||
|
analytics.trackEvent(
|
||||||
|
`current_change_log_clicked_v${version.installedVersion}`
|
||||||
|
);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
Release notes
|
||||||
|
</a>
|
||||||
|
)
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{!version.isLatest && version.remoteVersion && (
|
||||||
|
<>
|
||||||
|
<div className="flex gap-2 items-center mt-2">
|
||||||
|
<Paragraph className="text-text-secondary">
|
||||||
|
{version.remoteVersion} available!
|
||||||
|
</Paragraph>
|
||||||
|
<div className="text-xs text-text-primary opacity-75">
|
||||||
|
(
|
||||||
|
<a
|
||||||
|
href={baseGithubReleasesUrl + version.remoteVersion}
|
||||||
|
target="_blank"
|
||||||
|
className="underline"
|
||||||
|
onClick={() => {
|
||||||
|
analytics.trackEvent(
|
||||||
|
`new_change_log_clicked_v${version.remoteVersion}`
|
||||||
|
);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
Release notes
|
||||||
|
</a>
|
||||||
|
)
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<button
|
||||||
|
className="flex justify-center items-center self-start mt-2 bg-primary-main px-3 py-1 rounded-md"
|
||||||
|
onClick={() => {
|
||||||
|
{
|
||||||
|
analytics.trackEvent(`pressed_update`, {
|
||||||
|
toVersion: version.remoteVersion,
|
||||||
|
fromVersion: version.installedVersion,
|
||||||
|
});
|
||||||
|
window?.location?.reload();
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<span className="text-sm">Update</span>
|
||||||
|
<span className="text-xs"> (reload app)</span>
|
||||||
|
</button>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
<Separator height="1px" />
|
||||||
|
|
||||||
|
<SettingContainer>
|
||||||
|
<ToggleContainer>
|
||||||
|
<label>Show Player Menu Cog</label>
|
||||||
|
<Switch
|
||||||
|
checked={settings.showPlayerMenuCog}
|
||||||
|
onChange={() => {
|
||||||
|
setSettings({
|
||||||
|
...settings,
|
||||||
|
showPlayerMenuCog: !settings.showPlayerMenuCog,
|
||||||
|
});
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</ToggleContainer>
|
||||||
|
<Description>
|
||||||
|
A cog on the top right of each player's card will be shown if
|
||||||
|
this is enabled.
|
||||||
|
</Description>
|
||||||
|
</SettingContainer>
|
||||||
|
<SettingContainer>
|
||||||
|
<ToggleContainer>
|
||||||
|
<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">Player selection style</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}>Instant</option>
|
||||||
|
<option value={PreStartMode.RandomKing}>Royal Shuffle</option>
|
||||||
|
<option value={PreStartMode.FingerGame}>
|
||||||
|
Touch Roulette
|
||||||
|
</option>
|
||||||
|
<option value={PreStartMode.Trivia}>Group Trivia</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">Instant:</span> A random
|
||||||
|
starting player will simply be shown on start.
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
{settings.preStartMode === PreStartMode.RandomKing && (
|
||||||
|
<div className="text-xs text-left text-text-secondary mt-1">
|
||||||
|
<span className="text-text-primary">Royal Shuffle:</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">Touch Roulette:</span> All
|
||||||
|
players put a finger on the screen, one will be chosen at
|
||||||
|
random.
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{settings.preStartMode === PreStartMode.Trivia && (
|
||||||
|
<div className="text-xs text-left text-text-secondary mt-1">
|
||||||
|
<span className="text-text-primary">Group Trivia:</span> A
|
||||||
|
random "who is the most ..." type question will be shown, the
|
||||||
|
group decides which player fits the question best.
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</SettingContainer>
|
||||||
|
<SettingContainer>
|
||||||
|
<ToggleContainer>
|
||||||
|
<label>Keep Awake</label>
|
||||||
|
<Switch
|
||||||
|
checked={settings.keepAwake}
|
||||||
|
onChange={() => {
|
||||||
|
setSettings({
|
||||||
|
...settings,
|
||||||
|
keepAwake: !settings.keepAwake,
|
||||||
|
});
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</ToggleContainer>
|
||||||
|
<Description>
|
||||||
|
Will prevent device from going to sleep while this app is open
|
||||||
|
if this is enabled.
|
||||||
|
</Description>
|
||||||
|
</SettingContainer>
|
||||||
|
<SettingContainer>
|
||||||
|
<ToggleContainer>
|
||||||
|
<label>
|
||||||
|
Fullscreen on start{' '}
|
||||||
|
<span className="text-xs">(Android only)</span>
|
||||||
|
</label>
|
||||||
|
<Switch
|
||||||
|
checked={settings.goFullscreenOnStart}
|
||||||
|
onChange={() => {
|
||||||
|
setSettings({
|
||||||
|
...settings,
|
||||||
|
goFullscreenOnStart: !settings.goFullscreenOnStart,
|
||||||
|
});
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</ToggleContainer>
|
||||||
|
<Description>
|
||||||
|
Will enter fullscreen mode when starting a game if this is
|
||||||
|
enabled.
|
||||||
|
</Description>
|
||||||
|
</SettingContainer>
|
||||||
|
<Separator height="1px" />
|
||||||
|
<button
|
||||||
|
className="flex justify-center self-center items-center mt-1 mb-1 bg-primary-main px-3 py-1 rounded-md"
|
||||||
|
onClick={() => {
|
||||||
|
analytics.trackEvent('settings_save_clicked');
|
||||||
|
closeModal();
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<span className="text-sm">Save and Close</span>
|
||||||
|
</button>
|
||||||
|
{!isPWA && (
|
||||||
|
<>
|
||||||
|
<Separator height="1px" />
|
||||||
|
<SettingContainer>
|
||||||
|
<ToggleContainer>
|
||||||
|
<Paragraph>
|
||||||
|
<b>Tip:</b> You can{' '}
|
||||||
|
<b>add this webapp to your home page on iOS</b> or{' '}
|
||||||
|
<b>install it on Android</b> to have it act just like a
|
||||||
|
normal app!
|
||||||
|
</Paragraph>
|
||||||
|
</ToggleContainer>
|
||||||
|
<Description className="mt-1">
|
||||||
|
If you do, this app will work offline and the toolbar will
|
||||||
|
be automatically hidden.
|
||||||
|
</Description>
|
||||||
|
</SettingContainer>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
<Separator height="1px" />
|
||||||
|
</Container>
|
||||||
|
</ModalWrapper>
|
||||||
|
</>
|
||||||
</Modal>
|
</Modal>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,6 +0,0 @@
|
|||||||
import styled from 'styled-components';
|
|
||||||
|
|
||||||
export const Spacer = styled.div<{ width?: string; height?: string }>`
|
|
||||||
width: ${(props) => props.width};
|
|
||||||
height: ${(props) => props.height};
|
|
||||||
`;
|
|
||||||
@@ -1,43 +1,30 @@
|
|||||||
import { Button, Drawer } from '@mui/material';
|
import { Button, Drawer } from '@mui/material';
|
||||||
import { useState } from 'react';
|
import { useState } from 'react';
|
||||||
import styled from 'styled-components';
|
|
||||||
import { theme } from '../../Data/theme';
|
|
||||||
import { BuyMeCoffee, KoFi } from '../../Icons/generated/Support';
|
import { BuyMeCoffee, KoFi } from '../../Icons/generated/Support';
|
||||||
import { Paragraph } from './TextComponents';
|
import { Paragraph } from './TextComponents';
|
||||||
import LittleGuy from '../../Icons/generated/LittleGuy';
|
import LittleGuy from '../../Icons/generated/LittleGuy';
|
||||||
import { useAnalytics } from '../../Hooks/useAnalytics';
|
import { useAnalytics } from '../../Hooks/useAnalytics';
|
||||||
|
import { twc } from 'react-twc';
|
||||||
|
|
||||||
// import { ButtonBase } from '@mui/material';
|
const SupportContainer = twc.div`flex flex-col items-center justify-center gap-4 mt-4 mb-4`;
|
||||||
|
|
||||||
const SupportContainer = styled.div`
|
const SupportButton = twc.button`
|
||||||
display: flex;
|
flex
|
||||||
flex-direction: column;
|
flex-row
|
||||||
align-items: center;
|
items-center
|
||||||
justify-content: center;
|
justify-left
|
||||||
gap: 1rem;
|
border-none
|
||||||
margin: 16px 0;
|
cursor-pointer
|
||||||
`;
|
bg-primary-main
|
||||||
|
rounded-md
|
||||||
const SupportButton = styled.button`
|
w-10/12
|
||||||
display: flex;
|
mx-4
|
||||||
flex-direction: row;
|
px-4
|
||||||
align-items: center;
|
py-2
|
||||||
justify-content: center;
|
transition-colors duration-200 ease-in-out
|
||||||
border: none;
|
shadow-[1px_2px_4px_0px_rgba(0,0,0,0.3)]
|
||||||
background-color: transparent;
|
hover:bg-primary-dark
|
||||||
cursor: pointer;
|
`;
|
||||||
padding: 0;
|
|
||||||
margin: 0;
|
|
||||||
background-color: ${theme.palette.primary.main};
|
|
||||||
border-radius: 4px;
|
|
||||||
margin: 0 1rem;
|
|
||||||
padding: 0 1rem;
|
|
||||||
transition: background-color 0.2s ease-in-out;
|
|
||||||
box-shadow: 1px 2px 4px 0px rgba(0, 0, 0, 0.3);
|
|
||||||
&:hover {
|
|
||||||
background-color: ${theme.palette.primary.dark};
|
|
||||||
}
|
|
||||||
`;
|
|
||||||
|
|
||||||
export const SupportMe = () => {
|
export const SupportMe = () => {
|
||||||
const analytics = useAnalytics();
|
const analytics = useAnalytics();
|
||||||
@@ -87,13 +74,7 @@ export const SupportMe = () => {
|
|||||||
<LittleGuy
|
<LittleGuy
|
||||||
height={'4rem'}
|
height={'4rem'}
|
||||||
width={'2.5rem'}
|
width={'2.5rem'}
|
||||||
style={{
|
className="pointer-events-none absolute top-10 right-0 text-text-primary"
|
||||||
pointerEvents: 'none',
|
|
||||||
position: 'absolute',
|
|
||||||
top: '2.5rem',
|
|
||||||
right: '0',
|
|
||||||
color: theme.palette.text.primary,
|
|
||||||
}}
|
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<Drawer
|
<Drawer
|
||||||
@@ -104,22 +85,12 @@ export const SupportMe = () => {
|
|||||||
>
|
>
|
||||||
<SupportContainer>
|
<SupportContainer>
|
||||||
<SupportButton onClick={handleOpenBuyMeCoffee}>
|
<SupportButton onClick={handleOpenBuyMeCoffee}>
|
||||||
<BuyMeCoffee
|
<BuyMeCoffee height="1.5rem" width="1.5rem" className="mr-2" />
|
||||||
height={'1.5rem'}
|
<Paragraph className="text-xs">Buy him a tea</Paragraph>
|
||||||
width={'1.5rem'}
|
|
||||||
style={{ marginRight: '0.5rem' }}
|
|
||||||
/>
|
|
||||||
<Paragraph style={{ fontSize: '0.7rem' }}>Buy him a tea</Paragraph>
|
|
||||||
</SupportButton>
|
</SupportButton>
|
||||||
<SupportButton onClick={handleOpenKoFi}>
|
<SupportButton onClick={handleOpenKoFi}>
|
||||||
<KoFi
|
<KoFi height="1.5rem" width="1.5rem" className="mr-2" />
|
||||||
height={'1.5rem'}
|
<Paragraph className="text-xs">Buy him a ko-fi</Paragraph>
|
||||||
width={'1.5rem'}
|
|
||||||
style={{ marginRight: '0.5rem' }}
|
|
||||||
/>
|
|
||||||
<Paragraph style={{ fontSize: '0.7rem' }}>
|
|
||||||
Buy him a ko-fi
|
|
||||||
</Paragraph>
|
|
||||||
</SupportButton>
|
</SupportButton>
|
||||||
</SupportContainer>
|
</SupportContainer>
|
||||||
</Drawer>
|
</Drawer>
|
||||||
|
|||||||
@@ -1,11 +1,6 @@
|
|||||||
import styled from 'styled-components';
|
import { twc } from 'react-twc';
|
||||||
import { theme } from '../../Data/theme';
|
|
||||||
|
|
||||||
export const Paragraph = styled.p`
|
export const Paragraph = twc.p`text-text-primary;`;
|
||||||
color: ${theme.palette.text.primary};
|
|
||||||
`;
|
|
||||||
|
|
||||||
// eslint-disable-next-line react-refresh/only-export-components
|
// eslint-disable-next-line react-refresh/only-export-components
|
||||||
export const H1 = styled.h1`
|
export const H1 = twc.h1`text-text-primary;`;
|
||||||
color: ${theme.palette.text.primary};
|
|
||||||
`;
|
|
||||||
|
|||||||
@@ -1,455 +0,0 @@
|
|||||||
import { Button, Checkbox } from '@mui/material';
|
|
||||||
import styled, { css } from 'styled-components';
|
|
||||||
import { Player, Rotation } from '../../Types/Player';
|
|
||||||
import { theme } from '../../Data/theme';
|
|
||||||
import { useGlobalSettings } from '../../Hooks/useGlobalSettings';
|
|
||||||
import { usePlayers } from '../../Hooks/usePlayers';
|
|
||||||
import {
|
|
||||||
PartnerTax,
|
|
||||||
Poison,
|
|
||||||
Energy,
|
|
||||||
Experience,
|
|
||||||
Exit,
|
|
||||||
FullscreenOff,
|
|
||||||
FullscreenOn,
|
|
||||||
Cross,
|
|
||||||
ResetGame,
|
|
||||||
} from '../../Icons/generated';
|
|
||||||
import { useRef } from 'react';
|
|
||||||
import { Spacer } from '../Misc/Spacer';
|
|
||||||
import { useSafeRotate } from '../../Hooks/useSafeRotate';
|
|
||||||
|
|
||||||
const SettingsContainer = styled.div<{
|
|
||||||
$rotation: Rotation;
|
|
||||||
}>`
|
|
||||||
display: flex;
|
|
||||||
flex-direction: row;
|
|
||||||
flex-wrap: wrap;
|
|
||||||
height: 100%;
|
|
||||||
width: 100%;
|
|
||||||
|
|
||||||
${(props) => {
|
|
||||||
if (
|
|
||||||
props.$rotation === Rotation.SideFlipped ||
|
|
||||||
props.$rotation === Rotation.Side
|
|
||||||
) {
|
|
||||||
return css`
|
|
||||||
flex-direction: column-reverse;
|
|
||||||
height: 100%;
|
|
||||||
width: 100%;
|
|
||||||
`;
|
|
||||||
}
|
|
||||||
}}
|
|
||||||
${(props) => {
|
|
||||||
if (props.$rotation === Rotation.Side) {
|
|
||||||
return css`
|
|
||||||
rotate: ${props.$rotation - 180}deg;
|
|
||||||
`;
|
|
||||||
} else if (props.$rotation === Rotation.SideFlipped) {
|
|
||||||
return css`
|
|
||||||
rotate: ${props.$rotation - 180}deg;
|
|
||||||
`;
|
|
||||||
}
|
|
||||||
}}
|
|
||||||
`;
|
|
||||||
|
|
||||||
const BetterRowContainer = styled.div`
|
|
||||||
display: flex;
|
|
||||||
flex-direction: column;
|
|
||||||
flex-grow: 1;
|
|
||||||
width: 100%;
|
|
||||||
height: 100%;
|
|
||||||
justify-content: end;
|
|
||||||
align-items: stretch;
|
|
||||||
`;
|
|
||||||
|
|
||||||
const TogglesSection = styled.div`
|
|
||||||
display: flex;
|
|
||||||
position: relative;
|
|
||||||
flex-direction: row;
|
|
||||||
gap: 0.5rem;
|
|
||||||
justify-content: space-evenly;
|
|
||||||
`;
|
|
||||||
|
|
||||||
const ButtonsSections = styled.div`
|
|
||||||
display: flex;
|
|
||||||
max-width: 100%;
|
|
||||||
gap: 1rem;
|
|
||||||
justify-content: space-between;
|
|
||||||
padding: 3% 3%;
|
|
||||||
align-items: center;
|
|
||||||
`;
|
|
||||||
|
|
||||||
const ColorPicker = styled.input`
|
|
||||||
position: absolute;
|
|
||||||
top: 5%;
|
|
||||||
left: 5%;
|
|
||||||
height: 8vmax;
|
|
||||||
width: 8vmax;
|
|
||||||
border: none;
|
|
||||||
outline: none;
|
|
||||||
cursor: pointer;
|
|
||||||
background-color: transparent;
|
|
||||||
user-select: none;
|
|
||||||
color: #ffffff;
|
|
||||||
`;
|
|
||||||
|
|
||||||
const CheckboxContainer = styled.div<{ $rotation: Rotation }>`
|
|
||||||
${(props) => {
|
|
||||||
if (
|
|
||||||
props.$rotation === Rotation.SideFlipped ||
|
|
||||||
props.$rotation === Rotation.Side
|
|
||||||
) {
|
|
||||||
return css`
|
|
||||||
/* rotate: ${props.$rotation - 180}deg; */
|
|
||||||
`;
|
|
||||||
}
|
|
||||||
}}
|
|
||||||
`;
|
|
||||||
|
|
||||||
const PlayerMenuWrapper = styled.div<{
|
|
||||||
$rotation: Rotation;
|
|
||||||
}>`
|
|
||||||
display: flex;
|
|
||||||
flex-direction: column;
|
|
||||||
position: absolute;
|
|
||||||
width: 100%;
|
|
||||||
height: 100%;
|
|
||||||
background-color: rgba(20, 20, 20, 0.9);
|
|
||||||
align-items: center;
|
|
||||||
justify-content: center;
|
|
||||||
z-index: 2;
|
|
||||||
${(props) => {
|
|
||||||
if (
|
|
||||||
props.$rotation === Rotation.SideFlipped ||
|
|
||||||
props.$rotation === Rotation.Side
|
|
||||||
) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
return css`
|
|
||||||
rotate: ${props.$rotation}deg;
|
|
||||||
`;
|
|
||||||
}};
|
|
||||||
`;
|
|
||||||
|
|
||||||
const CloseButton = styled.div<{
|
|
||||||
$rotation: Rotation;
|
|
||||||
}>`
|
|
||||||
position: absolute;
|
|
||||||
top: 15%;
|
|
||||||
right: 5%;
|
|
||||||
z-index: 9999;
|
|
||||||
border: none;
|
|
||||||
outline: none;
|
|
||||||
cursor: pointer;
|
|
||||||
background-color: transparent;
|
|
||||||
|
|
||||||
${(props) => {
|
|
||||||
if (props.$rotation === Rotation.Side) {
|
|
||||||
return css`
|
|
||||||
rotate: ${props.$rotation - 180}deg;
|
|
||||||
top: 5%;
|
|
||||||
right: auto;
|
|
||||||
left: 5%;
|
|
||||||
`;
|
|
||||||
} else if (props.$rotation === Rotation.SideFlipped) {
|
|
||||||
return css`
|
|
||||||
rotate: ${props.$rotation - 180}deg;
|
|
||||||
top: auto;
|
|
||||||
left: auto;
|
|
||||||
bottom: 5%;
|
|
||||||
right: 5%;
|
|
||||||
`;
|
|
||||||
}
|
|
||||||
}}
|
|
||||||
`;
|
|
||||||
|
|
||||||
type PlayerMenuProps = {
|
|
||||||
player: Player;
|
|
||||||
setShowPlayerMenu: (showPlayerMenu: boolean) => void;
|
|
||||||
};
|
|
||||||
|
|
||||||
const PlayerMenu = ({ player, setShowPlayerMenu }: PlayerMenuProps) => {
|
|
||||||
const settingsContainerRef = useRef<HTMLDivElement | null>(null);
|
|
||||||
const dialogRef = useRef<HTMLDialogElement | null>(null);
|
|
||||||
|
|
||||||
const { isSide } = useSafeRotate({
|
|
||||||
rotation: player.settings.rotation,
|
|
||||||
containerRef: settingsContainerRef,
|
|
||||||
});
|
|
||||||
|
|
||||||
const handleOnClick = () => {
|
|
||||||
setShowPlayerMenu(false);
|
|
||||||
};
|
|
||||||
const { fullscreen, wakeLock, goToStart } = useGlobalSettings();
|
|
||||||
const { updatePlayer, resetCurrentGame } = usePlayers();
|
|
||||||
|
|
||||||
const handleColorChange = (event: React.ChangeEvent<HTMLInputElement>) => {
|
|
||||||
const updatedPlayer = { ...player, color: event.target.value };
|
|
||||||
updatePlayer(updatedPlayer);
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleSettingsChange = (event: React.ChangeEvent<HTMLInputElement>) => {
|
|
||||||
const { name, checked } = event.target;
|
|
||||||
const updatedSettings = { ...player.settings, [name]: checked };
|
|
||||||
const updatedPlayer = { ...player, settings: updatedSettings };
|
|
||||||
updatePlayer(updatedPlayer);
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleResetGame = () => {
|
|
||||||
resetCurrentGame();
|
|
||||||
setShowPlayerMenu(false);
|
|
||||||
};
|
|
||||||
|
|
||||||
const toggleFullscreen = () => {
|
|
||||||
if (fullscreen.isFullscreen) {
|
|
||||||
fullscreen.disableFullscreen();
|
|
||||||
} else {
|
|
||||||
fullscreen.enableFullscreen();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const buttonFontSize = isSide ? '1.5vmax' : '3vmin';
|
|
||||||
const iconSize = isSide ? '6vmin' : '3vmax';
|
|
||||||
const extraCountersSize = isSide ? '8vmin' : '4vmax';
|
|
||||||
const closeButtonSize = isSide ? '6vmin' : '3vmax';
|
|
||||||
|
|
||||||
return (
|
|
||||||
<PlayerMenuWrapper $rotation={player.settings.rotation}>
|
|
||||||
<CloseButton $rotation={player.settings.rotation}>
|
|
||||||
<Button
|
|
||||||
variant="text"
|
|
||||||
onClick={handleOnClick}
|
|
||||||
style={{
|
|
||||||
margin: 0,
|
|
||||||
padding: 0,
|
|
||||||
height: closeButtonSize,
|
|
||||||
width: closeButtonSize,
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<Cross size={closeButtonSize} />
|
|
||||||
</Button>
|
|
||||||
</CloseButton>
|
|
||||||
<SettingsContainer
|
|
||||||
$rotation={player.settings.rotation}
|
|
||||||
ref={settingsContainerRef}
|
|
||||||
>
|
|
||||||
<ColorPicker
|
|
||||||
type="color"
|
|
||||||
value={player.color}
|
|
||||||
onChange={handleColorChange}
|
|
||||||
role="button"
|
|
||||||
aria-label="Color picker"
|
|
||||||
/>
|
|
||||||
<BetterRowContainer>
|
|
||||||
<TogglesSection>
|
|
||||||
{player.settings.useCommanderDamage && (
|
|
||||||
<CheckboxContainer $rotation={player.settings.rotation}>
|
|
||||||
<Checkbox
|
|
||||||
name="usePartner"
|
|
||||||
checked={player.settings.usePartner}
|
|
||||||
icon={
|
|
||||||
<PartnerTax
|
|
||||||
size={extraCountersSize}
|
|
||||||
color="black"
|
|
||||||
stroke="white"
|
|
||||||
strokeWidth="30"
|
|
||||||
/>
|
|
||||||
}
|
|
||||||
checkedIcon={
|
|
||||||
<PartnerTax
|
|
||||||
size={extraCountersSize}
|
|
||||||
color={player.color}
|
|
||||||
stroke="white"
|
|
||||||
strokeWidth="30"
|
|
||||||
/>
|
|
||||||
}
|
|
||||||
onChange={handleSettingsChange}
|
|
||||||
role="checkbox"
|
|
||||||
aria-checked={player.settings.usePartner}
|
|
||||||
aria-label="Partner"
|
|
||||||
/>
|
|
||||||
</CheckboxContainer>
|
|
||||||
)}
|
|
||||||
|
|
||||||
<CheckboxContainer $rotation={player.settings.rotation}>
|
|
||||||
<Checkbox
|
|
||||||
name="usePoison"
|
|
||||||
checked={player.settings.usePoison}
|
|
||||||
icon={
|
|
||||||
<Poison
|
|
||||||
size={extraCountersSize}
|
|
||||||
color="black"
|
|
||||||
stroke="white"
|
|
||||||
strokeWidth="30"
|
|
||||||
/>
|
|
||||||
}
|
|
||||||
checkedIcon={
|
|
||||||
<Poison
|
|
||||||
size={extraCountersSize}
|
|
||||||
color={player.color}
|
|
||||||
stroke="white"
|
|
||||||
strokeWidth="30"
|
|
||||||
/>
|
|
||||||
}
|
|
||||||
onChange={handleSettingsChange}
|
|
||||||
role="checkbox"
|
|
||||||
aria-checked={player.settings.usePoison}
|
|
||||||
aria-label="Poison"
|
|
||||||
/>
|
|
||||||
</CheckboxContainer>
|
|
||||||
|
|
||||||
<CheckboxContainer $rotation={player.settings.rotation}>
|
|
||||||
<Checkbox
|
|
||||||
name="useEnergy"
|
|
||||||
checked={player.settings.useEnergy}
|
|
||||||
icon={
|
|
||||||
<Energy
|
|
||||||
size={extraCountersSize}
|
|
||||||
color="black"
|
|
||||||
stroke="white"
|
|
||||||
strokeWidth="15"
|
|
||||||
/>
|
|
||||||
}
|
|
||||||
checkedIcon={
|
|
||||||
<Energy
|
|
||||||
size={extraCountersSize}
|
|
||||||
color={player.color}
|
|
||||||
stroke="white"
|
|
||||||
strokeWidth="15"
|
|
||||||
/>
|
|
||||||
}
|
|
||||||
onChange={handleSettingsChange}
|
|
||||||
role="checkbox"
|
|
||||||
aria-checked={player.settings.useEnergy}
|
|
||||||
aria-label="Energy"
|
|
||||||
/>
|
|
||||||
</CheckboxContainer>
|
|
||||||
|
|
||||||
<CheckboxContainer $rotation={player.settings.rotation}>
|
|
||||||
<Checkbox
|
|
||||||
name="useExperience"
|
|
||||||
checked={player.settings.useExperience}
|
|
||||||
icon={
|
|
||||||
<Experience
|
|
||||||
size={extraCountersSize}
|
|
||||||
color="black"
|
|
||||||
stroke="white"
|
|
||||||
strokeWidth="15"
|
|
||||||
/>
|
|
||||||
}
|
|
||||||
checkedIcon={
|
|
||||||
<Experience
|
|
||||||
size={extraCountersSize}
|
|
||||||
color={player.color}
|
|
||||||
stroke="white"
|
|
||||||
strokeWidth="15"
|
|
||||||
/>
|
|
||||||
}
|
|
||||||
onChange={handleSettingsChange}
|
|
||||||
role="checkbox"
|
|
||||||
aria-checked={player.settings.useExperience}
|
|
||||||
aria-label="Experience"
|
|
||||||
/>
|
|
||||||
</CheckboxContainer>
|
|
||||||
</TogglesSection>
|
|
||||||
<Spacer height="1rem" />
|
|
||||||
<ButtonsSections>
|
|
||||||
<Button
|
|
||||||
variant="text"
|
|
||||||
style={{
|
|
||||||
cursor: 'pointer',
|
|
||||||
userSelect: 'none',
|
|
||||||
}}
|
|
||||||
onClick={goToStart}
|
|
||||||
aria-label="Back to start"
|
|
||||||
>
|
|
||||||
<Exit size={iconSize} style={{ rotate: '180deg' }} />
|
|
||||||
</Button>
|
|
||||||
<CheckboxContainer $rotation={player.settings.rotation}>
|
|
||||||
<Checkbox
|
|
||||||
name="fullscreen"
|
|
||||||
checked={document.fullscreenElement ? true : false}
|
|
||||||
icon={
|
|
||||||
<FullscreenOff
|
|
||||||
size={iconSize}
|
|
||||||
color={theme.palette.primary.main}
|
|
||||||
/>
|
|
||||||
}
|
|
||||||
checkedIcon={<FullscreenOn size={iconSize} />}
|
|
||||||
onChange={toggleFullscreen}
|
|
||||||
role="checkbox"
|
|
||||||
aria-checked={document.fullscreenElement ? true : false}
|
|
||||||
aria-label="Fullscreen"
|
|
||||||
/>
|
|
||||||
</CheckboxContainer>
|
|
||||||
|
|
||||||
<Button
|
|
||||||
variant={wakeLock.active ? 'contained' : 'outlined'}
|
|
||||||
style={{
|
|
||||||
cursor: 'pointer',
|
|
||||||
userSelect: 'none',
|
|
||||||
fontSize: buttonFontSize,
|
|
||||||
padding: '0 4px 0 4px',
|
|
||||||
}}
|
|
||||||
onClick={wakeLock.toggleWakeLock}
|
|
||||||
role="checkbox"
|
|
||||||
aria-checked={wakeLock.active}
|
|
||||||
aria-label="Keep awake"
|
|
||||||
>
|
|
||||||
Keep Awake
|
|
||||||
</Button>
|
|
||||||
|
|
||||||
<Button
|
|
||||||
style={{
|
|
||||||
cursor: 'pointer',
|
|
||||||
userSelect: 'none',
|
|
||||||
fontSize: buttonFontSize,
|
|
||||||
padding: '4px',
|
|
||||||
}}
|
|
||||||
onClick={() => dialogRef.current?.show()}
|
|
||||||
role="checkbox"
|
|
||||||
aria-checked={wakeLock.active}
|
|
||||||
aria-label="Reset Game"
|
|
||||||
>
|
|
||||||
<ResetGame size={iconSize} />
|
|
||||||
</Button>
|
|
||||||
</ButtonsSections>
|
|
||||||
</BetterRowContainer>
|
|
||||||
<dialog
|
|
||||||
ref={dialogRef}
|
|
||||||
style={{
|
|
||||||
zIndex: 9999,
|
|
||||||
background: theme.palette.background.default,
|
|
||||||
color: theme.palette.text.primary,
|
|
||||||
borderRadius: '1rem',
|
|
||||||
border: 'none',
|
|
||||||
position: 'absolute',
|
|
||||||
top: '10%',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<h1>Reset Game?</h1>
|
|
||||||
<div style={{ display: 'flex', justifyContent: 'space-evenly' }}>
|
|
||||||
<Button
|
|
||||||
variant="contained"
|
|
||||||
onClick={() => dialogRef.current?.close()}
|
|
||||||
>
|
|
||||||
No
|
|
||||||
</Button>
|
|
||||||
<Button
|
|
||||||
variant="contained"
|
|
||||||
onClick={() => {
|
|
||||||
handleResetGame();
|
|
||||||
dialogRef.current?.close();
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
Yes
|
|
||||||
</Button>
|
|
||||||
</div>
|
|
||||||
</dialog>
|
|
||||||
</SettingsContainer>
|
|
||||||
</PlayerMenuWrapper>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
export default PlayerMenu;
|
|
||||||
475
src/Components/Players/PlayerMenu.tsx
Normal file
475
src/Components/Players/PlayerMenu.tsx
Normal file
@@ -0,0 +1,475 @@
|
|||||||
|
import { Checkbox } from '@mui/material';
|
||||||
|
import { useRef } from 'react';
|
||||||
|
import { twc } from 'react-twc';
|
||||||
|
import { theme } from '../../Data/theme';
|
||||||
|
import { useGlobalSettings } from '../../Hooks/useGlobalSettings';
|
||||||
|
import { usePlayers } from '../../Hooks/usePlayers';
|
||||||
|
import { useSafeRotate } from '../../Hooks/useSafeRotate';
|
||||||
|
import {
|
||||||
|
Cross,
|
||||||
|
Energy,
|
||||||
|
Exit,
|
||||||
|
Experience,
|
||||||
|
FullscreenOff,
|
||||||
|
FullscreenOn,
|
||||||
|
PartnerTax,
|
||||||
|
Poison,
|
||||||
|
ResetGame,
|
||||||
|
} from '../../Icons/generated';
|
||||||
|
import { Player, Rotation } from '../../Types/Player';
|
||||||
|
import { RotationDivProps } from '../Buttons/CommanderDamage';
|
||||||
|
import { useAnalytics } from '../../Hooks/useAnalytics';
|
||||||
|
|
||||||
|
const PlayerMenuWrapper = twc.div`
|
||||||
|
flex
|
||||||
|
flex-col
|
||||||
|
absolute
|
||||||
|
w-full
|
||||||
|
h-full
|
||||||
|
bg-background-settings
|
||||||
|
backdrop-blur-[3px]
|
||||||
|
items-center
|
||||||
|
justify-center
|
||||||
|
z-[2]
|
||||||
|
webkit-user-select-none
|
||||||
|
transition-all
|
||||||
|
`;
|
||||||
|
|
||||||
|
const BetterRowContainer = twc.div`
|
||||||
|
flex
|
||||||
|
flex-col
|
||||||
|
flex-grow
|
||||||
|
w-full
|
||||||
|
h-full
|
||||||
|
justify-between
|
||||||
|
items-stretch
|
||||||
|
`;
|
||||||
|
|
||||||
|
const TogglesSection = twc.div`
|
||||||
|
flex
|
||||||
|
flex-row
|
||||||
|
flex-wrap
|
||||||
|
relative
|
||||||
|
h-full
|
||||||
|
justify-evenly
|
||||||
|
items-center
|
||||||
|
`;
|
||||||
|
|
||||||
|
const ButtonsSections = twc.div`
|
||||||
|
flex
|
||||||
|
max-w-full
|
||||||
|
justify-evenly
|
||||||
|
items-center
|
||||||
|
flex-wrap
|
||||||
|
mt-0
|
||||||
|
px-2
|
||||||
|
`;
|
||||||
|
|
||||||
|
const ColorPickerButton = twc.div`
|
||||||
|
h-[8vmax]
|
||||||
|
w-[8vmax]
|
||||||
|
relative
|
||||||
|
max-h-12
|
||||||
|
max-w-12
|
||||||
|
rounded-full
|
||||||
|
cursor-pointer
|
||||||
|
overflow-hidden
|
||||||
|
`;
|
||||||
|
|
||||||
|
const SettingsContainer = twc.div<RotationDivProps>((props) => [
|
||||||
|
'flex flex-wrap h-full w-full overflow-y-scroll',
|
||||||
|
props.$rotation === Rotation.SideFlipped || props.$rotation === Rotation.Side
|
||||||
|
? 'flex-col'
|
||||||
|
: 'flex-row',
|
||||||
|
]);
|
||||||
|
|
||||||
|
type PlayerMenuProps = {
|
||||||
|
player: Player;
|
||||||
|
setShowPlayerMenu: (showPlayerMenu: boolean) => void;
|
||||||
|
isShown: boolean;
|
||||||
|
};
|
||||||
|
|
||||||
|
const PlayerMenu = ({
|
||||||
|
player,
|
||||||
|
setShowPlayerMenu,
|
||||||
|
isShown,
|
||||||
|
}: 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,
|
||||||
|
setPlaying,
|
||||||
|
setRandomizingPlayer,
|
||||||
|
} = useGlobalSettings();
|
||||||
|
|
||||||
|
const analytics = useAnalytics();
|
||||||
|
|
||||||
|
const { updatePlayer, resetCurrentGame } = usePlayers();
|
||||||
|
|
||||||
|
const handleColorChange = (event: React.ChangeEvent<HTMLInputElement>) => {
|
||||||
|
const updatedPlayer = { ...player, color: event.target.value };
|
||||||
|
updatePlayer(updatedPlayer);
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleSettingsChange = (event: React.ChangeEvent<HTMLInputElement>) => {
|
||||||
|
const { name, checked } = event.target;
|
||||||
|
const updatedSettings = { ...player.settings, [name]: checked };
|
||||||
|
const updatedPlayer = { ...player, settings: updatedSettings };
|
||||||
|
updatePlayer(updatedPlayer);
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleResetGame = () => {
|
||||||
|
resetCurrentGame();
|
||||||
|
setShowPlayerMenu(false);
|
||||||
|
setPlaying(false);
|
||||||
|
setRandomizingPlayer(true);
|
||||||
|
analytics.trackEvent('reset_game');
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleGoToStart = () => {
|
||||||
|
goToStart();
|
||||||
|
setRandomizingPlayer(true);
|
||||||
|
};
|
||||||
|
|
||||||
|
const toggleFullscreen = () => {
|
||||||
|
if (fullscreen.isFullscreen) {
|
||||||
|
fullscreen.disableFullscreen();
|
||||||
|
} else {
|
||||||
|
fullscreen.enableFullscreen();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const buttonFontSize = isSide ? '1.5vmax' : '3vmin';
|
||||||
|
const iconSize = isSide ? '6vmin' : '3vmax';
|
||||||
|
const extraCountersSize = isSide ? '8vmin' : '4vmax';
|
||||||
|
|
||||||
|
const calcRotation =
|
||||||
|
player.settings.rotation === Rotation.Side
|
||||||
|
? `${player.settings.rotation - 180}deg`
|
||||||
|
: player.settings.rotation === Rotation.SideFlipped
|
||||||
|
? `${player.settings.rotation - 180}deg`
|
||||||
|
: '';
|
||||||
|
|
||||||
|
return (
|
||||||
|
<PlayerMenuWrapper
|
||||||
|
//TODO: Fix hacky solution to rotation for SideFlipped
|
||||||
|
style={{
|
||||||
|
rotate:
|
||||||
|
player.settings.rotation === Rotation.SideFlipped ? `180deg` : '',
|
||||||
|
translate: isShown ? '' : player.isSide ? `-100%` : `0 -100%`,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<SettingsContainer
|
||||||
|
$rotation={player.settings.rotation}
|
||||||
|
style={{
|
||||||
|
rotate: calcRotation,
|
||||||
|
}}
|
||||||
|
ref={settingsContainerRef}
|
||||||
|
>
|
||||||
|
<button
|
||||||
|
onClick={() => {
|
||||||
|
analytics.trackEvent('close_player_menu_button');
|
||||||
|
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">
|
||||||
|
<input
|
||||||
|
onChange={handleColorChange}
|
||||||
|
type="color"
|
||||||
|
className="size-[200%] absolute -left-2 -top-2"
|
||||||
|
value={player.color}
|
||||||
|
onClick={() => {
|
||||||
|
analytics.trackEvent('color_picker_opened', {
|
||||||
|
player: player.index,
|
||||||
|
});
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</ColorPickerButton>
|
||||||
|
{player.settings.useCommanderDamage && (
|
||||||
|
<div>
|
||||||
|
<Checkbox
|
||||||
|
name="usePartner"
|
||||||
|
checked={player.settings.usePartner}
|
||||||
|
icon={
|
||||||
|
<PartnerTax
|
||||||
|
size={extraCountersSize}
|
||||||
|
color="black"
|
||||||
|
stroke="white"
|
||||||
|
strokeWidth="30"
|
||||||
|
/>
|
||||||
|
}
|
||||||
|
checkedIcon={
|
||||||
|
<PartnerTax
|
||||||
|
size={extraCountersSize}
|
||||||
|
color={player.color}
|
||||||
|
stroke="white"
|
||||||
|
strokeWidth="30"
|
||||||
|
/>
|
||||||
|
}
|
||||||
|
onChange={(e) => {
|
||||||
|
analytics.trackEvent('toggle_partner', {
|
||||||
|
checked: e.target.checked,
|
||||||
|
});
|
||||||
|
handleSettingsChange(e);
|
||||||
|
}}
|
||||||
|
role="checkbox"
|
||||||
|
aria-checked={player.settings.usePartner}
|
||||||
|
aria-label="Partner"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
<div>
|
||||||
|
<Checkbox
|
||||||
|
name="usePoison"
|
||||||
|
checked={player.settings.usePoison}
|
||||||
|
icon={
|
||||||
|
<Poison
|
||||||
|
size={extraCountersSize}
|
||||||
|
color="black"
|
||||||
|
stroke="white"
|
||||||
|
strokeWidth="30"
|
||||||
|
/>
|
||||||
|
}
|
||||||
|
checkedIcon={
|
||||||
|
<Poison
|
||||||
|
size={extraCountersSize}
|
||||||
|
color={player.color}
|
||||||
|
stroke="white"
|
||||||
|
strokeWidth="30"
|
||||||
|
/>
|
||||||
|
}
|
||||||
|
onChange={(e) => {
|
||||||
|
analytics.trackEvent('toggle_poison', {
|
||||||
|
checked: e.target.checked,
|
||||||
|
});
|
||||||
|
handleSettingsChange(e);
|
||||||
|
}}
|
||||||
|
role="checkbox"
|
||||||
|
aria-checked={player.settings.usePoison}
|
||||||
|
aria-label="Poison"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<Checkbox
|
||||||
|
name="useEnergy"
|
||||||
|
checked={player.settings.useEnergy}
|
||||||
|
icon={
|
||||||
|
<Energy
|
||||||
|
size={extraCountersSize}
|
||||||
|
color="black"
|
||||||
|
stroke="white"
|
||||||
|
strokeWidth="15"
|
||||||
|
/>
|
||||||
|
}
|
||||||
|
checkedIcon={
|
||||||
|
<Energy
|
||||||
|
size={extraCountersSize}
|
||||||
|
color={player.color}
|
||||||
|
stroke="white"
|
||||||
|
strokeWidth="15"
|
||||||
|
/>
|
||||||
|
}
|
||||||
|
onChange={(e) => {
|
||||||
|
analytics.trackEvent('toggle_energy', {
|
||||||
|
checked: e.target.checked,
|
||||||
|
});
|
||||||
|
handleSettingsChange(e);
|
||||||
|
}}
|
||||||
|
role="checkbox"
|
||||||
|
aria-checked={player.settings.useEnergy}
|
||||||
|
aria-label="Energy"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<Checkbox
|
||||||
|
name="useExperience"
|
||||||
|
checked={player.settings.useExperience}
|
||||||
|
icon={
|
||||||
|
<Experience
|
||||||
|
size={extraCountersSize}
|
||||||
|
color="black"
|
||||||
|
stroke="white"
|
||||||
|
strokeWidth="15"
|
||||||
|
/>
|
||||||
|
}
|
||||||
|
checkedIcon={
|
||||||
|
<Experience
|
||||||
|
size={extraCountersSize}
|
||||||
|
color={player.color}
|
||||||
|
stroke="white"
|
||||||
|
strokeWidth="15"
|
||||||
|
/>
|
||||||
|
}
|
||||||
|
onChange={(e) => {
|
||||||
|
analytics.trackEvent('toggle_experience', {
|
||||||
|
checked: e.target.checked,
|
||||||
|
});
|
||||||
|
handleSettingsChange(e);
|
||||||
|
}}
|
||||||
|
role="checkbox"
|
||||||
|
aria-checked={player.settings.useExperience}
|
||||||
|
aria-label="Experience"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</TogglesSection>
|
||||||
|
<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>
|
||||||
|
<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}
|
||||||
|
icon={
|
||||||
|
<FullscreenOff
|
||||||
|
size={iconSize}
|
||||||
|
color={theme.palette.primary.main}
|
||||||
|
/>
|
||||||
|
}
|
||||||
|
checkedIcon={<FullscreenOn size={iconSize} />}
|
||||||
|
onChange={toggleFullscreen}
|
||||||
|
role="checkbox"
|
||||||
|
aria-checked={document.fullscreenElement ? true : false}
|
||||||
|
aria-label="Fullscreen"
|
||||||
|
style={{ padding: '4px' }}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<button
|
||||||
|
data-wake-lock-active={settings.keepAwake}
|
||||||
|
style={{
|
||||||
|
fontSize: buttonFontSize,
|
||||||
|
}}
|
||||||
|
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={settings.keepAwake}
|
||||||
|
aria-label="Keep awake"
|
||||||
|
>
|
||||||
|
Keep Awake
|
||||||
|
</button>
|
||||||
|
|
||||||
|
<button
|
||||||
|
style={{
|
||||||
|
cursor: 'pointer',
|
||||||
|
userSelect: 'none',
|
||||||
|
fontSize: buttonFontSize,
|
||||||
|
padding: '2px',
|
||||||
|
}}
|
||||||
|
className="text-primary-main"
|
||||||
|
onClick={() => resetGameDialogRef.current?.show()}
|
||||||
|
role="checkbox"
|
||||||
|
aria-label="Reset Game"
|
||||||
|
>
|
||||||
|
<ResetGame size={iconSize} />
|
||||||
|
</button>
|
||||||
|
</ButtonsSections>
|
||||||
|
</BetterRowContainer>
|
||||||
|
|
||||||
|
<dialog
|
||||||
|
ref={resetGameDialogRef}
|
||||||
|
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-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
|
||||||
|
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>
|
||||||
|
</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>
|
||||||
|
</dialog>
|
||||||
|
</SettingsContainer>
|
||||||
|
</PlayerMenuWrapper>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default PlayerMenu;
|
||||||
@@ -1,5 +1,8 @@
|
|||||||
import LifeCounter from '../LifeCounter/LifeCounter';
|
import { twc } from 'react-twc';
|
||||||
|
import { usePlayers } from '../../Hooks/usePlayers';
|
||||||
import { Player as PlayerType } from '../../Types/Player';
|
import { Player as PlayerType } from '../../Types/Player';
|
||||||
|
import LifeCounter from '../LifeCounter/LifeCounter';
|
||||||
|
import { GridLayout } from '../Views/Play';
|
||||||
|
|
||||||
const getGridArea = (player: PlayerType) => {
|
const getGridArea = (player: PlayerType) => {
|
||||||
switch (player.index) {
|
switch (player.index) {
|
||||||
@@ -20,13 +23,16 @@ const getGridArea = (player: PlayerType) => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export const Player = (players: PlayerType[], gridClasses: string) => {
|
const PlayersWrapper = twc.div`w-full h-full bg-black`;
|
||||||
|
|
||||||
|
export const Players = ({ gridLayout }: { gridLayout: GridLayout }) => {
|
||||||
|
const { players } = usePlayers();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="w-full h-full bg-black">
|
<PlayersWrapper>
|
||||||
<div className={`grid w-full h-full gap-1 box-border ${gridClasses} `}>
|
<div className={`grid w-full h-full gap-1 box-border ${gridLayout} `}>
|
||||||
{players.map((player) => {
|
{players.map((player) => {
|
||||||
const gridArea = getGridArea(player);
|
const gridArea = getGridArea(player);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
key={player.index}
|
key={player.index}
|
||||||
@@ -42,6 +48,6 @@ export const Player = (players: PlayerType[], gridClasses: string) => {
|
|||||||
);
|
);
|
||||||
})}
|
})}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</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>
|
||||||
|
);
|
||||||
|
};
|
||||||
160
src/Components/PreStartGame/Games/Trivia.tsx
Normal file
160
src/Components/PreStartGame/Games/Trivia.tsx
Normal file
@@ -0,0 +1,160 @@
|
|||||||
|
import { useState } from 'react';
|
||||||
|
import { useGlobalSettings } from '../../../Hooks/useGlobalSettings';
|
||||||
|
|
||||||
|
const questions = [
|
||||||
|
'Who has the most siblings?',
|
||||||
|
'Who has the most pets?',
|
||||||
|
'Who has the most tattoos?',
|
||||||
|
'Who has the most piercings?',
|
||||||
|
'Who has the most expensive shoes?',
|
||||||
|
'Who has the most most amount of teeth?',
|
||||||
|
'Who has the most least amount of teeth?',
|
||||||
|
'Who has the most least amount of teeth?',
|
||||||
|
'Who lives closest to the equator?',
|
||||||
|
'Who is the tallest person in the group?',
|
||||||
|
'Who is the shortest person in the group?',
|
||||||
|
'Who speaks the most languages?',
|
||||||
|
'Who has traveled to the most countries?',
|
||||||
|
'Who has the earliest birthday in the year?',
|
||||||
|
'Who has won the most awards or trophies?',
|
||||||
|
'Who is the best cook among you?',
|
||||||
|
'Who is the fastest runner?',
|
||||||
|
'Who has the most unique hobby?',
|
||||||
|
'Who is the biggest movie buff?',
|
||||||
|
'Who is the most tech-savvy?',
|
||||||
|
'Who is the best at solving puzzles?',
|
||||||
|
'Who has the most extensive music collection?',
|
||||||
|
'Who has the most impressive collection of books?',
|
||||||
|
'Who has the most experience in a particular sport or activity?',
|
||||||
|
'Who has the most interesting job or profession?',
|
||||||
|
'Who has the most artistic talent?',
|
||||||
|
'Who is the most organized person?',
|
||||||
|
'Who is the best at keeping secrets?',
|
||||||
|
'Who has the most fascinating family history?',
|
||||||
|
'Who has the most embarrassing childhood nickname?',
|
||||||
|
'Who has the most unusual talent or skill?',
|
||||||
|
'Who has the most interesting family tradition?',
|
||||||
|
'Who has the most impressive celebrity encounter?',
|
||||||
|
'Who has the most unusual phobia?',
|
||||||
|
'Who has the most adventurous spirit?',
|
||||||
|
'Who has the most unique item in their wallet/purse?',
|
||||||
|
'Who has the most daring fashion sense?',
|
||||||
|
'Who has the most impressive party trick?',
|
||||||
|
'Who has the most memorable encounter with a wild animal?',
|
||||||
|
'Who has the most adventurous palate?',
|
||||||
|
'Who has the most unusual collection?',
|
||||||
|
'Who has the most unique bucket list item?',
|
||||||
|
'Who has the most inspiring life motto or mantra?',
|
||||||
|
'Who is the most likely to break out into song or dance in public?',
|
||||||
|
'Who is the most likely to be found binge-watching TV shows?',
|
||||||
|
'Who is the biggest procrastinator?',
|
||||||
|
'Who is the most likely to cry during a movie?',
|
||||||
|
'Who is the most adventurous when it comes to trying new foods?',
|
||||||
|
"Who is the most likely to forget someone's birthday?",
|
||||||
|
'Who is the best at giving advice?',
|
||||||
|
'Who is the worst at giving advice?',
|
||||||
|
'Who is the most likely to be found reading a book at a party?',
|
||||||
|
'Who is the most likely to win in a game of charades?',
|
||||||
|
'Who is the most likely to get lost in their own neighborhood?',
|
||||||
|
'Who is the most sentimental?',
|
||||||
|
'Who is the most likely to become famous?',
|
||||||
|
'Who is the most likely to become a millionaire?',
|
||||||
|
'Who is the most likely to start their own business?',
|
||||||
|
'Who is the most likely to become president?',
|
||||||
|
'Who is the most likely to go viral on social media?',
|
||||||
|
'Who is the most likely to win a Nobel Prize?',
|
||||||
|
'Who is the most likely to be a superhero in disguise?',
|
||||||
|
'Who is the most likely to survive a zombie apocalypse?',
|
||||||
|
'Who is the most likely to believe in aliens?',
|
||||||
|
'Who is the most likely to spend all their money on something silly?',
|
||||||
|
'Who is the most likely to write a bestselling novel?',
|
||||||
|
'Who is the most likely to be a secret agent?',
|
||||||
|
'Who is the most likely to be a professional athlete?',
|
||||||
|
'Who is the most likely to win a game of trivia?',
|
||||||
|
|
||||||
|
'Who is the most likely to win the upcoming game?',
|
||||||
|
'Who is the most likely to win at a game of Pokémon TCG?',
|
||||||
|
'Who has the most valuable card in their collection?',
|
||||||
|
'Who is the best at building decks?',
|
||||||
|
'Who has won the most games?',
|
||||||
|
'Who has the largest collection of cards?',
|
||||||
|
'Who is the most knowledgeable about Magic the Gathering lore?',
|
||||||
|
'Who is the most strategic?',
|
||||||
|
'Who is the most likely to trade away their most valuable card for something silly?',
|
||||||
|
'Who is the most competitive?',
|
||||||
|
'Who would be the most creative when it comes to making up new Magic the Gathering rules?',
|
||||||
|
'Who is the most likely to organize a Magic the Gathering draft tournament?',
|
||||||
|
'Who is the most enthusiastic about opening booster packs?',
|
||||||
|
'Who has the most unique and unusual Magic the Gathering deck?',
|
||||||
|
'Who is the most likely to cosplay as their favorite Magic the Gathering character?',
|
||||||
|
'Who is the most likely to forget to bring their Magic the Gathering deck to a game night?',
|
||||||
|
'Who is the most generous when it comes to lending out their decks?',
|
||||||
|
'Who is the most likely to start their own Magic the Gathering YouTube channel?',
|
||||||
|
'Who is the most skilled at bluffing during a game of Magic the Gathering?',
|
||||||
|
'Who is the most likely to spend all their money on Magic the Gathering cards?',
|
||||||
|
'Who is the most likely to rage quit during a game of Magic the Gathering?',
|
||||||
|
'Who is the most likely to win in a Magic the Gathering trivia contest?',
|
||||||
|
'Who is the most likely to build a themed Magic the Gathering deck?',
|
||||||
|
'Who is the most likely to organize a Magic the Gathering cube draft?',
|
||||||
|
'Who is the most likely to teach new players how to play Magic the Gathering?',
|
||||||
|
'Who is the most likely to build a commander deck with a ridiculous theme?',
|
||||||
|
'Who is the most likely to collect foreign-language Magic the Gathering cards?',
|
||||||
|
'Who is the most likely to participate in a Magic the Gathering charity event?',
|
||||||
|
'Who is the most likely to cosplay as their Magic the Gathering commander?',
|
||||||
|
'Who is the most likely to organize a Magic the Gathering charity tournament?',
|
||||||
|
];
|
||||||
|
|
||||||
|
export const Trivia = () => {
|
||||||
|
const { setPlaying, goToStart } = useGlobalSettings();
|
||||||
|
|
||||||
|
const [randomQuestion, setRandomQuestion] = useState(
|
||||||
|
questions[Math.floor(Math.random() * questions.length)]
|
||||||
|
);
|
||||||
|
|
||||||
|
const setUniqueRandomQuestion = () => {
|
||||||
|
let newRandomQuestion =
|
||||||
|
questions[Math.floor(Math.random() * questions.length)];
|
||||||
|
while (newRandomQuestion === randomQuestion) {
|
||||||
|
newRandomQuestion =
|
||||||
|
questions[Math.floor(Math.random() * questions.length)];
|
||||||
|
}
|
||||||
|
setRandomQuestion(newRandomQuestion);
|
||||||
|
};
|
||||||
|
|
||||||
|
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"
|
||||||
|
onClick={() => setPlaying(true)}
|
||||||
|
>
|
||||||
|
<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-[0.80rem]">{'<'} </div>
|
||||||
|
Back
|
||||||
|
</button>
|
||||||
|
|
||||||
|
<button
|
||||||
|
className="absolute flex top-4 right-4 rounded-lg px-2 py-1 justify-center bg-primary-main text-text-primary text-xs"
|
||||||
|
onClick={(e) => {
|
||||||
|
e.stopPropagation();
|
||||||
|
setUniqueRandomQuestion();
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
Reroll
|
||||||
|
</button>
|
||||||
|
|
||||||
|
<div className="size-full flex flex-col justify-between items-center whitespace-nowrap pointer-events-none webkit-user-select-none text-wrap text-center py-[10vmin] px-[10vmax]">
|
||||||
|
<div className="text-[6vmin]">Decide who starts by answering:</div>
|
||||||
|
<div className="flex flex-col">
|
||||||
|
<div className="text-[8vmin] rotate-180 text-text-primary opacity-40">
|
||||||
|
{randomQuestion}
|
||||||
|
</div>
|
||||||
|
<div className="text-[8vmin]">{randomQuestion}</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="text-[6vmin]">(Tap the screen to dismiss)</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
35
src/Components/PreStartGame/PreStart.tsx
Normal file
35
src/Components/PreStartGame/PreStart.tsx
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
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';
|
||||||
|
import { Trivia } from './Games/Trivia';
|
||||||
|
|
||||||
|
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 />;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (settings.preStartMode === PreStartMode.Trivia) {
|
||||||
|
return <Trivia />;
|
||||||
|
}
|
||||||
|
|
||||||
|
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,73 +1,115 @@
|
|||||||
import styled from 'styled-components';
|
import { useEffect } from 'react';
|
||||||
|
import { twc } from 'react-twc';
|
||||||
|
import { twGridTemplateAreas } from '../../../tailwind.config';
|
||||||
import { useGlobalSettings } from '../../Hooks/useGlobalSettings';
|
import { useGlobalSettings } from '../../Hooks/useGlobalSettings';
|
||||||
import { usePlayers } from '../../Hooks/usePlayers';
|
import { usePlayers } from '../../Hooks/usePlayers';
|
||||||
import { Orientation } from '../../Types/Settings';
|
import { Orientation, PreStartMode } from '../../Types/Settings';
|
||||||
import { Player } from '../Player/Player';
|
import { Players } from '../Players/Players';
|
||||||
|
import { PreStart } from '../PreStartGame/PreStart';
|
||||||
|
|
||||||
const MainWrapper = styled.div`
|
const MainWrapper = twc.div`w-[100dvmax] h-[100dvmin] overflow-hidden, setPlayers`;
|
||||||
width: 100vmax;
|
|
||||||
height: 100vmin;
|
type GridTemplateAreasKeys = keyof typeof twGridTemplateAreas;
|
||||||
width: 100dvmax;
|
|
||||||
height: 100dvmin;
|
export type GridLayout = `grid-areas-${GridTemplateAreasKeys}`;
|
||||||
overflow: hidden;
|
|
||||||
`;
|
|
||||||
|
|
||||||
export const Play = () => {
|
export const Play = () => {
|
||||||
const { players } = usePlayers();
|
const { players, setPlayers } = usePlayers();
|
||||||
const { initialGameSettings } = useGlobalSettings();
|
const { initialGameSettings, playing, settings, preStartCompleted } =
|
||||||
|
useGlobalSettings();
|
||||||
|
|
||||||
let Layout: JSX.Element;
|
let gridLayout: GridLayout;
|
||||||
switch (players.length) {
|
switch (players.length) {
|
||||||
case 1:
|
case 1:
|
||||||
if (initialGameSettings?.orientation === Orientation.Portrait) {
|
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;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
switch (initialGameSettings?.orientation) {
|
switch (initialGameSettings?.orientation) {
|
||||||
case Orientation.Portrait:
|
case Orientation.Portrait:
|
||||||
Layout = Player(players, 'grid-areas-twoPlayersOppositePortrait');
|
gridLayout = 'grid-areas-twoPlayersOppositePortrait';
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
case Orientation.Landscape:
|
case Orientation.Landscape:
|
||||||
Layout = Player(players, 'grid-areas-twoPlayersSameSideLandscape');
|
gridLayout = 'grid-areas-twoPlayersSameSideLandscape';
|
||||||
break;
|
break;
|
||||||
case Orientation.OppositeLandscape:
|
case Orientation.OppositeLandscape:
|
||||||
Layout = Player(players, 'grid-areas-twoPlayersOppositeLandscape');
|
gridLayout = 'grid-areas-twoPlayersOppositeLandscape';
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
if (initialGameSettings?.orientation === Orientation.Portrait) {
|
if (initialGameSettings?.orientation === Orientation.Portrait) {
|
||||||
Layout = Player(players, 'grid-areas-threePlayersSide');
|
gridLayout = 'grid-areas-threePlayersSide';
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
Layout = Player(players, 'grid-areas-threePlayers');
|
gridLayout = 'grid-areas-threePlayers';
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
case 4:
|
case 4:
|
||||||
if (initialGameSettings?.orientation === Orientation.Portrait) {
|
if (initialGameSettings?.orientation === Orientation.Portrait) {
|
||||||
Layout = Player(players, 'grid-areas-fourPlayerPortrait');
|
gridLayout = 'grid-areas-fourPlayerPortrait';
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
Layout = Player(players, 'grid-areas-fourPlayer');
|
gridLayout = 'grid-areas-fourPlayer';
|
||||||
break;
|
break;
|
||||||
case 5:
|
case 5:
|
||||||
if (initialGameSettings?.orientation === Orientation.Portrait) {
|
if (initialGameSettings?.orientation === Orientation.Portrait) {
|
||||||
Layout = Player(players, 'grid-areas-fivePlayersSide');
|
gridLayout = 'grid-areas-fivePlayersSide';
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
Layout = Player(players, 'grid-areas-fivePlayers');
|
gridLayout = 'grid-areas-fivePlayers';
|
||||||
break;
|
break;
|
||||||
case 6:
|
case 6:
|
||||||
if (initialGameSettings?.orientation === Orientation.Portrait) {
|
if (initialGameSettings?.orientation === Orientation.Portrait) {
|
||||||
Layout = Player(players, 'grid-areas-sixPlayersSide');
|
gridLayout = 'grid-areas-sixPlayersSide';
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
Layout = Player(players, 'grid-areas-sixPlayers');
|
gridLayout = 'grid-areas-sixPlayers';
|
||||||
break;
|
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>
|
||||||
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,13 +1,14 @@
|
|||||||
import { FormControlLabel, Radio, RadioGroup } from '@mui/material';
|
import { FormControlLabel, Radio, RadioGroup } from '@mui/material';
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import styled from 'styled-components';
|
|
||||||
import { theme } from '../../../Data/theme';
|
import { theme } from '../../../Data/theme';
|
||||||
import {
|
import {
|
||||||
FivePlayers,
|
FivePlayers,
|
||||||
|
FivePlayersSide,
|
||||||
FourPlayers,
|
FourPlayers,
|
||||||
FourPlayersSide,
|
FourPlayersSide,
|
||||||
OnePlayerPortrait,
|
OnePlayerPortrait,
|
||||||
SixPlayers,
|
SixPlayers,
|
||||||
|
SixPlayersSide,
|
||||||
ThreePlayers,
|
ThreePlayers,
|
||||||
ThreePlayersSide,
|
ThreePlayersSide,
|
||||||
TwoPlayersOppositeLandscape,
|
TwoPlayersOppositeLandscape,
|
||||||
@@ -15,14 +16,11 @@ import {
|
|||||||
TwoPlayersSameSide,
|
TwoPlayersSameSide,
|
||||||
} from '../../../Icons/generated/Layouts';
|
} from '../../../Icons/generated/Layouts';
|
||||||
|
|
||||||
|
import { twc } from 'react-twc';
|
||||||
import OnePlayerLandscape from '../../../Icons/generated/Layouts/OnePlayerLandscape';
|
import OnePlayerLandscape from '../../../Icons/generated/Layouts/OnePlayerLandscape';
|
||||||
import { Orientation } from '../../../Types/Settings';
|
import { Orientation } from '../../../Types/Settings';
|
||||||
|
|
||||||
const LayoutWrapper = styled.div`
|
const LayoutWrapper = twc.div`flex flex-row justify-center items-center self-center w-full`;
|
||||||
flex-direction: row;
|
|
||||||
display: flex;
|
|
||||||
justify-content: space-evenly;
|
|
||||||
`;
|
|
||||||
|
|
||||||
type LayoutOptionsProps = {
|
type LayoutOptionsProps = {
|
||||||
numberOfPlayers: number;
|
numberOfPlayers: number;
|
||||||
@@ -35,8 +33,10 @@ export const LayoutOptions: React.FC<LayoutOptionsProps> = ({
|
|||||||
selectedOrientation,
|
selectedOrientation,
|
||||||
onChange,
|
onChange,
|
||||||
}) => {
|
}) => {
|
||||||
const iconHeight = '30vmin';
|
const iconWidth = '21vmin';
|
||||||
const iconWidth = '20vmin';
|
const iconHeight = '40vmin';
|
||||||
|
const iconMaxWidth = '124px';
|
||||||
|
const iconMaxHeight = '196px';
|
||||||
|
|
||||||
const renderLayoutOptions = () => {
|
const renderLayoutOptions = () => {
|
||||||
switch (numberOfPlayers) {
|
switch (numberOfPlayers) {
|
||||||
@@ -62,6 +62,7 @@ export const LayoutOptions: React.FC<LayoutOptionsProps> = ({
|
|||||||
/>
|
/>
|
||||||
}
|
}
|
||||||
TouchRippleProps={{ style: { display: 'none' } }}
|
TouchRippleProps={{ style: { display: 'none' } }}
|
||||||
|
style={{ maxWidth: iconMaxWidth, maxHeight: iconMaxHeight }}
|
||||||
/>
|
/>
|
||||||
}
|
}
|
||||||
label=""
|
label=""
|
||||||
@@ -85,6 +86,7 @@ export const LayoutOptions: React.FC<LayoutOptionsProps> = ({
|
|||||||
/>
|
/>
|
||||||
}
|
}
|
||||||
TouchRippleProps={{ style: { display: 'none' } }}
|
TouchRippleProps={{ style: { display: 'none' } }}
|
||||||
|
style={{ maxWidth: iconMaxWidth, maxHeight: iconMaxHeight }}
|
||||||
/>
|
/>
|
||||||
}
|
}
|
||||||
label=""
|
label=""
|
||||||
@@ -98,6 +100,7 @@ export const LayoutOptions: React.FC<LayoutOptionsProps> = ({
|
|||||||
value={Orientation.Landscape}
|
value={Orientation.Landscape}
|
||||||
control={
|
control={
|
||||||
<Radio
|
<Radio
|
||||||
|
style={{ maxWidth: iconMaxWidth, maxHeight: iconMaxHeight }}
|
||||||
icon={
|
icon={
|
||||||
<TwoPlayersSameSide
|
<TwoPlayersSameSide
|
||||||
height={iconHeight}
|
height={iconHeight}
|
||||||
@@ -121,6 +124,7 @@ export const LayoutOptions: React.FC<LayoutOptionsProps> = ({
|
|||||||
value={Orientation.Portrait}
|
value={Orientation.Portrait}
|
||||||
control={
|
control={
|
||||||
<Radio
|
<Radio
|
||||||
|
style={{ maxWidth: iconMaxWidth, maxHeight: iconMaxHeight }}
|
||||||
icon={
|
icon={
|
||||||
<TwoPlayersOppositePortrait
|
<TwoPlayersOppositePortrait
|
||||||
height={iconHeight}
|
height={iconHeight}
|
||||||
@@ -144,6 +148,7 @@ export const LayoutOptions: React.FC<LayoutOptionsProps> = ({
|
|||||||
value={Orientation.OppositeLandscape}
|
value={Orientation.OppositeLandscape}
|
||||||
control={
|
control={
|
||||||
<Radio
|
<Radio
|
||||||
|
style={{ maxWidth: iconMaxWidth, maxHeight: iconMaxHeight }}
|
||||||
icon={
|
icon={
|
||||||
<TwoPlayersOppositeLandscape
|
<TwoPlayersOppositeLandscape
|
||||||
height={iconHeight}
|
height={iconHeight}
|
||||||
@@ -172,6 +177,7 @@ export const LayoutOptions: React.FC<LayoutOptionsProps> = ({
|
|||||||
value={Orientation.Landscape}
|
value={Orientation.Landscape}
|
||||||
control={
|
control={
|
||||||
<Radio
|
<Radio
|
||||||
|
style={{ maxWidth: iconMaxWidth, maxHeight: iconMaxHeight }}
|
||||||
icon={
|
icon={
|
||||||
<ThreePlayers
|
<ThreePlayers
|
||||||
height={iconHeight}
|
height={iconHeight}
|
||||||
@@ -195,6 +201,7 @@ export const LayoutOptions: React.FC<LayoutOptionsProps> = ({
|
|||||||
value={Orientation.Portrait}
|
value={Orientation.Portrait}
|
||||||
control={
|
control={
|
||||||
<Radio
|
<Radio
|
||||||
|
style={{ maxWidth: iconMaxWidth, maxHeight: iconMaxHeight }}
|
||||||
icon={
|
icon={
|
||||||
<ThreePlayersSide
|
<ThreePlayersSide
|
||||||
height={iconHeight}
|
height={iconHeight}
|
||||||
@@ -224,6 +231,7 @@ export const LayoutOptions: React.FC<LayoutOptionsProps> = ({
|
|||||||
value={Orientation.Landscape}
|
value={Orientation.Landscape}
|
||||||
control={
|
control={
|
||||||
<Radio
|
<Radio
|
||||||
|
style={{ maxWidth: iconMaxWidth, maxHeight: iconMaxHeight }}
|
||||||
icon={
|
icon={
|
||||||
<FourPlayers
|
<FourPlayers
|
||||||
height={iconHeight}
|
height={iconHeight}
|
||||||
@@ -247,6 +255,7 @@ export const LayoutOptions: React.FC<LayoutOptionsProps> = ({
|
|||||||
value={Orientation.Portrait}
|
value={Orientation.Portrait}
|
||||||
control={
|
control={
|
||||||
<Radio
|
<Radio
|
||||||
|
style={{ maxWidth: iconMaxWidth, maxHeight: iconMaxHeight }}
|
||||||
icon={
|
icon={
|
||||||
<FourPlayersSide
|
<FourPlayersSide
|
||||||
height={iconHeight}
|
height={iconHeight}
|
||||||
@@ -276,6 +285,7 @@ export const LayoutOptions: React.FC<LayoutOptionsProps> = ({
|
|||||||
value={Orientation.Landscape}
|
value={Orientation.Landscape}
|
||||||
control={
|
control={
|
||||||
<Radio
|
<Radio
|
||||||
|
style={{ maxWidth: iconMaxWidth, maxHeight: iconMaxHeight }}
|
||||||
icon={
|
icon={
|
||||||
<FivePlayers
|
<FivePlayers
|
||||||
height={iconHeight}
|
height={iconHeight}
|
||||||
@@ -295,20 +305,21 @@ export const LayoutOptions: React.FC<LayoutOptionsProps> = ({
|
|||||||
}
|
}
|
||||||
label=""
|
label=""
|
||||||
/>
|
/>
|
||||||
{/* <FormControlLabel
|
<FormControlLabel
|
||||||
value={GridTemplateAreas.FivePlayersSide}
|
value={Orientation.Portrait}
|
||||||
control={
|
control={
|
||||||
<Radio
|
<Radio
|
||||||
|
style={{ maxWidth: iconMaxWidth, maxHeight: iconMaxHeight }}
|
||||||
icon={
|
icon={
|
||||||
<FivePlayersSide
|
<FivePlayersSide
|
||||||
height={iconHeight}
|
height={iconHeight}
|
||||||
width={iconWidth}
|
width={iconWidth}
|
||||||
fill={theme.palette.secondary.main}
|
fill={theme.palette.secondary.main}
|
||||||
/>
|
/>
|
||||||
}
|
}
|
||||||
checkedIcon={
|
checkedIcon={
|
||||||
<FivePlayersSide
|
<FivePlayersSide
|
||||||
height={iconHeight}
|
height={iconHeight}
|
||||||
width={iconWidth}
|
width={iconWidth}
|
||||||
fill={theme.palette.primary.main}
|
fill={theme.palette.primary.main}
|
||||||
/>
|
/>
|
||||||
@@ -317,7 +328,7 @@ export const LayoutOptions: React.FC<LayoutOptionsProps> = ({
|
|||||||
/>
|
/>
|
||||||
}
|
}
|
||||||
label=""
|
label=""
|
||||||
/> */}
|
/>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -328,6 +339,7 @@ export const LayoutOptions: React.FC<LayoutOptionsProps> = ({
|
|||||||
value={Orientation.Landscape}
|
value={Orientation.Landscape}
|
||||||
control={
|
control={
|
||||||
<Radio
|
<Radio
|
||||||
|
style={{ maxWidth: iconMaxWidth, maxHeight: iconMaxHeight }}
|
||||||
icon={
|
icon={
|
||||||
<SixPlayers
|
<SixPlayers
|
||||||
height={iconHeight}
|
height={iconHeight}
|
||||||
@@ -347,20 +359,21 @@ export const LayoutOptions: React.FC<LayoutOptionsProps> = ({
|
|||||||
}
|
}
|
||||||
label=""
|
label=""
|
||||||
/>
|
/>
|
||||||
{/* <FormControlLabel
|
<FormControlLabel
|
||||||
value={GridTemplateAreas.SixPlayersSide}
|
value={Orientation.Portrait}
|
||||||
control={
|
control={
|
||||||
<Radio
|
<Radio
|
||||||
|
style={{ maxWidth: iconMaxWidth, maxHeight: iconMaxHeight }}
|
||||||
icon={
|
icon={
|
||||||
<SixPlayersSide
|
<SixPlayersSide
|
||||||
height={iconHeight}
|
height={iconHeight}
|
||||||
width={iconWidth}
|
width={iconWidth}
|
||||||
fill={theme.palette.secondary.main}
|
fill={theme.palette.secondary.main}
|
||||||
/>
|
/>
|
||||||
}
|
}
|
||||||
checkedIcon={
|
checkedIcon={
|
||||||
<SixPlayersSide
|
<SixPlayersSide
|
||||||
height={iconHeight}
|
height={iconHeight}
|
||||||
width={iconWidth}
|
width={iconWidth}
|
||||||
fill={theme.palette.primary.main}
|
fill={theme.palette.primary.main}
|
||||||
/>
|
/>
|
||||||
@@ -369,7 +382,7 @@ export const LayoutOptions: React.FC<LayoutOptionsProps> = ({
|
|||||||
/>
|
/>
|
||||||
}
|
}
|
||||||
label=""
|
label=""
|
||||||
/> */}
|
/>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@@ -1,50 +1,33 @@
|
|||||||
import { Button, FormControl, FormLabel, Switch } from '@mui/material';
|
import { Button, FormControl, FormLabel, Switch } from '@mui/material';
|
||||||
import Slider from '@mui/material/Slider';
|
import Slider from '@mui/material/Slider';
|
||||||
import { useEffect, useState } from 'react';
|
import { useEffect, useState } from 'react';
|
||||||
import styled from 'styled-components';
|
import { twc } from 'react-twc';
|
||||||
import { createInitialPlayers } from '../../../Data/getInitialPlayers';
|
import { createInitialPlayers } from '../../../Data/getInitialPlayers';
|
||||||
import { theme } from '../../../Data/theme';
|
import { theme } from '../../../Data/theme';
|
||||||
import { useAnalytics } from '../../../Hooks/useAnalytics';
|
import { useAnalytics } from '../../../Hooks/useAnalytics';
|
||||||
import { useGlobalSettings } from '../../../Hooks/useGlobalSettings';
|
import { useGlobalSettings } from '../../../Hooks/useGlobalSettings';
|
||||||
import { usePlayers } from '../../../Hooks/usePlayers';
|
import { usePlayers } from '../../../Hooks/usePlayers';
|
||||||
import { Cog, Info } from '../../../Icons/generated';
|
import { Cog, Info } from '../../../Icons/generated';
|
||||||
import { InitialGameSettings, Orientation } from '../../../Types/Settings';
|
import {
|
||||||
|
InitialGameSettings,
|
||||||
|
Orientation,
|
||||||
|
PreStartMode,
|
||||||
|
defaultInitialGameSettings,
|
||||||
|
} from '../../../Types/Settings';
|
||||||
import { InfoModal } from '../../Misc/InfoModal';
|
import { InfoModal } from '../../Misc/InfoModal';
|
||||||
import { SettingsModal } from '../../Misc/SettingsModal';
|
import { SettingsModal } from '../../Misc/SettingsModal';
|
||||||
import { Spacer } from '../../Misc/Spacer';
|
|
||||||
import { SupportMe } from '../../Misc/SupportMe';
|
import { SupportMe } from '../../Misc/SupportMe';
|
||||||
import { H1, Paragraph } from '../../Misc/TextComponents';
|
|
||||||
import { LayoutOptions } from './LayoutOptions';
|
import { LayoutOptions } from './LayoutOptions';
|
||||||
|
|
||||||
const MainWrapper = styled.div`
|
const MainWrapper = twc.div`w-[100dvw] h-fit pb-14 overflow-hidden items-center flex flex-col`;
|
||||||
width: 100dvw;
|
|
||||||
height: fit-content;
|
|
||||||
padding-bottom: 58px;
|
|
||||||
overflow: hidden;
|
|
||||||
align-items: center;
|
|
||||||
display: flex;
|
|
||||||
flex-direction: column;
|
|
||||||
`;
|
|
||||||
|
|
||||||
const StartButtonFooter = styled.div`
|
const StartButtonFooter = twc.div`w-full max-w-[548px] fixed bottom-4 z-1 items-center flex flex-col px-4 z-10`;
|
||||||
position: fixed;
|
|
||||||
bottom: 1rem;
|
|
||||||
translate: -50%, -50%;
|
|
||||||
z-index: 1;
|
|
||||||
`;
|
|
||||||
|
|
||||||
const ToggleButtonsWrapper = styled.div`
|
const SliderWrapper = twc.div`mx-8`;
|
||||||
display: flex;
|
|
||||||
flex-direction: row;
|
|
||||||
justify-content: space-between;
|
|
||||||
align-items: center;
|
|
||||||
`;
|
|
||||||
|
|
||||||
const ToggleContainer = styled.div`
|
const ToggleButtonsWrapper = twc.div`flex flex-row justify-between items-center`;
|
||||||
display: flex;
|
|
||||||
flex-direction: column;
|
const ToggleContainer = twc.div`flex flex-col items-center`;
|
||||||
align-items: center;
|
|
||||||
`;
|
|
||||||
|
|
||||||
const playerMarks = [
|
const playerMarks = [
|
||||||
{
|
{
|
||||||
@@ -107,27 +90,50 @@ const Start = () => {
|
|||||||
setInitialGameSettings,
|
setInitialGameSettings,
|
||||||
settings,
|
settings,
|
||||||
isPWA,
|
isPWA,
|
||||||
|
setRandomizingPlayer,
|
||||||
|
version,
|
||||||
} = useGlobalSettings();
|
} = useGlobalSettings();
|
||||||
|
|
||||||
const [openInfoModal, setOpenInfoModal] = useState(false);
|
const [openInfoModal, setOpenInfoModal] = useState(false);
|
||||||
const [openSettingsModal, setOpenSettingsModal] = useState(false);
|
const [openSettingsModal, setOpenSettingsModal] = useState(false);
|
||||||
|
|
||||||
const [playerOptions, setPlayerOptions] = useState<InitialGameSettings>(
|
const [playerOptions, setPlayerOptions] = useState<InitialGameSettings>(
|
||||||
initialGameSettings || {
|
initialGameSettings || defaultInitialGameSettings
|
||||||
numberOfPlayers: 4,
|
|
||||||
startingLifeTotal: 40,
|
|
||||||
useCommanderDamage: true,
|
|
||||||
orientation: Orientation.Portrait,
|
|
||||||
gameFormat: 'commander',
|
|
||||||
}
|
|
||||||
);
|
);
|
||||||
|
|
||||||
|
let tracked = false;
|
||||||
|
// Check for new version on mount
|
||||||
|
useEffect(() => {
|
||||||
|
if (!tracked) {
|
||||||
|
console.log('checking version');
|
||||||
|
version.checkForNewVersion('start_menu');
|
||||||
|
|
||||||
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
|
tracked = true;
|
||||||
|
}
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
setInitialGameSettings(playerOptions);
|
||||||
|
}, [playerOptions, setInitialGameSettings]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
setPlayerOptions({
|
||||||
|
...playerOptions,
|
||||||
|
});
|
||||||
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
|
}, [playerOptions.numberOfPlayers]);
|
||||||
|
|
||||||
const doStartGame = () => {
|
const doStartGame = () => {
|
||||||
if (!initialGameSettings) {
|
if (!initialGameSettings) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
analytics.trackEvent('game_started', { ...initialGameSettings });
|
analytics.trackEvent('game_started', {
|
||||||
|
...initialGameSettings,
|
||||||
|
...settings,
|
||||||
|
isPWA,
|
||||||
|
});
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (settings.goFullscreenOnStart) {
|
if (settings.goFullscreenOnStart) {
|
||||||
@@ -144,25 +150,15 @@ const Start = () => {
|
|||||||
setInitialGameSettings(initialGameSettings);
|
setInitialGameSettings(initialGameSettings);
|
||||||
setPlayers(createInitialPlayers(initialGameSettings));
|
setPlayers(createInitialPlayers(initialGameSettings));
|
||||||
setShowPlay(true);
|
setShowPlay(true);
|
||||||
|
setRandomizingPlayer(settings.preStartMode === PreStartMode.RandomKing);
|
||||||
localStorage.setItem('playing', 'false');
|
localStorage.setItem('playing', 'false');
|
||||||
localStorage.setItem('showPlay', 'true');
|
localStorage.setItem('showPlay', 'true');
|
||||||
};
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
const valueText = (value: number) => {
|
||||||
setInitialGameSettings(playerOptions);
|
|
||||||
}, [playerOptions, setInitialGameSettings]);
|
|
||||||
|
|
||||||
const valuetext = (value: number) => {
|
|
||||||
return `${value}`;
|
return `${value}`;
|
||||||
};
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
setPlayerOptions({
|
|
||||||
...playerOptions,
|
|
||||||
});
|
|
||||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
||||||
}, [playerOptions.numberOfPlayers]);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<MainWrapper>
|
<MainWrapper>
|
||||||
<Info
|
<Info
|
||||||
@@ -190,130 +186,143 @@ const Start = () => {
|
|||||||
|
|
||||||
<SupportMe />
|
<SupportMe />
|
||||||
|
|
||||||
<H1>Life Trinket</H1>
|
<h1 className="relative flex flex-col text-3xl font-bold mt-6 mb-6 text-text-primary justify-center items-center">
|
||||||
<FormControl focused={false} style={{ width: '80vw' }}>
|
Life Trinket
|
||||||
<FormLabel>Number of Players</FormLabel>
|
<div className="h-[1px] w-[120%] bg-common-white opacity-50" />
|
||||||
<Slider
|
<div className="flex absolute text-xs font-medium -bottom-4">
|
||||||
title="Number of Players"
|
v{version.installedVersion}
|
||||||
max={6}
|
</div>
|
||||||
min={1}
|
</h1>
|
||||||
aria-label="Custom marks"
|
|
||||||
value={playerOptions?.numberOfPlayers ?? 4}
|
|
||||||
getAriaValueText={valuetext}
|
|
||||||
step={null}
|
|
||||||
marks={playerMarks}
|
|
||||||
onChange={(_e, value) => {
|
|
||||||
setPlayerOptions({
|
|
||||||
...playerOptions,
|
|
||||||
numberOfPlayers: value as number,
|
|
||||||
orientation: Orientation.Landscape,
|
|
||||||
});
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
<Spacer height="0.7rem" />
|
|
||||||
<FormLabel>Starting Health</FormLabel>
|
|
||||||
<Slider
|
|
||||||
title="Starting Health"
|
|
||||||
max={60}
|
|
||||||
min={20}
|
|
||||||
aria-label="Custom marks"
|
|
||||||
value={playerOptions?.startingLifeTotal ?? 40}
|
|
||||||
getAriaValueText={valuetext}
|
|
||||||
step={10}
|
|
||||||
marks={healthMarks}
|
|
||||||
onChange={(_e, value) =>
|
|
||||||
setPlayerOptions({
|
|
||||||
...playerOptions,
|
|
||||||
startingLifeTotal: value as number,
|
|
||||||
orientation: Orientation.Landscape,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
/>
|
|
||||||
<Spacer height="1rem" />
|
|
||||||
|
|
||||||
<ToggleButtonsWrapper>
|
<div className="overflow-hidden items-center flex flex-col max-w-[548px] w-full mb-8 px-4">
|
||||||
<ToggleContainer>
|
<FormControl focused={false} style={{ width: '100%' }}>
|
||||||
<FormLabel>Commander</FormLabel>
|
<FormLabel>Number of Players</FormLabel>
|
||||||
<Switch
|
<SliderWrapper>
|
||||||
checked={
|
<Slider
|
||||||
playerOptions.useCommanderDamage ??
|
title="Number of Players"
|
||||||
initialGameSettings?.useCommanderDamage ??
|
max={6}
|
||||||
true
|
min={1}
|
||||||
}
|
aria-label="Custom marks"
|
||||||
|
value={playerOptions?.numberOfPlayers ?? 4}
|
||||||
|
getAriaValueText={valueText}
|
||||||
|
step={null}
|
||||||
|
marks={playerMarks}
|
||||||
onChange={(_e, value) => {
|
onChange={(_e, value) => {
|
||||||
if (value) {
|
|
||||||
setPlayerOptions({
|
|
||||||
...playerOptions,
|
|
||||||
useCommanderDamage: value,
|
|
||||||
numberOfPlayers: 4,
|
|
||||||
startingLifeTotal: 40,
|
|
||||||
orientation: Orientation.Landscape,
|
|
||||||
});
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
setPlayerOptions({
|
setPlayerOptions({
|
||||||
...playerOptions,
|
...playerOptions,
|
||||||
useCommanderDamage: value,
|
numberOfPlayers: value as number,
|
||||||
numberOfPlayers: 2,
|
|
||||||
startingLifeTotal: 20,
|
|
||||||
orientation: Orientation.Landscape,
|
orientation: Orientation.Landscape,
|
||||||
});
|
});
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
</ToggleContainer>
|
</SliderWrapper>
|
||||||
<Button
|
|
||||||
variant="contained"
|
<FormLabel className="mt-[0.7rem]">Starting Health</FormLabel>
|
||||||
style={{ height: '2rem' }}
|
<SliderWrapper>
|
||||||
onClick={() => {
|
<Slider
|
||||||
setOpenSettingsModal(true);
|
title="Starting Health"
|
||||||
|
max={60}
|
||||||
|
min={20}
|
||||||
|
aria-label="Custom marks"
|
||||||
|
value={playerOptions?.startingLifeTotal ?? 40}
|
||||||
|
getAriaValueText={valueText}
|
||||||
|
step={10}
|
||||||
|
marks={healthMarks}
|
||||||
|
onChange={(_e, value) =>
|
||||||
|
setPlayerOptions({
|
||||||
|
...playerOptions,
|
||||||
|
startingLifeTotal: value as number,
|
||||||
|
orientation: Orientation.Landscape,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
</SliderWrapper>
|
||||||
|
|
||||||
|
<ToggleButtonsWrapper className="mt-4">
|
||||||
|
<ToggleContainer>
|
||||||
|
<FormLabel>Commander</FormLabel>
|
||||||
|
<Switch
|
||||||
|
checked={
|
||||||
|
playerOptions.useCommanderDamage ??
|
||||||
|
initialGameSettings?.useCommanderDamage ??
|
||||||
|
true
|
||||||
|
}
|
||||||
|
onChange={(_e, value) => {
|
||||||
|
if (value) {
|
||||||
|
setPlayerOptions({
|
||||||
|
...playerOptions,
|
||||||
|
useCommanderDamage: value,
|
||||||
|
numberOfPlayers: 4,
|
||||||
|
startingLifeTotal: 40,
|
||||||
|
orientation: Orientation.Landscape,
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
setPlayerOptions({
|
||||||
|
...playerOptions,
|
||||||
|
useCommanderDamage: value,
|
||||||
|
numberOfPlayers: 2,
|
||||||
|
startingLifeTotal: 20,
|
||||||
|
orientation: Orientation.Landscape,
|
||||||
|
});
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</ToggleContainer>
|
||||||
|
<div className="flex flex-nowrap text-nowrap relative justify-center items-start">
|
||||||
|
<Button
|
||||||
|
variant="contained"
|
||||||
|
style={{ height: '2rem' }}
|
||||||
|
onClick={() => {
|
||||||
|
setOpenSettingsModal(true);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Cog /> Game Settings
|
||||||
|
</Button>
|
||||||
|
|
||||||
|
<div
|
||||||
|
data-not-latest-version={
|
||||||
|
!version.isLatest && !!version.remoteVersion
|
||||||
|
}
|
||||||
|
className="absolute flex justify-center text-text-primary text-xxs -bottom-5 bg-primary-dark px-2 rounded-md
|
||||||
|
opacity-0 transition-all duration-200 delay-500
|
||||||
|
data-[not-latest-version=true]:opacity-100
|
||||||
|
"
|
||||||
|
>
|
||||||
|
<div className="absolute bg-primary-dark rotate-45 size-2 -top-[2px] z-0" />
|
||||||
|
<span className="z-10">
|
||||||
|
v{version.remoteVersion} available!
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</ToggleButtonsWrapper>
|
||||||
|
|
||||||
|
<FormLabel>Layout</FormLabel>
|
||||||
|
<LayoutOptions
|
||||||
|
numberOfPlayers={playerOptions.numberOfPlayers}
|
||||||
|
selectedOrientation={playerOptions.orientation}
|
||||||
|
onChange={(orientation) => {
|
||||||
|
setPlayerOptions({
|
||||||
|
...playerOptions,
|
||||||
|
orientation,
|
||||||
|
});
|
||||||
}}
|
}}
|
||||||
>
|
/>
|
||||||
<Cog /> Other settings
|
</FormControl>
|
||||||
</Button>
|
{!isPWA && (
|
||||||
</ToggleButtonsWrapper>
|
<p className="text-center text-xs text-text-primary w-11/12 mt-4">
|
||||||
|
If you're on iOS, this page works better if you{' '}
|
||||||
<FormLabel>Layout</FormLabel>
|
<strong>hide the toolbar</strong> or{' '}
|
||||||
{/* <LayoutOptions
|
<strong>add the app to your home screen</strong>.
|
||||||
numberOfPlayers={playerOptions.numberOfPlayers}
|
</p>
|
||||||
gridAreas={playerOptions.gridAreas}
|
)}
|
||||||
onChange={(gridAreas) =>
|
</div>
|
||||||
setPlayerOptions({
|
|
||||||
...playerOptions,
|
|
||||||
gridAreas,
|
|
||||||
//TODO fix the layout selection
|
|
||||||
orientation: Orientation.Portrait,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
/> */}
|
|
||||||
<LayoutOptions
|
|
||||||
numberOfPlayers={playerOptions.numberOfPlayers}
|
|
||||||
selectedOrientation={playerOptions.orientation}
|
|
||||||
onChange={(orientation) => {
|
|
||||||
console.log('orientation', { orientation });
|
|
||||||
setPlayerOptions({
|
|
||||||
...playerOptions,
|
|
||||||
orientation,
|
|
||||||
});
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
</FormControl>
|
|
||||||
|
|
||||||
{!isPWA && (
|
|
||||||
<Paragraph
|
|
||||||
style={{ textAlign: 'center', maxWidth: '75%', fontSize: '0.7rem' }}
|
|
||||||
>
|
|
||||||
If you're on iOS, this page works better if you{' '}
|
|
||||||
<strong>hide the toolbar</strong> or{' '}
|
|
||||||
<strong>add the app to your home screen</strong>.
|
|
||||||
</Paragraph>
|
|
||||||
)}
|
|
||||||
|
|
||||||
<StartButtonFooter>
|
<StartButtonFooter>
|
||||||
<Button
|
<Button
|
||||||
size="large"
|
size="large"
|
||||||
variant="contained"
|
variant="contained"
|
||||||
onClick={doStartGame}
|
onClick={doStartGame}
|
||||||
style={{ width: '90dvw' }}
|
fullWidth
|
||||||
>
|
>
|
||||||
START GAME
|
START GAME
|
||||||
</Button>
|
</Button>
|
||||||
|
|||||||
@@ -1,6 +1,13 @@
|
|||||||
import { createContext } from 'react';
|
import { createContext } from 'react';
|
||||||
import { InitialGameSettings, Settings } from '../Types/Settings';
|
import { InitialGameSettings, Settings } from '../Types/Settings';
|
||||||
|
|
||||||
|
type Version = {
|
||||||
|
installedVersion: string;
|
||||||
|
isLatest: boolean;
|
||||||
|
checkForNewVersion: (source: 'settings' | 'start_menu') => Promise<void>;
|
||||||
|
remoteVersion?: string;
|
||||||
|
};
|
||||||
|
|
||||||
export type GlobalSettingsContextType = {
|
export type GlobalSettingsContextType = {
|
||||||
fullscreen: {
|
fullscreen: {
|
||||||
isFullscreen: boolean;
|
isFullscreen: boolean;
|
||||||
@@ -22,7 +29,15 @@ export type GlobalSettingsContextType = {
|
|||||||
setInitialGameSettings: (initialGameSettings: InitialGameSettings) => void;
|
setInitialGameSettings: (initialGameSettings: InitialGameSettings) => void;
|
||||||
settings: Settings;
|
settings: Settings;
|
||||||
setSettings: (settings: Settings) => void;
|
setSettings: (settings: Settings) => void;
|
||||||
|
playing: boolean;
|
||||||
|
setPlaying: (playing: boolean) => void;
|
||||||
|
randomizingPlayer: boolean;
|
||||||
|
setRandomizingPlayer: (stopRandom: boolean) => void;
|
||||||
isPWA: boolean;
|
isPWA: boolean;
|
||||||
|
preStartCompleted: boolean;
|
||||||
|
setPreStartCompleted: (completed: boolean) => void;
|
||||||
|
|
||||||
|
version: Version;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const GlobalSettingsContext =
|
export const GlobalSettingsContext =
|
||||||
|
|||||||
@@ -7,6 +7,8 @@ export type PlayersContextType = {
|
|||||||
updatePlayer: (updatedPlayer: Player) => void;
|
updatePlayer: (updatedPlayer: Player) => void;
|
||||||
updateLifeTotal: (player: Player, updatedLifeTotal: number) => number;
|
updateLifeTotal: (player: Player, updatedLifeTotal: number) => number;
|
||||||
resetCurrentGame: () => void;
|
resetCurrentGame: () => void;
|
||||||
|
startingPlayerIndex: number;
|
||||||
|
setStartingPlayerIndex: (index: number) => void;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const PlayersContext = createContext<PlayersContextType | null>(null);
|
export const PlayersContext = createContext<PlayersContextType | null>(null);
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { Player, Rotation } from '../Types/Player';
|
import { Player, Rotation } from '../Types/Player';
|
||||||
import { InitialGameSettings, Orientation } from '../Types/Settings';
|
import { InitialGameSettings, Orientation } from '../Types/Settings';
|
||||||
|
|
||||||
const presetColors = [
|
export const presetColors = [
|
||||||
'#F06292', // Light Pink
|
'#F06292', // Light Pink
|
||||||
'#4DB6AC', // Teal
|
'#4DB6AC', // Teal
|
||||||
'#FFA726', // Orange
|
'#FFA726', // Orange
|
||||||
@@ -127,15 +127,15 @@ const getOrientationRotations = (
|
|||||||
case Orientation.Portrait:
|
case Orientation.Portrait:
|
||||||
switch (index) {
|
switch (index) {
|
||||||
case 0:
|
case 0:
|
||||||
return Rotation.Side;
|
return Rotation.Flipped;
|
||||||
case 1:
|
case 1:
|
||||||
return Rotation.Side;
|
return Rotation.Flipped;
|
||||||
case 2:
|
case 2:
|
||||||
return Rotation.SideFlipped;
|
return Rotation.Side;
|
||||||
case 3:
|
case 3:
|
||||||
return Rotation.SideFlipped;
|
return Rotation.Normal;
|
||||||
case 4:
|
case 4:
|
||||||
return Rotation.SideFlipped;
|
return Rotation.Normal;
|
||||||
default:
|
default:
|
||||||
return Rotation.Normal;
|
return Rotation.Normal;
|
||||||
}
|
}
|
||||||
@@ -163,17 +163,17 @@ const getOrientationRotations = (
|
|||||||
case Orientation.Portrait:
|
case Orientation.Portrait:
|
||||||
switch (index) {
|
switch (index) {
|
||||||
case 0:
|
case 0:
|
||||||
return Rotation.Side;
|
return Rotation.SideFlipped;
|
||||||
case 1:
|
case 1:
|
||||||
return Rotation.Side;
|
return Rotation.Flipped;
|
||||||
case 2:
|
case 2:
|
||||||
return Rotation.Side;
|
return Rotation.Flipped;
|
||||||
case 3:
|
case 3:
|
||||||
return Rotation.SideFlipped;
|
return Rotation.Side;
|
||||||
case 4:
|
case 4:
|
||||||
return Rotation.SideFlipped;
|
return Rotation.Normal;
|
||||||
case 5:
|
case 5:
|
||||||
return Rotation.SideFlipped;
|
return Rotation.Normal;
|
||||||
default:
|
default:
|
||||||
return Rotation.Normal;
|
return Rotation.Normal;
|
||||||
}
|
}
|
||||||
@@ -191,10 +191,8 @@ export const createInitialPlayers = ({
|
|||||||
}: InitialGameSettings): Player[] => {
|
}: InitialGameSettings): 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];
|
||||||
|
|
||||||
@@ -224,11 +222,11 @@ export const createInitialPlayers = ({
|
|||||||
usePoison: false,
|
usePoison: false,
|
||||||
rotation,
|
rotation,
|
||||||
},
|
},
|
||||||
isStartingPlayer,
|
|
||||||
showStartingPlayer: isStartingPlayer,
|
|
||||||
extraCounters: [],
|
extraCounters: [],
|
||||||
commanderDamage,
|
commanderDamage,
|
||||||
hasLost: false,
|
hasLost: false,
|
||||||
|
isStartingPlayer: false,
|
||||||
|
isSide: rotation === Rotation.Side || rotation === Rotation.SideFlipped,
|
||||||
};
|
};
|
||||||
|
|
||||||
players.push(player);
|
players.push(player);
|
||||||
|
|||||||
@@ -1,34 +1,28 @@
|
|||||||
import { createTheme } from '@mui/material';
|
import { createTheme } from '@mui/material';
|
||||||
|
import resolveConfig from 'tailwindcss/resolveConfig';
|
||||||
|
import tailwindConfig from '../../tailwind.config';
|
||||||
|
|
||||||
|
//TODO Create provider for this
|
||||||
|
const fullConfig = resolveConfig(tailwindConfig);
|
||||||
|
|
||||||
|
const { primary, secondary, background, text, action, common } =
|
||||||
|
fullConfig.theme.colors;
|
||||||
|
|
||||||
export const theme = createTheme({
|
export const theme = createTheme({
|
||||||
palette: {
|
palette: {
|
||||||
primary: {
|
primary,
|
||||||
main: '#7F9172',
|
secondary,
|
||||||
},
|
background,
|
||||||
secondary: {
|
text,
|
||||||
main: '#5E714C',
|
action,
|
||||||
},
|
common,
|
||||||
background: {
|
|
||||||
default: '#495E35',
|
|
||||||
},
|
|
||||||
text: {
|
|
||||||
primary: '#F5F5F5',
|
|
||||||
secondary: '#b3b39b',
|
|
||||||
},
|
|
||||||
action: {
|
|
||||||
disabled: '#5E714C',
|
|
||||||
},
|
|
||||||
common: {
|
|
||||||
white: '#F9FFE3',
|
|
||||||
black: '#000000',
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
components: {
|
components: {
|
||||||
MuiFormLabel: {
|
MuiFormLabel: {
|
||||||
styleOverrides: {
|
styleOverrides: {
|
||||||
root: {
|
root: {
|
||||||
fontSize: '1rem',
|
fontSize: '1rem',
|
||||||
color: '#F5F5F5',
|
color: text.primary,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -36,12 +30,12 @@ export const theme = createTheme({
|
|||||||
styleOverrides: {
|
styleOverrides: {
|
||||||
markLabel: {
|
markLabel: {
|
||||||
fontSize: '1rem',
|
fontSize: '1rem',
|
||||||
color: '#F5F5F5',
|
color: text.primary,
|
||||||
},
|
},
|
||||||
valueLabel: {
|
valueLabel: {
|
||||||
display: 'none',
|
display: 'none',
|
||||||
color: '#F5F5F5',
|
color: text.primary,
|
||||||
background: '#5E714C',
|
background: secondary.main,
|
||||||
},
|
},
|
||||||
track: {
|
track: {
|
||||||
height: '0.7rem',
|
height: '0.7rem',
|
||||||
@@ -77,7 +71,7 @@ export const theme = createTheme({
|
|||||||
styleOverrides: {
|
styleOverrides: {
|
||||||
paper: {
|
paper: {
|
||||||
top: '1rem',
|
top: '1rem',
|
||||||
background: '#495E35',
|
background: background.default,
|
||||||
height: 'auto',
|
height: 'auto',
|
||||||
borderRadius: '8px',
|
borderRadius: '8px',
|
||||||
},
|
},
|
||||||
@@ -86,7 +80,7 @@ export const theme = createTheme({
|
|||||||
MuiBackdrop: {
|
MuiBackdrop: {
|
||||||
styleOverrides: {
|
styleOverrides: {
|
||||||
root: {
|
root: {
|
||||||
backgroundColor: 'rgba(0, 0, 0, 0.3)',
|
backgroundColor: background.backdrop,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -100,7 +94,7 @@ export const theme = createTheme({
|
|||||||
MuiSwitch: {
|
MuiSwitch: {
|
||||||
styleOverrides: {
|
styleOverrides: {
|
||||||
colorPrimary: {
|
colorPrimary: {
|
||||||
color: '#5E714C',
|
color: action.disabled,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -18,7 +18,17 @@ export const useAnalytics = () => {
|
|||||||
eventName: string,
|
eventName: string,
|
||||||
eventParams?: { [key: string]: unknown }
|
eventParams?: { [key: string]: unknown }
|
||||||
) => {
|
) => {
|
||||||
logEvent(analytics, eventName, eventParams);
|
if (process.env.NODE_ENV === 'development') {
|
||||||
|
console.info('Event not tracked:', { eventName, eventParams });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const paramsWithVersion = {
|
||||||
|
...eventParams,
|
||||||
|
app_version: import.meta.env.VITE_APP_VERSION,
|
||||||
|
};
|
||||||
|
|
||||||
|
logEvent(analytics, eventName, paramsWithVersion);
|
||||||
};
|
};
|
||||||
|
|
||||||
return { trackEvent };
|
return { trackEvent };
|
||||||
|
|||||||
52
src/Hooks/useOrientation.ts
Normal file
52
src/Hooks/useOrientation.ts
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
import { useEffect, useState } from 'react';
|
||||||
|
|
||||||
|
export interface OrientationState {
|
||||||
|
angle: number;
|
||||||
|
type: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
const defaultState: OrientationState = {
|
||||||
|
angle: 0,
|
||||||
|
type: 'landscape-primary',
|
||||||
|
};
|
||||||
|
|
||||||
|
export default function useOrientation(
|
||||||
|
initialState: OrientationState = defaultState
|
||||||
|
) {
|
||||||
|
const [state, setState] = useState(initialState);
|
||||||
|
const [isLandscape, setIsLandscape] = useState(false);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const screen = window.screen;
|
||||||
|
let mounted = true;
|
||||||
|
|
||||||
|
const onChange = () => {
|
||||||
|
if (mounted) {
|
||||||
|
const { orientation } = screen;
|
||||||
|
|
||||||
|
if (orientation) {
|
||||||
|
const { angle, type } = orientation;
|
||||||
|
setState({ angle, type });
|
||||||
|
if (type.includes('landscape')) {
|
||||||
|
setIsLandscape(true);
|
||||||
|
} else if (type.includes('portrait')) {
|
||||||
|
setIsLandscape(false);
|
||||||
|
}
|
||||||
|
} else if (window.orientation !== undefined) {
|
||||||
|
setState({
|
||||||
|
angle:
|
||||||
|
typeof window.orientation === 'number' ? window.orientation : 0,
|
||||||
|
type: '',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
onChange();
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
mounted = false;
|
||||||
|
};
|
||||||
|
}, [isLandscape]);
|
||||||
|
|
||||||
|
return { state, isLandscape };
|
||||||
|
}
|
||||||
@@ -5,7 +5,14 @@ import {
|
|||||||
GlobalSettingsContextType,
|
GlobalSettingsContextType,
|
||||||
} from '../Contexts/GlobalSettingsContext';
|
} from '../Contexts/GlobalSettingsContext';
|
||||||
import { useAnalytics } from '../Hooks/useAnalytics';
|
import { useAnalytics } from '../Hooks/useAnalytics';
|
||||||
import { InitialGameSettings, Orientation, Settings } from '../Types/Settings';
|
import {
|
||||||
|
InitialGameSettings,
|
||||||
|
Settings,
|
||||||
|
defaultInitialGameSettings,
|
||||||
|
defaultSettings,
|
||||||
|
initialGameSettingsSchema,
|
||||||
|
settingsSchema,
|
||||||
|
} from '../Types/Settings';
|
||||||
|
|
||||||
export const GlobalSettingsProvider = ({
|
export const GlobalSettingsProvider = ({
|
||||||
children,
|
children,
|
||||||
@@ -17,43 +24,108 @@ export const GlobalSettingsProvider = ({
|
|||||||
const savedShowPlay = localStorage.getItem('showPlay');
|
const savedShowPlay = localStorage.getItem('showPlay');
|
||||||
const savedGameSettings = localStorage.getItem('initialGameSettings');
|
const savedGameSettings = localStorage.getItem('initialGameSettings');
|
||||||
const savedSettings = localStorage.getItem('settings');
|
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>(
|
const [showPlay, setShowPlay] = useState<boolean>(
|
||||||
savedShowPlay ? savedShowPlay === 'true' : false
|
savedShowPlay ? savedShowPlay === 'true' : false
|
||||||
);
|
);
|
||||||
|
|
||||||
const [initialGameSettings, setInitialSettings] =
|
const [randomizingPlayer, setRandomizingPlayer] = useState<boolean>(
|
||||||
|
savedSettings
|
||||||
|
? Boolean(JSON.parse(savedSettings).preStartMode === 'random-king')
|
||||||
|
: true
|
||||||
|
);
|
||||||
|
|
||||||
|
const [initialGameSettings, setInitialGameSettings] =
|
||||||
useState<InitialGameSettings | null>(
|
useState<InitialGameSettings | null>(
|
||||||
savedGameSettings ? JSON.parse(savedGameSettings) : null
|
savedGameSettings ? JSON.parse(savedGameSettings) : null
|
||||||
);
|
);
|
||||||
|
|
||||||
const setInitialGameSettings = (initialGameSettings: InitialGameSettings) => {
|
const setInitialGameSettingsAndLocalStorage = (
|
||||||
const defaultSettings: InitialGameSettings = {
|
initialGameSettings: InitialGameSettings
|
||||||
numberOfPlayers: 4,
|
) => {
|
||||||
startingLifeTotal: 40,
|
setInitialGameSettings(initialGameSettings);
|
||||||
useCommanderDamage: true,
|
|
||||||
orientation: Orientation.Landscape,
|
|
||||||
gameFormat: 'commander',
|
|
||||||
};
|
|
||||||
setInitialSettings({ ...defaultSettings, ...initialGameSettings });
|
|
||||||
};
|
|
||||||
|
|
||||||
const [settings, setSettings] = useState<Settings>(
|
|
||||||
savedSettings
|
|
||||||
? JSON.parse(savedSettings)
|
|
||||||
: { goFullscreenOnStart: true, keepAwake: true, showStartingPlayer: true }
|
|
||||||
);
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
localStorage.setItem(
|
localStorage.setItem(
|
||||||
'initialGameSettings',
|
'initialGameSettings',
|
||||||
JSON.stringify(initialGameSettings)
|
JSON.stringify(initialGameSettings)
|
||||||
);
|
);
|
||||||
}, [initialGameSettings]);
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
const [settings, setSettings] = useState<Settings>(
|
||||||
|
savedSettings ? JSON.parse(savedSettings) : defaultSettings
|
||||||
|
);
|
||||||
|
|
||||||
|
const setSettingsAndLocalStorage = (settings: Settings) => {
|
||||||
|
setSettings(settings);
|
||||||
localStorage.setItem('settings', JSON.stringify(settings));
|
localStorage.setItem('settings', JSON.stringify(settings));
|
||||||
}, [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);
|
||||||
|
};
|
||||||
|
|
||||||
|
// Set settings if they are not valid
|
||||||
|
useEffect(() => {
|
||||||
|
// If there are no saved settings, set default settings
|
||||||
|
if (!savedSettings) {
|
||||||
|
setSettingsAndLocalStorage(defaultSettings);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const parsedSettings = settingsSchema.safeParse(JSON.parse(savedSettings));
|
||||||
|
|
||||||
|
// If saved settings are not valid, remove them
|
||||||
|
if (!parsedSettings.success) {
|
||||||
|
console.error('invalid settings, resetting to default settings');
|
||||||
|
setSettingsAndLocalStorage(defaultSettings);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
localStorage.setItem('settings', JSON.stringify(parsedSettings.data));
|
||||||
|
}, [settings, savedSettings]);
|
||||||
|
|
||||||
|
// Set initial game settings if they are not valid
|
||||||
|
useEffect(() => {
|
||||||
|
if (!savedGameSettings) {
|
||||||
|
setInitialGameSettingsAndLocalStorage(defaultInitialGameSettings);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
//parse existing game settings with zod schema
|
||||||
|
const parsedInitialGameSettings =
|
||||||
|
initialGameSettingsSchema.safeParse(initialGameSettings);
|
||||||
|
|
||||||
|
if (!parsedInitialGameSettings.success) {
|
||||||
|
console.error('invalid game settings, resetting to default settings');
|
||||||
|
setInitialGameSettingsAndLocalStorage(defaultInitialGameSettings);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
localStorage.setItem(
|
||||||
|
'initialGameSettings',
|
||||||
|
JSON.stringify(parsedInitialGameSettings.data)
|
||||||
|
);
|
||||||
|
}, [initialGameSettings, savedGameSettings]);
|
||||||
|
|
||||||
const [isFullscreen, setIsFullscreen] = useState(false);
|
const [isFullscreen, setIsFullscreen] = useState(false);
|
||||||
|
|
||||||
@@ -70,6 +142,11 @@ export const GlobalSettingsProvider = ({
|
|||||||
};
|
};
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
const [isLatestVersion, setIsLatestVersion] = useState(false);
|
||||||
|
const [remoteVersion, setRemoteVersion] = useState<string | undefined>(
|
||||||
|
undefined
|
||||||
|
);
|
||||||
|
|
||||||
const { isSupported, release, released, request, type } = useWakeLock();
|
const { isSupported, release, released, request, type } = useWakeLock();
|
||||||
|
|
||||||
const active = settings.keepAwake;
|
const active = settings.keepAwake;
|
||||||
@@ -78,14 +155,6 @@ export const GlobalSettingsProvider = ({
|
|||||||
request();
|
request();
|
||||||
}
|
}
|
||||||
|
|
||||||
const removeLocalStorage = async () => {
|
|
||||||
localStorage.removeItem('initialGameSettings');
|
|
||||||
localStorage.removeItem('players');
|
|
||||||
localStorage.removeItem('playing');
|
|
||||||
localStorage.removeItem('showPlay');
|
|
||||||
setShowPlay(localStorage.getItem('showPlay') === 'true' ?? false);
|
|
||||||
};
|
|
||||||
|
|
||||||
const ctxValue = useMemo((): GlobalSettingsContextType => {
|
const ctxValue = useMemo((): GlobalSettingsContextType => {
|
||||||
const goToStart = async () => {
|
const goToStart = async () => {
|
||||||
const currentPlayers = localStorage.getItem('players');
|
const currentPlayers = localStorage.getItem('players');
|
||||||
@@ -100,7 +169,6 @@ export const GlobalSettingsProvider = ({
|
|||||||
};
|
};
|
||||||
|
|
||||||
const toggleWakeLock = async () => {
|
const toggleWakeLock = async () => {
|
||||||
console.log('on press', active);
|
|
||||||
if (active) {
|
if (active) {
|
||||||
setSettings({ ...settings, keepAwake: false });
|
setSettings({ ...settings, keepAwake: false });
|
||||||
release();
|
release();
|
||||||
@@ -127,6 +195,51 @@ export const GlobalSettingsProvider = ({
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const setPreStartCompletedAndLocalStorage = (preStartComplete: boolean) => {
|
||||||
|
setPreStartCompleted(preStartComplete);
|
||||||
|
localStorage.setItem('playing', String(playing));
|
||||||
|
};
|
||||||
|
|
||||||
|
async function checkForNewVersion(source: 'settings' | 'start_menu') {
|
||||||
|
try {
|
||||||
|
const result = await fetch(
|
||||||
|
'https://api.github.com/repos/Vikeo/LifeTrinket/releases/latest',
|
||||||
|
{
|
||||||
|
headers: {
|
||||||
|
Authorization: `Bearer ${
|
||||||
|
import.meta.env.VITE_REPO_READ_ACCESS_TOKEN
|
||||||
|
}`,
|
||||||
|
Accept: 'application/vnd.github+json',
|
||||||
|
'X-GitHub-Api-Version': '2022-11-28',
|
||||||
|
},
|
||||||
|
}
|
||||||
|
);
|
||||||
|
const data = await result.json();
|
||||||
|
|
||||||
|
if (!data.name) {
|
||||||
|
setRemoteVersion(undefined);
|
||||||
|
setIsLatestVersion(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
setRemoteVersion(data.name);
|
||||||
|
|
||||||
|
if (data.name === import.meta.env.VITE_APP_VERSION) {
|
||||||
|
setIsLatestVersion(true);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
analytics.trackEvent(`${source}_has_new_version`, {
|
||||||
|
remoteVersion: data.name,
|
||||||
|
installedVersion: import.meta.env.VITE_APP_VERSION,
|
||||||
|
});
|
||||||
|
|
||||||
|
setIsLatestVersion(false);
|
||||||
|
} catch (error) {
|
||||||
|
console.error('error getting latest version string', error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
fullscreen: { isFullscreen, enableFullscreen, disableFullscreen },
|
fullscreen: { isFullscreen, enableFullscreen, disableFullscreen },
|
||||||
wakeLock: {
|
wakeLock: {
|
||||||
@@ -140,23 +253,41 @@ export const GlobalSettingsProvider = ({
|
|||||||
goToStart,
|
goToStart,
|
||||||
showPlay,
|
showPlay,
|
||||||
setShowPlay,
|
setShowPlay,
|
||||||
|
playing,
|
||||||
|
setPlaying: setPlayingAndLocalStorage,
|
||||||
initialGameSettings,
|
initialGameSettings,
|
||||||
setInitialGameSettings,
|
setInitialGameSettings,
|
||||||
settings,
|
settings,
|
||||||
setSettings,
|
setSettings: setSettingsAndLocalStorage,
|
||||||
|
randomizingPlayer,
|
||||||
|
setRandomizingPlayer,
|
||||||
isPWA: window?.matchMedia('(display-mode: standalone)').matches,
|
isPWA: window?.matchMedia('(display-mode: standalone)').matches,
|
||||||
|
preStartCompleted,
|
||||||
|
setPreStartCompleted: setPreStartCompletedAndLocalStorage,
|
||||||
|
|
||||||
|
version: {
|
||||||
|
installedVersion: import.meta.env.VITE_APP_VERSION,
|
||||||
|
remoteVersion,
|
||||||
|
isLatest: isLatestVersion,
|
||||||
|
checkForNewVersion,
|
||||||
|
},
|
||||||
};
|
};
|
||||||
}, [
|
}, [
|
||||||
active,
|
|
||||||
analytics,
|
|
||||||
initialGameSettings,
|
|
||||||
isFullscreen,
|
isFullscreen,
|
||||||
isSupported,
|
isSupported,
|
||||||
release,
|
release,
|
||||||
|
active,
|
||||||
request,
|
request,
|
||||||
settings,
|
|
||||||
showPlay,
|
|
||||||
type,
|
type,
|
||||||
|
showPlay,
|
||||||
|
playing,
|
||||||
|
initialGameSettings,
|
||||||
|
settings,
|
||||||
|
randomizingPlayer,
|
||||||
|
preStartCompleted,
|
||||||
|
remoteVersion,
|
||||||
|
isLatestVersion,
|
||||||
|
analytics,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
@@ -7,6 +7,17 @@ import { InitialGameSettings } from '../Types/Settings';
|
|||||||
export const PlayersProvider = ({ children }: { children: ReactNode }) => {
|
export const PlayersProvider = ({ children }: { children: ReactNode }) => {
|
||||||
const savedPlayers = localStorage.getItem('players');
|
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[]>(
|
const [players, setPlayers] = useState<Player[]>(
|
||||||
savedPlayers ? JSON.parse(savedPlayers) : []
|
savedPlayers ? JSON.parse(savedPlayers) : []
|
||||||
);
|
);
|
||||||
@@ -50,9 +61,7 @@ export const PlayersProvider = ({ children }: { children: ReactNode }) => {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const startingPlayerIndex = Math.floor(
|
const newStartingPlayerIndex = Math.floor(Math.random() * players.length);
|
||||||
Math.random() * initialGameSettings.numberOfPlayers
|
|
||||||
);
|
|
||||||
|
|
||||||
players.forEach((player: Player) => {
|
players.forEach((player: Player) => {
|
||||||
player.commanderDamage.map((damage) => {
|
player.commanderDamage.map((damage) => {
|
||||||
@@ -65,16 +74,9 @@ export const PlayersProvider = ({ children }: { children: ReactNode }) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
player.lifeTotal = initialGameSettings.startingLifeTotal;
|
player.lifeTotal = initialGameSettings.startingLifeTotal;
|
||||||
|
|
||||||
player.hasLost = false;
|
player.hasLost = false;
|
||||||
|
|
||||||
const isStartingPlayer = player.index === startingPlayerIndex;
|
player.isStartingPlayer = newStartingPlayerIndex === player.index;
|
||||||
|
|
||||||
player.isStartingPlayer = isStartingPlayer;
|
|
||||||
|
|
||||||
if (player.isStartingPlayer) {
|
|
||||||
player.showStartingPlayer = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
updatePlayer(player);
|
updatePlayer(player);
|
||||||
});
|
});
|
||||||
@@ -87,8 +89,10 @@ export const PlayersProvider = ({ children }: { children: ReactNode }) => {
|
|||||||
updatePlayer,
|
updatePlayer,
|
||||||
updateLifeTotal,
|
updateLifeTotal,
|
||||||
resetCurrentGame,
|
resetCurrentGame,
|
||||||
|
startingPlayerIndex,
|
||||||
|
setStartingPlayerIndex: setStartingPlayerIndexAndLocalStorage,
|
||||||
};
|
};
|
||||||
}, [players]);
|
}, [players, startingPlayerIndex]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<PlayersContext.Provider value={ctxValue}>
|
<PlayersContext.Provider value={ctxValue}>
|
||||||
|
|||||||
@@ -6,8 +6,8 @@ export type Player = {
|
|||||||
commanderDamage: CommanderDamage[];
|
commanderDamage: CommanderDamage[];
|
||||||
extraCounters: ExtraCounter[];
|
extraCounters: ExtraCounter[];
|
||||||
isStartingPlayer: boolean;
|
isStartingPlayer: boolean;
|
||||||
showStartingPlayer: boolean;
|
|
||||||
hasLost: boolean;
|
hasLost: boolean;
|
||||||
|
isSide: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type PlayerSettings = {
|
export type PlayerSettings = {
|
||||||
|
|||||||
@@ -1,13 +1,30 @@
|
|||||||
|
import { z } from 'zod';
|
||||||
|
|
||||||
export enum Orientation {
|
export enum Orientation {
|
||||||
OppositeLandscape = 'opposite-landscape',
|
OppositeLandscape = 'opposite-landscape',
|
||||||
Landscape = 'landscape',
|
Landscape = 'landscape',
|
||||||
Portrait = 'portrait',
|
Portrait = 'portrait',
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export enum GameFormat {
|
||||||
|
Commander = 'commander',
|
||||||
|
Standard = 'standard',
|
||||||
|
TwoHeadedGiant = 'two-headed-giant',
|
||||||
|
}
|
||||||
|
|
||||||
|
export enum PreStartMode {
|
||||||
|
None = 'none',
|
||||||
|
RandomKing = 'random-king',
|
||||||
|
FingerGame = 'finger-game',
|
||||||
|
Trivia = 'trivia',
|
||||||
|
}
|
||||||
|
|
||||||
export type Settings = {
|
export type Settings = {
|
||||||
keepAwake: boolean;
|
keepAwake: boolean;
|
||||||
showStartingPlayer: boolean;
|
showStartingPlayer: boolean;
|
||||||
|
showPlayerMenuCog: boolean;
|
||||||
goFullscreenOnStart: boolean;
|
goFullscreenOnStart: boolean;
|
||||||
|
preStartMode: PreStartMode;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type InitialGameSettings = {
|
export type InitialGameSettings = {
|
||||||
@@ -18,4 +35,34 @@ export type InitialGameSettings = {
|
|||||||
orientation: Orientation;
|
orientation: Orientation;
|
||||||
};
|
};
|
||||||
|
|
||||||
type GameFormat = 'commander' | 'standard' | 'two-headed-giant';
|
export const initialGameSettingsSchema = z.object({
|
||||||
|
startingLifeTotal: z.number().min(1).max(200),
|
||||||
|
useCommanderDamage: z.boolean(),
|
||||||
|
gameFormat: z.nativeEnum(GameFormat),
|
||||||
|
numberOfPlayers: z.number().min(1).max(6),
|
||||||
|
orientation: z.nativeEnum(Orientation),
|
||||||
|
});
|
||||||
|
|
||||||
|
export const defaultInitialGameSettings = {
|
||||||
|
numberOfPlayers: 4,
|
||||||
|
startingLifeTotal: 40,
|
||||||
|
useCommanderDamage: true,
|
||||||
|
orientation: Orientation.Landscape,
|
||||||
|
gameFormat: GameFormat.Commander,
|
||||||
|
};
|
||||||
|
|
||||||
|
export const settingsSchema = z.object({
|
||||||
|
keepAwake: z.boolean(),
|
||||||
|
showStartingPlayer: z.boolean(),
|
||||||
|
showPlayerMenuCog: z.boolean(),
|
||||||
|
goFullscreenOnStart: z.boolean(),
|
||||||
|
preStartMode: z.nativeEnum(PreStartMode),
|
||||||
|
});
|
||||||
|
|
||||||
|
export const defaultSettings: Settings = {
|
||||||
|
goFullscreenOnStart: true,
|
||||||
|
keepAwake: true,
|
||||||
|
showStartingPlayer: true,
|
||||||
|
showPlayerMenuCog: true,
|
||||||
|
preStartMode: PreStartMode.None,
|
||||||
|
};
|
||||||
|
|||||||
87
src/Utils/checkContrast.ts
Normal file
87
src/Utils/checkContrast.ts
Normal file
@@ -0,0 +1,87 @@
|
|||||||
|
type RGBA = {
|
||||||
|
red: number;
|
||||||
|
green: number;
|
||||||
|
blue: number;
|
||||||
|
alpha: number;
|
||||||
|
};
|
||||||
|
|
||||||
|
export const hexToRgb = (hex: string): RGBA => {
|
||||||
|
hex = hex.replace(/^#/, '');
|
||||||
|
let alpha = 255;
|
||||||
|
|
||||||
|
if (hex.length === 8) {
|
||||||
|
alpha = parseInt(hex.slice(6, 8), 16);
|
||||||
|
hex = hex.substring(0, 6);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (hex.length === 4) {
|
||||||
|
alpha = parseInt(hex.slice(3, 4).repeat(2), 16);
|
||||||
|
hex = hex.substring(0, 3);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (hex.length === 3) {
|
||||||
|
hex = hex[0] + hex[0] + hex[1] + hex[1] + hex[2] + hex[2];
|
||||||
|
}
|
||||||
|
|
||||||
|
const num = parseInt(hex, 16);
|
||||||
|
const red = num >> 16;
|
||||||
|
const green = (num >> 8) & 255;
|
||||||
|
const blue = num & 255;
|
||||||
|
|
||||||
|
return { red, green, blue, alpha };
|
||||||
|
};
|
||||||
|
|
||||||
|
export const luminance = (a: number, b: number) => {
|
||||||
|
const l1 = Math.max(a, b);
|
||||||
|
const l2 = Math.min(a, b);
|
||||||
|
return (l1 + 0.05) / (l2 + 0.05);
|
||||||
|
};
|
||||||
|
|
||||||
|
export const rgbContrast = (a: RGBA, b: RGBA) => {
|
||||||
|
return luminance(relativeLuminance(a), relativeLuminance(b));
|
||||||
|
};
|
||||||
|
|
||||||
|
// calculate the color contrast ratio
|
||||||
|
export const checkContrast = (hexC1: string, hexC2: string) => {
|
||||||
|
const color1rgb = hexToRgb(hexC1);
|
||||||
|
const color2rgb = hexToRgb(hexC2);
|
||||||
|
|
||||||
|
const contrast = rgbContrast(color1rgb, color2rgb);
|
||||||
|
|
||||||
|
if (contrast >= 7) {
|
||||||
|
return 'AAA';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (contrast >= 4.5) {
|
||||||
|
return 'AA';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (contrast >= 3) {
|
||||||
|
return 'AA Large';
|
||||||
|
}
|
||||||
|
|
||||||
|
return 'Fail';
|
||||||
|
};
|
||||||
|
|
||||||
|
// red, green, and blue coefficients
|
||||||
|
const rc = 0.2126;
|
||||||
|
const gc = 0.7152;
|
||||||
|
const bc = 0.0722;
|
||||||
|
// low-gamma adjust coefficient
|
||||||
|
const lowc = 1 / 12.92;
|
||||||
|
|
||||||
|
function adjustGamma(input: number) {
|
||||||
|
return Math.pow((input + 0.055) / 1.055, 2.4);
|
||||||
|
}
|
||||||
|
|
||||||
|
export const relativeLuminance = (rgb: RGBA) => {
|
||||||
|
const rsrgb = rgb.red / 255;
|
||||||
|
const gsrgb = rgb.green / 255;
|
||||||
|
const bsrgb = rgb.blue / 255;
|
||||||
|
|
||||||
|
const r = rsrgb <= 0.03928 ? rsrgb * lowc : adjustGamma(rsrgb);
|
||||||
|
const g = gsrgb <= 0.03928 ? gsrgb * lowc : adjustGamma(gsrgb);
|
||||||
|
const b = bsrgb <= 0.03928 ? bsrgb * lowc : adjustGamma(bsrgb);
|
||||||
|
|
||||||
|
return r * rc + g * gc + b * bc;
|
||||||
|
};
|
||||||
@@ -2,7 +2,19 @@
|
|||||||
@tailwind components;
|
@tailwind components;
|
||||||
@tailwind utilities;
|
@tailwind utilities;
|
||||||
|
|
||||||
|
html {
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
|
||||||
body {
|
body {
|
||||||
|
overflow: auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
html,
|
||||||
|
body {
|
||||||
|
height: 100%;
|
||||||
|
position: relative;
|
||||||
|
background-color: theme('colors.background.default');
|
||||||
margin: 0;
|
margin: 0;
|
||||||
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',
|
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',
|
||||||
'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue',
|
'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue',
|
||||||
@@ -10,8 +22,25 @@ body {
|
|||||||
-webkit-font-smoothing: antialiased;
|
-webkit-font-smoothing: antialiased;
|
||||||
-moz-osx-font-smoothing: grayscale;
|
-moz-osx-font-smoothing: grayscale;
|
||||||
}
|
}
|
||||||
|
#root {
|
||||||
|
touch-action: manipulation;
|
||||||
|
}
|
||||||
|
|
||||||
code {
|
code {
|
||||||
font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New',
|
font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New',
|
||||||
monospace;
|
monospace;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@layer utilities {
|
||||||
|
.pointer-events-all {
|
||||||
|
pointer-events: all;
|
||||||
|
}
|
||||||
|
|
||||||
|
.webkit-user-select-none {
|
||||||
|
-webkit-touch-callout: none;
|
||||||
|
-webkit-tap-highlight-color: transparent;
|
||||||
|
-moz-user-select: -moz-none;
|
||||||
|
-webkit-user-select: none;
|
||||||
|
-ms-user-select: none;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
9
src/vite-env.d.ts
vendored
9
src/vite-env.d.ts
vendored
@@ -1 +1,10 @@
|
|||||||
/// <reference types="vite/client" />
|
/// <reference types="vite/client" />
|
||||||
|
|
||||||
|
interface ImportMetaEnv {
|
||||||
|
readonly VITE_APP_VERSION: string;
|
||||||
|
readonly VITE_REPO_READ_ACCESS_TOKEN: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface ImportMeta {
|
||||||
|
readonly env: ImportMetaEnv;
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,41 +0,0 @@
|
|||||||
import tailwindcssGridAreas from '@savvywombat/tailwindcss-grid-areas';
|
|
||||||
|
|
||||||
/** @type {import('tailwindcss').Config} */
|
|
||||||
export default {
|
|
||||||
content: ['./index.html', './src/**/*.{js,ts,jsx,tsx}'],
|
|
||||||
theme: {
|
|
||||||
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',
|
|
||||||
],
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
plugins: [tailwindcssGridAreas],
|
|
||||||
};
|
|
||||||
113
tailwind.config.ts
Normal file
113
tailwind.config.ts
Normal file
@@ -0,0 +1,113 @@
|
|||||||
|
//@ts-expect-error - tailwindcss-grid-areas does not have typescript support
|
||||||
|
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}'],
|
||||||
|
theme: {
|
||||||
|
screens: {
|
||||||
|
modalSm: '548px',
|
||||||
|
},
|
||||||
|
extend: {
|
||||||
|
gridTemplateAreas: twGridTemplateAreas,
|
||||||
|
colors: baseColors,
|
||||||
|
keyframes: {
|
||||||
|
fadeOut: {
|
||||||
|
'0%': {
|
||||||
|
opacity: '1',
|
||||||
|
},
|
||||||
|
'33%': {
|
||||||
|
opacity: '0.6',
|
||||||
|
},
|
||||||
|
'100%': {
|
||||||
|
opacity: '0',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
animation: {
|
||||||
|
fadeOut: 'fadeOut 3s 1s ease-out forwards',
|
||||||
|
},
|
||||||
|
fontSize: {
|
||||||
|
xxs: ['0.625rem', '1rem'],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
plugins: [tailwindcssGridAreas],
|
||||||
|
} satisfies Config;
|
||||||
|
// #98FF98
|
||||||
@@ -1,13 +1,31 @@
|
|||||||
import { defineConfig } from 'vite';
|
|
||||||
import react from '@vitejs/plugin-react-swc';
|
import react from '@vitejs/plugin-react-swc';
|
||||||
|
import { defineConfig } from 'vite';
|
||||||
|
import { VitePWA } from 'vite-plugin-pwa';
|
||||||
|
|
||||||
// https://vitejs.dev/config/
|
// https://vitejs.dev/config/
|
||||||
export default defineConfig({
|
export default defineConfig({
|
||||||
plugins: [react()],
|
plugins: [
|
||||||
|
react(),
|
||||||
|
VitePWA({
|
||||||
|
registerType: 'autoUpdate',
|
||||||
|
workbox: {
|
||||||
|
clientsClaim: true,
|
||||||
|
skipWaiting: true,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
],
|
||||||
build: {
|
build: {
|
||||||
minify: 'esbuild',
|
minify: 'esbuild',
|
||||||
rollupOptions: {
|
rollupOptions: {
|
||||||
external: ['babel-plugin-macros'],
|
external: ['babel-plugin-macros'],
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
define: {
|
||||||
|
'import.meta.env.VITE_APP_VERSION': JSON.stringify(
|
||||||
|
process.env.npm_package_version
|
||||||
|
),
|
||||||
|
VITE_REPO_READ_ACCESS_TOKEN: JSON.stringify(
|
||||||
|
process.env.VITE_REPO_READ_ACCESS_TOKEN
|
||||||
|
),
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user