From 1ce3026e6f7e21216b8aac07a2c5fde68f4a9b43 Mon Sep 17 00:00:00 2001
From: Mikayla Dobson <93477693+innocuous-symmetry@users.noreply.github.com>
Date: Mon, 25 Jul 2022 12:29:39 -0500
Subject: [PATCH] in progress: ui for viewing player resources
---
src/components/Card/Card.tsx | 7 +++---
src/components/Card/CardRow.tsx | 29 ++++++++++++++++-----
src/components/Gameboard/Gameboard.tsx | 6 ++---
src/components/Player/ActionMethods.ts | 35 +-------------------------
src/components/Player/Player.tsx | 11 ++++++--
5 files changed, 40 insertions(+), 48 deletions(-)
diff --git a/src/components/Card/Card.tsx b/src/components/Card/Card.tsx
index ef94e68..b2520e3 100644
--- a/src/components/Card/Card.tsx
+++ b/src/components/Card/Card.tsx
@@ -1,11 +1,11 @@
-import { CardData } from '../../util/types';
+import { CardData, StateProps } from '../../util/types';
import { v4 } from 'uuid';
-type CardProps = {
+interface CardProps extends StateProps {
data: CardData
}
-export default function Card({ data }: CardProps) {
+export default function Card({ data, state, setState }: CardProps) {
return (
@@ -18,6 +18,7 @@ export default function Card({ data }: CardProps) {
return (data.resourceCost[key] > 0) &&
{key}: {data.resourceCost[key]}
})
}
+ { state.actions.buyCard.active &&
}
)
diff --git a/src/components/Card/CardRow.tsx b/src/components/Card/CardRow.tsx
index fc02b6f..8906727 100644
--- a/src/components/Card/CardRow.tsx
+++ b/src/components/Card/CardRow.tsx
@@ -1,18 +1,35 @@
import { v4 } from 'uuid';
-import { CardData } from "../../util/types"
+import { CardData, StateProps } from "../../util/types"
import Card from "../Card/Card"
-interface CardRowProps {
- tier: number,
- cards: CardData[]
+interface CardRowProps extends StateProps {
+ tier: number
}
-export default function CardRow({tier, cards}: CardRowProps) {
+export default function CardRow({tier, state, setState}: CardRowProps) {
+ let cards: Array
+ switch (tier) {
+ case 1:
+ cards = state.gameboard.cardRows.tierOne;
+ break;
+ case 2:
+ cards = state.gameboard.cardRows.tierTwo;
+ break;
+ case 3:
+ cards = state.gameboard.cardRows.tierThree;
+ break;
+ default:
+ cards = new Array;
+ break;
+ }
+
return (
Tier: {tier}
- { cards && cards.map((cardData: CardData) => ) }
+ { cards && cards.map((cardData: CardData) => {
+ return
+ })}
)
diff --git a/src/components/Gameboard/Gameboard.tsx b/src/components/Gameboard/Gameboard.tsx
index c942fe8..b2e198a 100644
--- a/src/components/Gameboard/Gameboard.tsx
+++ b/src/components/Gameboard/Gameboard.tsx
@@ -79,9 +79,9 @@ export default function Gameboard({ state, setState }: StateProps) {
Round: {state.round}
-
-
-
+
+
+
{/* @ts-ignore */}
diff --git a/src/components/Player/ActionMethods.ts b/src/components/Player/ActionMethods.ts
index 1b2a88c..081fca3 100644
--- a/src/components/Player/ActionMethods.ts
+++ b/src/components/Player/ActionMethods.ts
@@ -2,27 +2,6 @@ import { AppState, PlayerData, ResourceCost, setStateType } from "../../util/typ
import { turnOrderUtil } from "../../util/TurnOrderUtil";
import { initialActions } from "../../util/stateSetters";
-export const _getChips = (resource: string | Array
, dynamic: PlayerData | undefined, setState: setStateType) => {
- if (!dynamic || !dynamic?.turnActive) return;
-
- setState((prev: AppState) => {
- const { newPlayers, roundIncrement } = turnOrderUtil(prev, dynamic);
-
- return {
- ...prev,
- round: (roundIncrement ? prev.round + 1 : prev.round),
- gameboard: {
- ...prev.gameboard,
- tradingResources: {
- ...prev.gameboard.tradingResources,
- [resource as keyof ResourceCost]: prev.gameboard.tradingResources[resource as keyof ResourceCost] -= 1
- }
- },
- players: newPlayers
- }
- })
-}
-
export const validateChips = (state: AppState): boolean => {
if (!state.actions.getChips.active || !state.actions.getChips.selection) return false;
@@ -50,13 +29,7 @@ export const validateChips = (state: AppState): boolean => {
return true;
}
-export const getChips = (state: AppState, setState: setStateType): boolean => {
- /**
- * features:
- * update their inventory state
- * update the total available resources
- */
-
+export const getChips = (state: AppState, setState: setStateType) => {
let targetPlayer: PlayerData;
for (let each in state.players) {
@@ -88,10 +61,8 @@ export const getChips = (state: AppState, setState: setStateType): boolean => {
}
}
}
-
}
-
return {
...prev,
round: (roundIncrement ? prev.round + 1 : prev.round),
@@ -103,10 +74,6 @@ export const getChips = (state: AppState, setState: setStateType): boolean => {
actions: initialActions
}
})
-
- console.log(state.players);
-
- return true;
}
export const buyCard = () => {
diff --git a/src/components/Player/Player.tsx b/src/components/Player/Player.tsx
index 56f2aad..b9e4f12 100644
--- a/src/components/Player/Player.tsx
+++ b/src/components/Player/Player.tsx
@@ -12,7 +12,9 @@ export default function Player({ player, state, setState, setActionState }: Play
const [prompt, setPrompt] = useState("Your turn! Select an action type below.");
const [actionSelection, setActionSelection] = useState(-1);
- useEffect(() => setDynamic(state.players.find((element: PlayerData) => element.id === player.id)), [state]);
+ useEffect(() => {
+ setDynamic(state.players.find((element: PlayerData) => element.id === player.id))
+ }, [state]);
useEffect(() => {
setActionState(actionSelection, dynamic);
@@ -40,7 +42,12 @@ export default function Player({ player, state, setState, setActionState }: Play
-
+
+
{dynamic?.name}'s Resources
+ { dynamic && Object.entries(dynamic?.inventory).map(([key,value]) => {
+ return value > 0 &&
{key}: {value}
+ })}
+
)