forked from external-repos/LifeTrinket
Compare commits
13 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0f86928cb3 | ||
|
|
efbfb7719c | ||
|
|
71e5614f52 | ||
|
|
677fd79bee | ||
|
|
1bff41bc10 | ||
|
|
7852520f8e | ||
|
|
04c3d60967 | ||
|
|
664e2e5688 | ||
|
|
6eb7ac9f50 | ||
|
|
ef06e0d125 | ||
|
|
ae9f5707b2 | ||
|
|
8b33a2a38a | ||
|
|
cc915dff36 |
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "life-trinket",
|
"name": "life-trinket",
|
||||||
"private": true,
|
"private": true,
|
||||||
"version": "0.6.3",
|
"version": "0.6.5",
|
||||||
"type": "commonjs",
|
"type": "commonjs",
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=18",
|
"node": ">=18",
|
||||||
|
|||||||
@@ -66,8 +66,7 @@ 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 downPositionRef = useRef({ x: 0, y: 0 });
|
||||||
|
|
||||||
const handleCommanderDamageChange = (
|
const handleCommanderDamageChange = (
|
||||||
@@ -109,16 +108,16 @@ export const CommanderDamage = ({
|
|||||||
|
|
||||||
const handleDownInput = ({ opponentIndex, isPartner, event }: InputProps) => {
|
const handleDownInput = ({ opponentIndex, isPartner, event }: InputProps) => {
|
||||||
downPositionRef.current = { x: event.clientX, y: event.clientY };
|
downPositionRef.current = { x: event.clientX, y: event.clientY };
|
||||||
setTimeoutFinished(false);
|
setDownLongPressed(false);
|
||||||
setHasPressedDown(true);
|
|
||||||
timeoutRef.current = setTimeout(() => {
|
timeoutRef.current = setTimeout(() => {
|
||||||
setTimeoutFinished(true);
|
setDownLongPressed(true);
|
||||||
handleCommanderDamageChange(opponentIndex, -1, isPartner);
|
handleCommanderDamageChange(opponentIndex, -1, isPartner);
|
||||||
}, decrementTimeoutMs);
|
}, decrementTimeoutMs);
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleUpInput = ({ opponentIndex, isPartner, event }: InputProps) => {
|
const handleUpInput = ({ opponentIndex, isPartner, event }: InputProps) => {
|
||||||
if (!(hasPressedDown && !timeoutFinished)) {
|
if (downLongPressed) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -134,14 +133,14 @@ export const CommanderDamage = ({
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
|||||||
@@ -1,8 +1,9 @@
|
|||||||
import { useRef, useState } from 'react';
|
import { useEffect, useRef, useState } from 'react';
|
||||||
import { TwcComponentProps, twc } from 'react-twc';
|
import { TwcComponentProps, twc } from 'react-twc';
|
||||||
import { lifeLongPressMultiplier } from '../../Data/constants';
|
import { lifeLongPressMultiplier } from '../../Data/constants';
|
||||||
import { Rotation } from '../../Types/Player';
|
import { Player, Rotation } from '../../Types/Player';
|
||||||
import { MAX_TAP_MOVE_DISTANCE } from './CommanderDamage';
|
import { MAX_TAP_MOVE_DISTANCE } from './CommanderDamage';
|
||||||
|
import { checkContrast } from '../../Utils/checkContrast';
|
||||||
|
|
||||||
type RotationButtonProps = TwcComponentProps<'div'> & {
|
type RotationButtonProps = TwcComponentProps<'div'> & {
|
||||||
$align?: string;
|
$align?: string;
|
||||||
@@ -13,7 +14,6 @@ const LifeCounterButtonTwc = twc.button`
|
|||||||
h-full
|
h-full
|
||||||
w-full
|
w-full
|
||||||
flex
|
flex
|
||||||
text-lifeCounter-text
|
|
||||||
font-semibold
|
font-semibold
|
||||||
bg-transparent
|
bg-transparent
|
||||||
border-none
|
border-none
|
||||||
@@ -40,17 +40,15 @@ const TextContainer = twc.div<RotationButtonProps>((props) => [
|
|||||||
]);
|
]);
|
||||||
|
|
||||||
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) => {
|
||||||
@@ -59,8 +57,20 @@ const LifeCounterButton = ({
|
|||||||
const [hasPressedDown, setHasPressedDown] = useState(false);
|
const [hasPressedDown, setHasPressedDown] = useState(false);
|
||||||
const downPositionRef = useRef({ x: 0, y: 0 });
|
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 = (event: React.PointerEvent<HTMLButtonElement>) => {
|
const handleDownInput = (event: React.PointerEvent<HTMLButtonElement>) => {
|
||||||
@@ -102,7 +112,8 @@ 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';
|
||||||
|
|
||||||
@@ -118,8 +129,11 @@ 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>
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ const LoseButton = twc.div<RotationDivProps>((props) => [
|
|||||||
'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 ',
|
'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 ',
|
||||||
|
|
||||||
props.$rotation === Rotation.SideFlipped || props.$rotation === Rotation.Side
|
props.$rotation === Rotation.SideFlipped || props.$rotation === Rotation.Side
|
||||||
? `left-[19%]`
|
? `left-[21%]`
|
||||||
: 'top-[21%]',
|
: 'top-[21%]',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
|||||||
@@ -10,6 +10,8 @@ import {
|
|||||||
import { CounterType, Player, Rotation } from '../../Types/Player';
|
import { CounterType, Player, Rotation } from '../../Types/Player';
|
||||||
import { RotationDivProps } from '../Buttons/CommanderDamage';
|
import { RotationDivProps } from '../Buttons/CommanderDamage';
|
||||||
import ExtraCounter from '../Buttons/ExtraCounter';
|
import ExtraCounter from '../Buttons/ExtraCounter';
|
||||||
|
import { useEffect, useState } from 'react';
|
||||||
|
import { checkContrast } from '../../Utils/checkContrast';
|
||||||
|
|
||||||
const Container = twc.div<RotationDivProps>((props) => [
|
const Container = twc.div<RotationDivProps>((props) => [
|
||||||
'flex',
|
'flex',
|
||||||
@@ -31,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,
|
||||||
@@ -93,7 +106,13 @@ 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(
|
||||||
@@ -108,7 +127,13 @@ 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(
|
||||||
@@ -123,7 +148,13 @@ 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')
|
||||||
@@ -137,7 +168,13 @@ 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')
|
||||||
@@ -151,7 +188,13 @@ 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(
|
||||||
|
|||||||
@@ -118,9 +118,8 @@ const Health = ({
|
|||||||
return (
|
return (
|
||||||
<LifeContainer $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}
|
||||||
/>
|
/>
|
||||||
@@ -148,9 +147,8 @@ 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}
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ const PlayerMenuWrapper = twc.div`
|
|||||||
w-full
|
w-full
|
||||||
h-full
|
h-full
|
||||||
bg-background-settings
|
bg-background-settings
|
||||||
backdrop-blur-[10px]
|
backdrop-blur-[3px]
|
||||||
items-center
|
items-center
|
||||||
justify-center
|
justify-center
|
||||||
z-[2]
|
z-[2]
|
||||||
@@ -66,17 +66,15 @@ const ButtonsSections = twc.div`
|
|||||||
flex-wrap
|
flex-wrap
|
||||||
`;
|
`;
|
||||||
|
|
||||||
const ColorPicker = twc.input`
|
const ColorPickerButton = twc.div`
|
||||||
h-[8vmax]
|
h-[8vmax]
|
||||||
w-[8vmax]
|
w-[8vmax]
|
||||||
|
relative
|
||||||
max-h-12
|
max-h-12
|
||||||
max-w-11
|
max-w-12
|
||||||
border-none
|
rounded-full
|
||||||
outline-none
|
|
||||||
cursor-pointer
|
cursor-pointer
|
||||||
bg-transparent
|
overflow-hidden
|
||||||
user-select-none
|
|
||||||
text-common-white
|
|
||||||
`;
|
`;
|
||||||
|
|
||||||
const SettingsContainer = twc.div<RotationDivProps>((props) => [
|
const SettingsContainer = twc.div<RotationDivProps>((props) => [
|
||||||
@@ -98,7 +96,7 @@ const PlayerMenu = ({
|
|||||||
isShown,
|
isShown,
|
||||||
}: PlayerMenuProps) => {
|
}: PlayerMenuProps) => {
|
||||||
const settingsContainerRef = useRef<HTMLDivElement | null>(null);
|
const settingsContainerRef = useRef<HTMLDivElement | null>(null);
|
||||||
const dialogRef = useRef<HTMLDialogElement | null>(null);
|
const resetGameDialogRef = useRef<HTMLDialogElement | null>(null);
|
||||||
|
|
||||||
const { isSide } = useSafeRotate({
|
const { isSide } = useSafeRotate({
|
||||||
rotation: player.settings.rotation,
|
rotation: player.settings.rotation,
|
||||||
@@ -162,13 +160,14 @@ const PlayerMenu = ({
|
|||||||
>
|
>
|
||||||
<BetterRowContainer>
|
<BetterRowContainer>
|
||||||
<TogglesSection>
|
<TogglesSection>
|
||||||
<ColorPicker
|
<ColorPickerButton aria-label="Color picker">
|
||||||
type="color"
|
<input
|
||||||
value={player.color}
|
onChange={handleColorChange}
|
||||||
onChange={handleColorChange}
|
type="color"
|
||||||
role="button"
|
className="size-[200%] absolute -left-2 -top-2"
|
||||||
aria-label="Color picker"
|
value={player.color}
|
||||||
/>
|
/>
|
||||||
|
</ColorPickerButton>
|
||||||
{player.settings.useCommanderDamage && (
|
{player.settings.useCommanderDamage && (
|
||||||
<CheckboxContainer>
|
<CheckboxContainer>
|
||||||
<Checkbox
|
<Checkbox
|
||||||
@@ -197,7 +196,6 @@ const PlayerMenu = ({
|
|||||||
/>
|
/>
|
||||||
</CheckboxContainer>
|
</CheckboxContainer>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
<CheckboxContainer>
|
<CheckboxContainer>
|
||||||
<Checkbox
|
<Checkbox
|
||||||
name="usePoison"
|
name="usePoison"
|
||||||
@@ -224,7 +222,6 @@ const PlayerMenu = ({
|
|||||||
aria-label="Poison"
|
aria-label="Poison"
|
||||||
/>
|
/>
|
||||||
</CheckboxContainer>
|
</CheckboxContainer>
|
||||||
|
|
||||||
<CheckboxContainer>
|
<CheckboxContainer>
|
||||||
<Checkbox
|
<Checkbox
|
||||||
name="useEnergy"
|
name="useEnergy"
|
||||||
@@ -251,7 +248,6 @@ const PlayerMenu = ({
|
|||||||
aria-label="Energy"
|
aria-label="Energy"
|
||||||
/>
|
/>
|
||||||
</CheckboxContainer>
|
</CheckboxContainer>
|
||||||
|
|
||||||
<CheckboxContainer>
|
<CheckboxContainer>
|
||||||
<Checkbox
|
<Checkbox
|
||||||
name="useExperience"
|
name="useExperience"
|
||||||
@@ -332,7 +328,7 @@ const PlayerMenu = ({
|
|||||||
fontSize: buttonFontSize,
|
fontSize: buttonFontSize,
|
||||||
padding: '4px',
|
padding: '4px',
|
||||||
}}
|
}}
|
||||||
onClick={() => dialogRef.current?.show()}
|
onClick={() => resetGameDialogRef.current?.show()}
|
||||||
role="checkbox"
|
role="checkbox"
|
||||||
aria-checked={wakeLock.active}
|
aria-checked={wakeLock.active}
|
||||||
aria-label="Reset Game"
|
aria-label="Reset Game"
|
||||||
@@ -342,27 +338,30 @@ const PlayerMenu = ({
|
|||||||
</ButtonsSections>
|
</ButtonsSections>
|
||||||
</BetterRowContainer>
|
</BetterRowContainer>
|
||||||
<dialog
|
<dialog
|
||||||
ref={dialogRef}
|
ref={resetGameDialogRef}
|
||||||
className="z-[9999] min-h-2/4 bg-background-default text-text-primary rounded-2xl border-none absolute bottom-[20%]"
|
className="z-[999] size-full bg-background-settings"
|
||||||
|
onClick={() => resetGameDialogRef.current?.close()}
|
||||||
>
|
>
|
||||||
<div className="flex flex-col p-4 gap-2">
|
<div className="flex size-full items-center justify-center">
|
||||||
<h1 className="text-center">Reset Game?</h1>
|
<div className="flex flex-col justify-center p-4 gap-2 bg-background-default rounded-2xl border-none">
|
||||||
<div className="flex justify-evenly gap-4">
|
<h1 className="text-center text-text-primary">Reset Game?</h1>
|
||||||
<Button
|
<div className="flex justify-evenly gap-4">
|
||||||
variant="contained"
|
<Button
|
||||||
onClick={() => dialogRef.current?.close()}
|
variant="contained"
|
||||||
>
|
onClick={() => resetGameDialogRef.current?.close()}
|
||||||
No
|
>
|
||||||
</Button>
|
No
|
||||||
<Button
|
</Button>
|
||||||
variant="contained"
|
<Button
|
||||||
onClick={() => {
|
variant="contained"
|
||||||
handleResetGame();
|
onClick={() => {
|
||||||
dialogRef.current?.close();
|
handleResetGame();
|
||||||
}}
|
resetGameDialogRef.current?.close();
|
||||||
>
|
}}
|
||||||
Yes
|
>
|
||||||
</Button>
|
Yes
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</dialog>
|
</dialog>
|
||||||
|
|||||||
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;
|
||||||
|
};
|
||||||
@@ -54,6 +54,10 @@ export default {
|
|||||||
backdrop: 'rgba(0, 0, 0, 0.3)',
|
backdrop: 'rgba(0, 0, 0, 0.3)',
|
||||||
settings: 'rgba(20, 20, 0, 0.9)',
|
settings: 'rgba(20, 20, 0, 0.9)',
|
||||||
},
|
},
|
||||||
|
icons: {
|
||||||
|
dark: '#00000080',
|
||||||
|
light: '#ffffff4f',
|
||||||
|
},
|
||||||
text: {
|
text: {
|
||||||
primary: '#F5F5F5',
|
primary: '#F5F5F5',
|
||||||
secondary: '#76A6A5',
|
secondary: '#76A6A5',
|
||||||
|
|||||||
Reference in New Issue
Block a user