Skip to content

Commit

Permalink
Merge pull request #46 from JollyGrin/feat/add-boost-from-top-of-deck
Browse files Browse the repository at this point in the history
Feat/add boost from top of deck
  • Loading branch information
JollyGrin authored Nov 10, 2024
2 parents 988f76a + d9948c4 commit 9070345
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 13 deletions.
16 changes: 16 additions & 0 deletions components/DeckPool/PoolFns.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,22 @@ export const boostCard = (pool: PoolType, cardIndex: number): PoolType => {
return pool;
};

export const boostFromTopDeck = (pool: PoolType): PoolType => {
if (!pool?.deck) return pool;
if (!pool?.hand) return pool;
if (pool.commit.boost) return pool;

if (pool.deck.length === 0) {
alert("No cards left");
}
const card = pool?.deck?.pop();
if (card) {
pool.commit.boost = card;
}

return pool;
};

export const cancelBoost = (pool: PoolType): PoolType => {
if (!pool?.commit.boost) return pool;
pool.hand.unshift(pool.commit.boost);
Expand Down
13 changes: 2 additions & 11 deletions components/Game/game.carousel.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,10 @@
//@ts-nocheck
import { mockDeck } from "@/_mocks_/deck";
import React, { useEffect, useRef, useState } from "react";
import React, { useRef, useState } from "react";
import AliceCarousel from "react-alice-carousel";
import "react-alice-carousel/lib/alice-carousel.css";
import { CardFactory } from "../CardFactory/card.factory";
import {
Box,
Button,
Flex,
Popover,
Select,
Skeleton,
Spacer,
Text,
} from "@chakra-ui/react";
import { Box, Flex, Skeleton, Spacer, Text } from "@chakra-ui/react";
import {
DeckImportCardType,
DeckImportType,
Expand Down
15 changes: 14 additions & 1 deletion components/Game/game.modal-body.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { PoolType } from "../DeckPool/PoolFns";
import { useState } from "react";

import { GiUpgrade as IconBoost } from "react-icons/gi";
import { PopoverCardActions } from "./card-actions.popover";

export const DeckModalContent = ({
cards,
Expand Down Expand Up @@ -55,7 +56,8 @@ export const CommitModalContent: React.FC<{
onClose: () => void;
onFlip: () => void;
onDiscard: () => void;
}> = ({ commits, onClose, onFlip, onDiscard }) => {
onBoostTopDeck: () => void;
}> = ({ commits, onClose, onFlip, onDiscard, onBoostTopDeck }) => {
return (
<Flex flexDir="column" justifyContent="space-evenly" gap={3} minH={"40svh"}>
<Flex
Expand All @@ -72,6 +74,17 @@ export const CommitModalContent: React.FC<{
<Button onClick={onClose}>Cancel</Button>
<Button onClick={onFlip}>Flip</Button>
<Button onClick={onDiscard}>Discard</Button>

<div style={{ fontSize: "2rem" }}>
<PopoverCardActions
actions={[
{
text: "Boost from top of deck",
fn: onBoostTopDeck,
},
]}
/>
</div>
</Flex>
</Flex>
);
Expand Down
8 changes: 7 additions & 1 deletion components/Game/game.modal-template.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ import {
PlayerCommit,
} from "./game.modal-body";
import { ModalType } from "@/pages/game";
import { useWebGame } from "@/lib/contexts/WebGameProvider";
import {
PoolType,
boostFromTopDeck,
cancelCommit,
discardCommit,
drawDeck,
Expand Down Expand Up @@ -88,6 +88,11 @@ export const ModalContainer: React.FC<ModalTemplateType> = ({
setGameState,
);

const gBoostTopDeck = flow(
() => playerState?.pool && boostFromTopDeck(playerState?.pool),
setGameState,
);

const gDrawDeck = (discardIndex: number) =>
flow(
() => playerState?.pool && drawDeck(playerState?.pool, discardIndex),
Expand Down Expand Up @@ -141,6 +146,7 @@ export const ModalContainer: React.FC<ModalTemplateType> = ({
commits={commits}
onFlip={gFlip}
onDiscard={gDiscardCommit}
onBoostTopDeck={gBoostTopDeck}
/>
)}
</ModalBody>
Expand Down

0 comments on commit 9070345

Please sign in to comment.