Skip to content

Commit

Permalink
Merge pull request #7 from JollyGrin/feat/deck
Browse files Browse the repository at this point in the history
Feat/deck
  • Loading branch information
JollyGrin authored Sep 9, 2024
2 parents 0f5c987 + a8f0914 commit f6ec17c
Show file tree
Hide file tree
Showing 14 changed files with 203 additions and 99 deletions.
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
"@dnd-kit/sortable": "^8.0.0",
"@radix-ui/react-dialog": "^1.1.1",
"@shadow-panda/style-context": "^0.7.1",
"lucide-react": "^0.439.0",
"next": "14.2.8",
"react": "^18",
"react-dom": "^18"
Expand Down
12 changes: 0 additions & 12 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file added public/card-backs/atlas.webp
Binary file not shown.
Binary file added public/card-backs/m_atlas.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/card-backs/m_spells.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion src/components/atoms/card-view/card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export const CardImage = ({
backgroundRepeat="no-repeat"
transition="all 0.25s ease"
// bg="gray.400"
/>{" "}
/>
</Box>
);
};
36 changes: 8 additions & 28 deletions src/components/atoms/mock-cards/atlas.tsx
Original file line number Diff line number Diff line change
@@ -1,56 +1,36 @@
import { useHover } from "@/utils/hooks/useHover";
import { useKeyPress } from "@/utils/hooks/useKeyPress";
import { useEffect, useRef, useState } from "react";
import { Box } from "styled-system/jsx";

