diff --git a/apps/frontend/src/components/board/BoardView.tsx b/apps/frontend/src/components/board/BoardView.tsx index 76b509d..630d05e 100644 --- a/apps/frontend/src/components/board/BoardView.tsx +++ b/apps/frontend/src/components/board/BoardView.tsx @@ -14,14 +14,25 @@ const BoardView: FunctionComponent<{ boardViewModel: BoardViewModel; revert: boolean; onPitSelect: (index: number, pit: Pit) => void; -}> = ({ game, context, boardId, boardViewModel, revert, onPitSelect: onPitSelect }) => { +}> = ({ game, context, boardId, boardViewModel, revert, onPitSelect }) => { const mancalaGame = game?.mancalaGame; const theme = context.themeManager.theme; - const createPitView = (key: any, pit: Pit, pitViewModel: PitViewModel) => { - return onPitSelect(pit.index, pit)} context={context} />; - }; - const createPitViewList = (pits: Pit[]) => pits.map((pit, index) => createPitView(index, pit, boardViewModel.pits[pit.index])); + // Compute pit width based on viewport (each column is 11vw) + const pitWidth = typeof window !== "undefined" ? window.innerWidth * 0.11 : 100; + + const createPitView = (key: any, pit: Pit, pitViewModel: PitViewModel) => ( + onPitSelect(pit.index, pit)} + fontSize={pitWidth / 6} + /> + ); + + const createPitViewList = (pits: Pit[]) => + pits.map((pit, index) => createPitView(index, pit, boardViewModel.pits[pit.index])); const player1Pits = createPitViewList(mancalaGame?.board.player1Pits); const player2Pits = createPitViewList(mancalaGame?.board.player2Pits); @@ -29,6 +40,7 @@ const BoardView: FunctionComponent<{ const player2BankIndex = mancalaGame?.board.player2BankIndex(); const player1BankViewModel = boardViewModel.pits[player1BankIndex]; const player2BankViewModel = boardViewModel.pits[player2BankIndex]; + return (
{revert ? player1Pits?.reverse() : player2Pits?.reverse()} {revert ? player2Pits : player1Pits} diff --git a/apps/frontend/src/components/board/PitView.tsx b/apps/frontend/src/components/board/PitView.tsx index 71c4fc4..052e9c4 100644 --- a/apps/frontend/src/components/board/PitView.tsx +++ b/apps/frontend/src/components/board/PitView.tsx @@ -1,58 +1,83 @@ import * as React from "react"; import { FunctionComponent } from "react"; -import { getColorByBrightness } from "@mancala/core"; +import { getColorByBrightness, PitViewModel } from "@mancala/core"; import { Context } from "../../context/context"; import Util from "../../util/Util"; -import { PitViewModel } from "@mancala/core"; import StoneView from "./StoneView"; -const PitView: FunctionComponent<{ - pitViewModel: PitViewModel; - onClick: () => void; - context: Context; -}> = ({ pitViewModel, onClick, context }) => { - const textColor = getColorByBrightness( - pitViewModel.pitColor, - context.themeManager.theme.textColor, - context.themeManager.theme.textLightColor - ); - const stones = [...Util.range(pitViewModel.stoneCount)].map((i, index) => ( - - )); +interface PitViewProps { + pitViewModel: PitViewModel; + context: Context; + onClick: () => void; + fontSize: number; +} - return ( -
- {stones} - {pitViewModel.stoneCount} - -
- ); + const stones = [...Util.range(pitViewModel.stoneCount)].map((i, index) => ( + + )); + + return ( +
+ {stones} + {pitViewModel.stoneCount > 0 && ( + + {pitViewModel.stoneCount} + + )} + +
+ ); }; export default PitView; \ No newline at end of file diff --git a/apps/mobile/src/components/board/BoardView.tsx b/apps/mobile/src/components/board/BoardView.tsx index 54fb4e1..d42a00c 100644 --- a/apps/mobile/src/components/board/BoardView.tsx +++ b/apps/mobile/src/components/board/BoardView.tsx @@ -17,9 +17,9 @@ const BoardView: FunctionComponent<{ boardViewModel: BoardViewModel; revert: boolean; onPitSelect: (index: number, pit: Pit) => void; -}> = ({ game, context, boardId, boardViewModel, revert, onPitSelect: onPitSelect }) => { +}> = ({ game, context, boardId, boardViewModel, revert, onPitSelect }) => { const windowWidth = Dimensions.get('window').width; - const windowHeight = Dimensions.get('window').height; + const windowHeight = Dimensions.get('window').height; // Currently unused but kept for potential future use const boardMargin = 0; const boardPadding = 10; @@ -33,19 +33,22 @@ const BoardView: FunctionComponent<{ const createPitView = (key: any, pit: Pit, pitViewModel: PitViewModel) => { const stones = [...Util.range(pitViewModel.stoneCount)].map((i, index) => ( - + )); - return onPitSelect(pit.index, pit)} - style={{width: pitWidth, height: pitWidth}} - context={context} - fontSize={pitWidth / 5} - > - {stones} - ; + return ( + onPitSelect(pit.index, pit)} + style={{ width: pitWidth, height: pitWidth }} + fontSize={pitWidth / 5} // keep original divisor as per revert request + > + {stones} + + ); }; + const createPitViewList = (pits: Pit[]) => pits.map((pit, index) => createPitView(index, pit, boardViewModel.pits[pit.index])); const player1Pits = createPitViewList(mancalaGame?.board.player1Pits); @@ -57,52 +60,60 @@ const BoardView: FunctionComponent<{ const primaryStoreViewModel = revert ? player1BankViewModel : player2BankViewModel; const secondaryStoreViewModel = revert ? player2BankViewModel : player1BankViewModel; + const stonesPrimaryStore = [...Util.range(primaryStoreViewModel.stoneCount)].map((i, index) => ( - + )); + const stonesSecondaryStore = [...Util.range(secondaryStoreViewModel.stoneCount)].map((i, index) => ( - + )); return ( - + {stonesPrimaryStore} - - + + {revert ? player1Pits?.reverse() : player2Pits?.reverse()} - + {revert ? player2Pits : player1Pits} {stonesSecondaryStore} diff --git a/apps/mobile/src/components/board/PitView.tsx b/apps/mobile/src/components/board/PitView.tsx index 7a9c004..c4da6a4 100644 --- a/apps/mobile/src/components/board/PitView.tsx +++ b/apps/mobile/src/components/board/PitView.tsx @@ -3,55 +3,50 @@ import { FunctionComponent } from "react"; import { PitViewModel, getColorByBrightness } from "@mancala/core"; import { Context } from "../../context/context"; import { Pressable, View, ViewStyle, Text } from "react-native"; +import Util from "../../util/Util"; +import StoneView from "./StoneView"; -const PitView: FunctionComponent<{ - pitViewModel: PitViewModel; - context: Context; - onClick: () => void; - style: ViewStyle, - fontSize: number; - children: React.ReactNode -}> = ({ pitViewModel, context, onClick, style, fontSize, children }) => { - const textColor = getColorByBrightness( - pitViewModel.pitColor, - context.themeManager.theme.textColor, - context.themeManager.theme.textLightColor - ); +interface PitViewProps { + pitViewModel: PitViewModel; + context: Context; + onClick: () => void; + style: ViewStyle; + fontSize: number; +} - return ( - - - {children} - - {pitViewModel.stoneCount > 0 && ( - - {pitViewModel.stoneCount} - - )} - - ); +const PitView: FunctionComponent = ({ pitViewModel, context, onClick, style, fontSize }) => { + const textColor = getColorByBrightness( + pitViewModel.pitColor, + context.themeManager.theme.textColor, + context.themeManager.theme.textLightColor + ); + + const stones = [...Util.range(pitViewModel.stoneCount)].map((i, index) => ( + + )); + + return ( + + + {stones} + + {pitViewModel.stoneCount > 0 && ( + + {pitViewModel.stoneCount} + + )} + + ); }; export default PitView; \ No newline at end of file