various changes to reserved card handling in player ui
This commit is contained in:
@@ -1,21 +1,27 @@
|
|||||||
import { v4 } from 'uuid';
|
import { v4 } from 'uuid';
|
||||||
import { CardProps } from '../../util/propTypes';
|
import { CardProps } from '../../util/propTypes';
|
||||||
import { ResourceCost } from '../../util/types';
|
import { CardData, PlayerCards, ResourceCost } from '../../util/types';
|
||||||
import { useCurrentPlayer } from '../../hooks/useCurrentPlayer';
|
import { useCurrentPlayer } from '../../hooks/useCurrentPlayer';
|
||||||
import { buyCardActions } from '../Player/ActionMethods';
|
import { buyCardActions } from '../Player/ActionMethods';
|
||||||
import { hasMaxReserved, reserveCard } from '../Player/ActionMethods/reserveCardActions';
|
import { hasMaxReserved, reserveCard } from '../Player/ActionMethods/reserveCardActions';
|
||||||
const { buyCard, tooExpensive } = buyCardActions;
|
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);
|
const currentPlayer = useCurrentPlayer(state);
|
||||||
if (!data) return <div className="card"></div>;
|
if (!data || !currentPlayer) return <div className="card"></div>;
|
||||||
|
|
||||||
|
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 (
|
return (
|
||||||
<div className="card" key={v4()}>
|
<div className='card' key={v4()}>
|
||||||
<img src={data.image} loading="lazy" />
|
<img src={data.image} loading="lazy" />
|
||||||
<div className="foreground">
|
<div className={reserved ? `foreground-${data.gemValue}` : 'foreground'}>
|
||||||
|
<section className="card-top-section">
|
||||||
<p>{data.gemValue.toUpperCase()}</p>
|
<p>{data.gemValue.toUpperCase()}</p>
|
||||||
{ (data.points && data.points > 0) ? <p>{data.points} {data.points === 1 ? 'point' : 'points'}</p> : null }
|
|
||||||
<div className="total-card-cost">
|
<div className="total-card-cost">
|
||||||
{
|
{
|
||||||
Object.keys(data.resourceCost).map((key: keyof ResourceCost | string) => {
|
Object.keys(data.resourceCost).map((key: keyof ResourceCost | string) => {
|
||||||
@@ -28,20 +34,29 @@ export default function Card({ data, state, setState }: CardProps) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
</div>
|
</div>
|
||||||
|
{ (data.points && data.points > 0) ? <p>{data.points} {data.points === 1 ? 'point' : 'points'}</p> : null }
|
||||||
|
</section>
|
||||||
|
|
||||||
|
{
|
||||||
|
(state.actions.buyCard.active || state.actions.reserveCard.active) && (
|
||||||
|
<section className="card-action-section">
|
||||||
{ state.actions.buyCard.active &&
|
{ state.actions.buyCard.active &&
|
||||||
<button
|
<button
|
||||||
onClick={() => buyCard(state, setState, data)}
|
onClick={() => buyCard(state, setState, data)}
|
||||||
disabled={tooExpensive(data, state)}>
|
disabled={purchaseDisabled()}>
|
||||||
Buy This Card
|
Buy This Card
|
||||||
</button>
|
</button>
|
||||||
}
|
}
|
||||||
{ state.actions.reserveCard.active &&
|
{ !reserved && state.actions.reserveCard.active &&
|
||||||
<button
|
<button
|
||||||
onClick={() => reserveCard(state, setState, data)}
|
onClick={() => reserveCard(state, setState, data)}
|
||||||
disabled={hasMaxReserved(currentPlayer)}>
|
disabled={hasMaxReserved(currentPlayer)}>
|
||||||
Reserve This Card
|
Reserve This Card
|
||||||
</button>
|
</button>
|
||||||
}
|
}
|
||||||
|
</section>
|
||||||
|
)
|
||||||
|
}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -56,7 +56,6 @@
|
|||||||
@include map-gem-values(".card-cost");
|
@include map-gem-values(".card-cost");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.card-count {
|
.card-count {
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
@import '../../sass/helper/mixins';
|
@import '../../sass/helper/mixins';
|
||||||
|
@import '../../sass/helper/variables';
|
||||||
@import '../../sass/helper/placeholders';
|
@import '../../sass/helper/placeholders';
|
||||||
|
|
||||||
.all-players {
|
.all-players {
|
||||||
@@ -33,5 +34,35 @@
|
|||||||
@include map-gem-values(".reserve-cost");
|
@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");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -29,18 +29,7 @@ export default function Player({ player, state, setState }: PlayerProps) {
|
|||||||
dynamic && setReservedView(
|
dynamic && setReservedView(
|
||||||
<div className="reserved-card-view">
|
<div className="reserved-card-view">
|
||||||
<p>Reserved cards:</p>
|
<p>Reserved cards:</p>
|
||||||
{
|
{ dynamic.reservedCards?.map((data: CardData) => <Card key={v4()} data={data} state={state} setState={setState} reserved={true} />) }
|
||||||
dynamic.reservedCards?.map((data: CardData) => (
|
|
||||||
<div className="reserved-card">
|
|
||||||
<p className={`mini-card ${data.gemValue}`} key={v4()}>{data.gemValue} card: {data.points || 0} points</p>
|
|
||||||
<div className="reserved-card-cost">
|
|
||||||
{
|
|
||||||
Object.entries(data.resourceCost).map(([key, value]) => value > 0 && <p className={`reserve-cost-${key}`} key={v4()}>{value}</p>)
|
|
||||||
}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
))
|
|
||||||
}
|
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
}, [dynamic, setState])
|
}, [dynamic, setState])
|
||||||
|
|||||||
@@ -1,8 +1 @@
|
|||||||
$emerald-images:
|
$gemlist: 'ruby', 'sapphire', 'onyx', 'emerald', 'diamond', 'gold';
|
||||||
"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"
|
|
||||||
;
|
|
||||||
@@ -7,6 +7,7 @@ export interface StateProps {
|
|||||||
|
|
||||||
export interface CardProps extends StateProps {
|
export interface CardProps extends StateProps {
|
||||||
data: CardData
|
data: CardData
|
||||||
|
reserved?: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface CardRowProps extends StateProps {
|
export interface CardRowProps extends StateProps {
|
||||||
|
|||||||
Reference in New Issue
Block a user