export const CardAtlas = ({
height = "90px",
img = "atlas_rift_valley.webp",
}: {
img?: string;
height?: string;
}) => {
const hoverRef = useRef(null);
const isHovering = useHover(hoverRef);

const isPressed = useKeyPress("Alt");
const [preview, setPreview] = useState(false);
useEffect(() => {
if (isHovering && isPressed) {
setPreview((prev) => !prev);
}
}, [isPressed]);

// const show = preview && isHovering; // full preview of the card
const show = false;
return (
<Box
position="relative"
m="0.5rem auto"
m="0 auto"
w="calc(100% - 1rem)"
maxW="221px"
h="70px"
bg="yellow"
borderRadius="1rem"
isolation="isolate"
overflow={show ? "unset" : "clip"}
zIndex={show ? 1000000 : "unset"}
onMouseOut={() => setPreview(false)}
overflow="clip"
style={{ height }}
>
<Box
style={{ backgroundImage: `url(/mock-cards/${img})` }} // bgImage has caching issues
ref={hoverRef}
isolation="isolate"
h="310px"
w="100%"
position="absolute"
top={show ? 0 : "-85px"}
right={0 + "px"}
bottom={-160 + "px"}
backgroundPosition="right"
backgroundSize="cover"
backgroundRepeat="no-repeat"
transform={
show
? "scale(1.45) rotate(90deg) translate(-47.8%, 0px)"
: "scale(0.85) rotate(90deg) translate(-47.8%, 0px)"
}
transform="scale(0.85) rotate(90deg) translate(-47.8%, 0px)"
bg="gray.400"
borderRadius="1rem"
transition="all 0.25s ease"
Expand Down
6 changes: 4 additions & 2 deletions src/components/atoms/mock-cards/card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { useEffect, useRef, useState } from "react";
import { Box } from "styled-system/jsx";

export const CardImage = ({
height = "90px",
img = "headless_haunt.webp",
position = "top",
index = 1,
Expand All @@ -15,6 +16,7 @@ export const CardImage = ({
index?: number;
isTapped?: boolean;
show?: boolean;
height?: string;
}) => {
const hoverRef = useRef(null);
const isHovering = useHover(hoverRef);
Expand All @@ -32,10 +34,9 @@ export const CardImage = ({
return (
<Box
position="relative"
m="0.5rem auto"
m="0 auto"
w="calc(100% - 1rem)"
maxW="221px"
h="90px"
bg="yellow"
overflow={show ? "unset" : "clip"}
borderRadius="1rem"
Expand All @@ -48,6 +49,7 @@ export const CardImage = ({
opacity={isTapped && !isHovering ? "0.8" : "1"}
transition="all 0.25s ease"
onMouseOut={() => setPreview(false)}
style={{ height }}
>
<Box
ref={hoverRef}
Expand Down
7 changes: 4 additions & 3 deletions src/components/organisms/GameBoard/Auras/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,16 @@ import { useState } from "react";
import { Modal } from "@/components/atoms/Modal";
import { FullCardAtlas } from "@/components/atoms/card-view/atlas";
import { CardImage as FullCard } from "@/components/atoms/card-view/card";
import { GRIDS } from "../constants";

export const Auras = (props: GameStateActions) => {
return (
<Box position="absolute" w="100%" h="100%">
{Array.from({ length: 12 }).map((_, index) => (
<Aura
key={"aura" + index}
card={props.gridItems?.[21 + index]?.[0]}
gridIndex={21 + index}
card={props.gridItems?.[GRIDS.AURA_1 + index]?.[0]}
gridIndex={GRIDS.AURA_1 + index}
index={0}
/>
))}
Expand All @@ -26,7 +27,7 @@ export const Auras = (props: GameStateActions) => {
const Aura = (props: { card: GameCard; gridIndex: number; index: number }) => {
const auraCard = props.card;

const auraIndex = props.gridIndex - 21; // normalize to zero
const auraIndex = props.gridIndex - GRIDS.AURA_1; // normalize to zero
const topIndex = Math.floor(auraIndex / 4) + 1; // increments every 4
const top = `${topIndex * 25}%`; // in percent
const leftIndex = 1 + (auraIndex % 4); // every 4, resets
Expand Down
94 changes: 94 additions & 0 deletions src/components/organisms/GameBoard/Footer/Decks.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
import { Grid, VStack } from "styled-system/jsx";
import { GRIDS, LAYOUT_HEIGHTS } from "../constants";
import { GameStateActions } from "..";

export const DecksTray = (props: GameStateActions) => {
function draw(deck: GRIDS.DECK | GRIDS.ATLAS_DECK) {
props.setGridItems((prev) => {
// Create a shallow copy of the previous grid items array
const newGridItems = [...prev];

// Make a copy of the deck and hand arrays, preserving their positions
const newDeck = [...newGridItems[deck]];
const newHand = [...newGridItems[GRIDS.HAND]];

// Pop a card from the deck and push it to the hand
const card = newDeck.pop();
if (card) newHand.push(card);

// Update the newGridItems array with the updated deck and hand arrays
newGridItems[deck] = newDeck;
newGridItems[GRIDS.HAND] = newHand;

// Return the updated newGridItems array to trigger a re-render
return newGridItems;
});
}

function drawDeck() {
draw(GRIDS.DECK);
}
function drawAtlas() {
draw(GRIDS.ATLAS_DECK);
}

const atlasRemainingCards = props.gridItems[GRIDS.ATLAS_DECK]?.length;
const deckRemainingCards = props.gridItems[GRIDS.DECK]?.length;

return (
<VStack
bg="blue"
w="100%"
py="1rem"
// style={{ height: LAYOUT_HEIGHTS.footer }}
style={{ height: LAYOUT_HEIGHTS.footer }}
>
<Grid
h="70px"
aspectRatio={3 / 2}
onClick={drawAtlas}
placeItems="center"
borderRadius="0.25rem"
cursor="pointer"
backgroundSize="cover"
style={{
backgroundImage: "url(/card-backs/m_atlas.png)",
}}
>
<p
style={{
fontWeight: 700,
background: "rgba(255,255,255,0.7)",
padding: "0 0.25rem",
borderRadius: "0.25rem",
}}
>
{atlasRemainingCards}
</p>
</Grid>
<Grid
w="60px"
aspectRatio={2 / 3}
onClick={drawDeck}
placeItems="center"
borderRadius="0.25rem"
cursor="pointer"
backgroundSize="cover"
style={{
backgroundImage: "url(/card-backs/m_spells.png)",
}}
>
<p
style={{
fontWeight: 700,
background: "rgba(255,255,255,0.7)",
padding: "0 0.25rem",
borderRadius: "0.25rem",
}}
>
{deckRemainingCards}
</p>
</Grid>
</VStack>
);
};
22 changes: 15 additions & 7 deletions src/components/organisms/GameBoard/Footer/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Grid, HStack } from "styled-system/jsx";
import { LAYOUT_HEIGHTS } from "../constants";
import { Box, Grid, HStack } from "styled-system/jsx";
import { GRIDS, LAYOUT_HEIGHTS } from "../constants";
import { DroppableGridItem } from "@/components/molecules/DropGridItem";
import {
horizontalListSortingStrategy,
Expand All @@ -9,9 +9,10 @@ import { GameStateActions } from "..";
import { SortableItem } from "@/components/molecules/SortItem";
import { CardAtlas } from "@/components/atoms/mock-cards/atlas";
import { CardImage } from "@/components/atoms/mock-cards/card";
import { DecksTray } from "./Decks";

export const GameFooter = (props: GameStateActions) => {
const gridIndex = 20;
const gridIndex = GRIDS.HAND;
const cardsInHand = props.gridItems[gridIndex] ?? [];

return (
Expand All @@ -23,9 +24,9 @@ export const GameFooter = (props: GameStateActions) => {
overflowX: "auto",
}}
>
<Grid h="100%" gridTemplateColumns="100px 100px 1fr">
<p>Grave</p>
<p>Deck</p>
<Grid h="100%" gridTemplateColumns="repeat(2,150px) 1fr" gap={0}>
<Box bg="yellow">Grave</Box>
<DecksTray {...props} />
<DroppableGridItem id={gridIndex.toString()} gridIndex={gridIndex}>
<SortableContext
id={`grid-${gridIndex}`}
Expand All @@ -34,7 +35,14 @@ export const GameFooter = (props: GameStateActions) => {
)}
strategy={horizontalListSortingStrategy}
>
<HStack p={0} m={0} w="100%" h="100%" justifyContent="start">
<HStack
p={0}
m={0}
w="calc(100vw - 300px)"
h="100%"
justifyContent="start"
overflowX="auto"
>
{props.gridItems?.[gridIndex]?.map((card, index) => (
<div
key={card.id}
Expand Down
45 changes: 45 additions & 0 deletions src/components/organisms/GameBoard/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,48 @@ const footer = `170px`;
const body = `calc(100vh - ${nav} - ${footer})`;

export const LAYOUT_HEIGHTS = { nav, footer, body };

/**
* GRID ORDERING
*
* Contains the grid, auras, hand, deck, atlas deck, grave
* */

export enum GRIDS {
GRID_1,
GRID_2,
GRID_3,
GRID_4,
GRID_5,
GRID_6,
GRID_7,
GRID_8,
GRID_9,
GRID_10,
GRID_11,
GRID_12,
GRID_13,
GRID_14,
GRID_15,
GRID_16,
GRID_17,
GRID_18,
GRID_19,
GRID_20,
AURA_1,
AURA_2,
AURA_3,
AURA_4,
AURA_5,
AURA_6,
AURA_7,
AURA_8,
AURA_9,
AURA_10,
AURA_11,
AURA_12,
HAND,
DECK,
ATLAS_DECK,
GRAVE,
}
Loading

0 comments on commit f6ec17c

Please sign in to comment.