-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add initial implementation for the initiative tracker
- Loading branch information
Jan Stevens
committed
Apr 27, 2024
1 parent
38adb46
commit 2aef13d
Showing
24 changed files
with
1,170 additions
and
1,017 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import { | ||
PinInput as ArkPinInput, | ||
type PinInputRootProps, | ||
} from '@ark-ui/react/pin-input'; | ||
import { css, cx } from '@style/css'; | ||
import { splitCssProps } from '@style/jsx'; | ||
import { pinInput, type PinInputVariantProps } from '@style/recipes'; | ||
import type { Assign, JsxStyleProps } from '@style/types'; | ||
import { forwardRef, type ReactNode } from 'react'; | ||
|
||
import { Input } from './Input'; | ||
|
||
export interface PinInputProps | ||
extends Assign<JsxStyleProps, PinInputRootProps>, | ||
PinInputVariantProps { | ||
children?: ReactNode; | ||
/** | ||
* The number of inputs to render. | ||
* @default 4 | ||
*/ | ||
length?: number; | ||
} | ||
|
||
export const PinInput = forwardRef<HTMLDivElement, PinInputProps>( | ||
(props, ref) => { | ||
const [variantProps, pinInputProps] = pinInput.splitVariantProps(props); | ||
const [cssProps, localProps] = splitCssProps(pinInputProps); | ||
const { children, className, length = 4, ...rootProps } = localProps; | ||
const styles = pinInput(variantProps); | ||
|
||
return ( | ||
<ArkPinInput.Root | ||
className={cx(styles.root, css(cssProps), className)} | ||
ref={ref} | ||
{...rootProps} | ||
> | ||
{children && ( | ||
<ArkPinInput.Label className={styles.label}> | ||
{children} | ||
</ArkPinInput.Label> | ||
)} | ||
<ArkPinInput.Control className={styles.control}> | ||
{Array.from({ length }, (_, index) => index).map((id, index) => ( | ||
<ArkPinInput.Input | ||
className={styles.input} | ||
key={id} | ||
index={index} | ||
asChild | ||
> | ||
<Input size={variantProps.size} /> | ||
</ArkPinInput.Input> | ||
))} | ||
</ArkPinInput.Control> | ||
</ArkPinInput.Root> | ||
); | ||
}, | ||
); | ||
|
||
PinInput.displayName = 'PinInput'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
'use client'; | ||
|
||
import { Box, VStack } from '@style/jsx'; | ||
import { CHARACTERS } from 'data/characters'; | ||
import Image from 'next/image'; | ||
|
||
import { getEnemyArtwork } from 'utils/deck.utils'; | ||
|
||
import { useStore } from 'services/stores'; | ||
import { CharacterNames } from 'types/character.types'; | ||
|
||
import { inactiveImage } from './styles'; | ||
|
||
const isCharacterName = (name: string): name is CharacterNames => | ||
Object.values(CharacterNames).includes(name as CharacterNames); | ||
|
||
const InitiativeList = () => { | ||
const initiatives = useStore((state) => state.initiatives); | ||
console.log(initiatives); | ||
const { toggleInitiativePlayed } = useStore((state) => state.actions); | ||
|
||
const sortedInitiatives = Object.values(initiatives).sort( | ||
(initiativeA, initiativeB) => | ||
initiativeA.initiative - initiativeB.initiative, | ||
); | ||
|
||
console.log({ sortedInitiatives }); | ||
|
||
return ( | ||
<Box | ||
width={75} | ||
borderLeft="1px" | ||
borderColor="border.subtle" | ||
borderStyle="solid" | ||
my="4" | ||
px="4" | ||
> | ||
<VStack gap={1}> | ||
{sortedInitiatives.map((initiative) => { | ||
const isCharacter = isCharacterName(initiative.name); | ||
const icon = isCharacterName(initiative.name) | ||
? `/images/characters/${CHARACTERS[initiative.name].icon}` | ||
: `/images/thumbnails/${getEnemyArtwork(initiative.name)}`; | ||
|
||
return ( | ||
<Box | ||
key={initiative.name} | ||
my="2" | ||
cursor="pointer" | ||
onClick={() => toggleInitiativePlayed(initiative.name)} | ||
> | ||
<Image | ||
src={icon} | ||
width={37} | ||
height={37} | ||
alt={initiative.name} | ||
className={inactiveImage({ | ||
state: initiative.played ? 'disabled' : 'active', | ||
type: isCharacter ? 'character' : 'enemy', | ||
})} | ||
style={{ filter: 'grey-scale(1)' }} | ||
/> | ||
</Box> | ||
); | ||
})} | ||
</VStack> | ||
</Box> | ||
); | ||
}; | ||
|
||
export default InitiativeList; |
Oops, something went wrong.