From 8be89334463509146fa125506ce3d38730f6706b Mon Sep 17 00:00:00 2001 From: Mikayla Dobson Date: Sat, 27 Aug 2022 14:53:02 -0500 Subject: [PATCH] various changes to reserved card handling in player ui --- src/components/Card/Card.tsx | 77 ++++++++++++++++----------- src/components/Card/CardRow.scss | 1 - src/components/Player/AllPlayers.scss | 31 +++++++++++ src/components/Player/Player.tsx | 13 +---- src/sass/helper/_variables.scss | 9 +--- src/util/propTypes.ts | 1 + 6 files changed, 80 insertions(+), 52 deletions(-) diff --git a/src/components/Card/Card.tsx b/src/components/Card/Card.tsx index 3f7090d..af60a5c 100644 --- a/src/components/Card/Card.tsx +++ b/src/components/Card/Card.tsx @@ -1,46 +1,61 @@ import { v4 } from 'uuid'; import { CardProps } from '../../util/propTypes'; -import { ResourceCost } from '../../util/types'; +import { CardData, PlayerCards, ResourceCost } from '../../util/types'; import { useCurrentPlayer } from '../../hooks/useCurrentPlayer'; import { buyCardActions } from '../Player/ActionMethods'; import { hasMaxReserved, reserveCard } from '../Player/ActionMethods/reserveCardActions'; const { buyCard, tooExpensive } = buyCardActions; -export default function Card({ data, state, setState }: CardProps) { +export default function Card({ data, state, setState, reserved = false }: CardProps) { const currentPlayer = useCurrentPlayer(state); - if (!data) return
; + if (!data || !currentPlayer) return
; + + const purchaseDisabled = (): boolean => { + // TO DO: check whether a card belongs to the current player, + // if card is tagged as reserved + return tooExpensive(data, state); + } return ( -
+
-
-

{data.gemValue.toUpperCase()}

- { (data.points && data.points > 0) ?

{data.points} {data.points === 1 ? 'point' : 'points'}

: null } -
+
+
+

{data.gemValue.toUpperCase()}

+
+ { + Object.keys(data.resourceCost).map((key: keyof ResourceCost | string) => { + // @ts-ignore + return (data.resourceCost[key as keyof ResourceCost] > 0) && ( +

+ {data.resourceCost[key as keyof ResourceCost]} +

+ ) + }) + } +
+ { (data.points && data.points > 0) ?

{data.points} {data.points === 1 ? 'point' : 'points'}

: null } +
+ { - Object.keys(data.resourceCost).map((key: keyof ResourceCost | string) => { - // @ts-ignore - return (data.resourceCost[key as keyof ResourceCost] > 0) && ( -

- {data.resourceCost[key as keyof ResourceCost]} -

- ) - }) - } -
- { state.actions.buyCard.active && - - } - { state.actions.reserveCard.active && - + (state.actions.buyCard.active || state.actions.reserveCard.active) && ( +
+ { state.actions.buyCard.active && + + } + { !reserved && state.actions.reserveCard.active && + + } +
+ ) }
diff --git a/src/components/Card/CardRow.scss b/src/components/Card/CardRow.scss index 8a79b83..bfac8e9 100644 --- a/src/components/Card/CardRow.scss +++ b/src/components/Card/CardRow.scss @@ -56,7 +56,6 @@ @include map-gem-values(".card-cost"); } } - } .card-count { diff --git a/src/components/Player/AllPlayers.scss b/src/components/Player/AllPlayers.scss index 0d9d233..f823dae 100644 --- a/src/components/Player/AllPlayers.scss +++ b/src/components/Player/AllPlayers.scss @@ -1,4 +1,5 @@ @import '../../sass/helper/mixins'; +@import '../../sass/helper/variables'; @import '../../sass/helper/placeholders'; .all-players { @@ -33,5 +34,35 @@ @include map-gem-values(".reserve-cost"); } } + + .card { + width: 100%; + + img { + display: none; + } + + @each $gem in $gemlist { + @include map-gem-values('.foreground'); + .foreground-#{$gem} { + display: flex; + flex-direction: column; + align-items: center; + padding: 8px; + + p { + display: inline; + padding: 8px; + } + + .total-card-cost { + display: flex; + flex-flow: row wrap; + justify-content: center; + @include map-gem-values(".card-cost"); + } + } + } + } } } \ No newline at end of file diff --git a/src/components/Player/Player.tsx b/src/components/Player/Player.tsx index 5baeebb..f3ce8f4 100644 --- a/src/components/Player/Player.tsx +++ b/src/components/Player/Player.tsx @@ -29,18 +29,7 @@ export default function Player({ player, state, setState }: PlayerProps) { dynamic && setReservedView(

Reserved cards:

- { - dynamic.reservedCards?.map((data: CardData) => ( -
-

{data.gemValue} card: {data.points || 0} points

-
- { - Object.entries(data.resourceCost).map(([key, value]) => value > 0 &&

{value}

) - } -
-
- )) - } + { dynamic.reservedCards?.map((data: CardData) => ) }
) }, [dynamic, setState]) diff --git a/src/sass/helper/_variables.scss b/src/sass/helper/_variables.scss index 47b029f..4e85eae 100644 --- a/src/sass/helper/_variables.scss +++ b/src/sass/helper/_variables.scss @@ -1,8 +1 @@ -$emerald-images: - "src/assets/img/SUCCULENT-angele-kamp-unsplash.jpg", - "src/assets/img/SUCCULENT-annie-spratt-unsplash.jpg", - "src/assets/img/SUCCULENT-calle-macarone-unsplash.jpg", - "src/assets/img/SUCCULENT-edgar-castrejon-unsplash.jpg", - "src/assets/img/SUCCULENT-jacalyn-beales-unsplash.jpg", - "src/assets/img/SUCCULENT-tim-mossholder-unsplash.jpg" -; \ No newline at end of file +$gemlist: 'ruby', 'sapphire', 'onyx', 'emerald', 'diamond', 'gold'; \ No newline at end of file diff --git a/src/util/propTypes.ts b/src/util/propTypes.ts index de669f6..d8c4ef9 100644 --- a/src/util/propTypes.ts +++ b/src/util/propTypes.ts @@ -7,6 +7,7 @@ export interface StateProps { export interface CardProps extends StateProps { data: CardData + reserved?: boolean } export interface CardRowProps extends StateProps {