version maintenance

This commit is contained in:
2022-08-16 11:31:22 -05:00
parent 3234966629
commit 40904d36d3
4 changed files with 19 additions and 10 deletions

View File

@@ -12,6 +12,8 @@ import AvailableChips from '../Resources/AvailableChips';
import AllPlayers from '../Player/AllPlayers';
import CardRow from '../Card/CardRow';
import SelectionView from '../Resources/SelectionView';
import { useCurrentPlayer } from '../../hooks/useCurrentPlayer';
import getTotalBuyingPower from '../../util/getTotalBuyingPower';
const { validateChips } = getChipsActions;
export default function Gameboard({ state, setState }: StateProps) {
@@ -57,6 +59,13 @@ export default function Gameboard({ state, setState }: StateProps) {
}
}, [state])
useEffect(() => {
if (state.actions.buyCard.active) {
const currentPlayer = useCurrentPlayer(state);
currentPlayer && console.log(getTotalBuyingPower(currentPlayer));
}
}, [state.actions])
// displays state of board if data is populated, otherwise points to game constructor
useEffect(() => {
if (!state.players.length) {

View File

@@ -1,11 +1,11 @@
import { turnOrderUtil } from "../../../util/turnOrderUtil";
import { AppState, CardData, FullDeck, PlayerCards, ResourceCost, setStateType } from "../../../util/types";
import { useCurrentPlayer } from "../../../hooks/useCurrentPlayer";
import getTotalBuyingPower from "../../../util/getTotalBuyingPower";
import { initialActions, setStateGetNoble } from "../../../hooks/stateSetters";
import { canPickUpNoble } from "../../Nobles/canPickUpNoble";
import usePreviousPlayer from "../../../hooks/usePreviousPlayer";
import { AppState, CardData, PlayerCards, ResourceCost, setStateType } from "../../../util/types";
import cardTierToKey from "../../../util/cardTierToKey";
import { canPickUpNoble } from "../../Nobles/canPickUpNoble";
import { initialActions, setStateGetNoble } from "../../../hooks/stateSetters";
import { useCurrentPlayer } from "../../../hooks/useCurrentPlayer";
import usePreviousPlayer from "../../../hooks/usePreviousPlayer";
export const tooExpensive = (card: CardData, state: AppState): boolean => {
const currentPlayer = useCurrentPlayer(state);
@@ -63,7 +63,7 @@ export const buyCard = (state: AppState, setState: setStateType, card: CardData)
let goldToReturn = 0;
// @ts-ignore
if (cardCost[typedKey] > totalBuyingPower[typedKey]) {
while (cardCostPointer > tempPlayerInventory) {
availableGold--;
goldToReturn++;
tempPlayerInventory++;

View File

@@ -1,6 +1,6 @@
import React from 'react'
import ReactDOM from 'react-dom/client'
import { render } from 'react-dom'
import App from './App'
import './index.css'
ReactDOM.createRoot(document.getElementById('root') as HTMLElement).render(<App />)
const root = document.getElementById('root') as HTMLElement;
render(<App />, root);

View File

@@ -11,7 +11,7 @@ export default function getTotalBuyingPower(currentPlayer: PlayerData) {
}
if (!currentPlayer) return totalBuyingPower;
for (let [key,quantity] of Object.entries(currentPlayer.inventory)) {
totalBuyingPower[key as keyof ResourceCost] += quantity;
}