Compare commits

..

5 Commits

5 changed files with 183 additions and 154 deletions

View File

@ -21,18 +21,18 @@ const BoardView: FunctionComponent<{
// Compute pit width based on viewport (each column is 11vw) // Compute pit width based on viewport (each column is 11vw)
const pitWidth = typeof window !== "undefined" ? window.innerWidth * 0.11 : 100; const pitWidth = typeof window !== "undefined" ? window.innerWidth * 0.11 : 100;
const createPitView = (key: any, pit: Pit, pitViewModel: PitViewModel) => { const createPitView = (key: any, pit: Pit, pitViewModel: PitViewModel) => (
return ( <PitView
<PitView key={key}
key={key} pitViewModel={pitViewModel}
pitViewModel={pitViewModel} context={context}
context={context} onClick={() => onPitSelect(pit.index, pit)}
onClick={() => onPitSelect(pit.index, pit)} fontSize={pitWidth / 6}
fontSize={pitWidth / 5} />
/> );
);
}; const createPitViewList = (pits: Pit[]) =>
const createPitViewList = (pits: Pit[]) => pits.map((pit, index) => createPitView(index, pit, boardViewModel.pits[pit.index])); pits.map((pit, index) => createPitView(index, pit, boardViewModel.pits[pit.index]));
const player1Pits = createPitViewList(mancalaGame?.board.player1Pits); const player1Pits = createPitViewList(mancalaGame?.board.player1Pits);
const player2Pits = createPitViewList(mancalaGame?.board.player2Pits); const player2Pits = createPitViewList(mancalaGame?.board.player2Pits);
@ -40,6 +40,7 @@ const BoardView: FunctionComponent<{
const player2BankIndex = mancalaGame?.board.player2BankIndex(); const player2BankIndex = mancalaGame?.board.player2BankIndex();
const player1BankViewModel = boardViewModel.pits[player1BankIndex]; const player1BankViewModel = boardViewModel.pits[player1BankIndex];
const player2BankViewModel = boardViewModel.pits[player2BankIndex]; const player2BankViewModel = boardViewModel.pits[player2BankIndex];
return ( return (
<div className="board" style={{ background: theme.boardColor }}> <div className="board" style={{ background: theme.boardColor }}>
<StoreView <StoreView

View File

@ -1,66 +1,83 @@
import * as React from "react"; import * as React from "react";
import { FunctionComponent } from "react"; import { FunctionComponent } from "react";
import Util from "../../util/Util"; import { getColorByBrightness, PitViewModel } from "@mancala/core";
import { PitViewModel, getColorByBrightness } from "@mancala/core";
import { Context } from "../../context/context"; import { Context } from "../../context/context";
import Util from "../../util/Util";
import StoneView from "./StoneView"; import StoneView from "./StoneView";
const PitView: FunctionComponent<{ interface PitViewProps {
pitViewModel: PitViewModel; pitViewModel: PitViewModel;
context: Context; context: Context;
onClick: () => void; onClick: () => void;
fontSize: number; fontSize: number;
}> = ({ pitViewModel, context, onClick, fontSize }) => { }
const stones = [...Util.range(pitViewModel.stoneCount)].map((i, index) => (
<StoneView key={index} color={pitViewModel.stoneColor} /> const PitView: FunctionComponent<PitViewProps> = ({ pitViewModel, context, onClick, fontSize }) => {
)); const textColor = getColorByBrightness(
const textColor = getColorByBrightness( pitViewModel.pitColor,
pitViewModel.pitColor, context.themeManager.theme.textColor,
context.themeManager.theme.textColor, context.themeManager.theme.textLightColor
context.themeManager.theme.textLightColor );
);
return ( const stones = [...Util.range(pitViewModel.stoneCount)].map((i, index) => (
<div <StoneView key={index} color={pitViewModel.stoneColor} />
className="pit" ));
onClick={onClick}
style={{ return (
background: pitViewModel.pitColor, <div
position: "relative", className="pit"
}} onClick={onClick}
style={{
background: pitViewModel.pitColor,
position: "relative",
}}
>
{stones}
{pitViewModel.stoneCount > 0 && (
<span
className="stone-count"
style={{
color: textColor,
position: "absolute",
bottom: fontSize / 2,
left: "50%",
transform: "translateX(-50%)",
fontFamily: "monospace",
fontWeight: "bold",
fontSize: fontSize,
pointerEvents: "none",
}}
> >
{stones} {pitViewModel.stoneCount}
{pitViewModel.stoneCount > 0 && ( </span>
<span )}
style={{ <style jsx>{`
color: textColor, .pit {
position: "absolute", margin: 5px;
bottom: fontSize / 2, padding: 5px;
left: "50%", border-radius: 10vw;
transform: "translateX(-50%)", transition: background-color 0.5s;
fontFamily: "monospace", display: flex;
fontWeight: "bold", align-items: center;
fontSize: fontSize, align-content: center;
}} justify-content: center;
> justify-items: center;
{pitViewModel.stoneCount} flex-wrap: wrap;
</span> position: relative;
)} }
<style jsx>{` .stone-count {
.pit { position: absolute;
margin: 5px; bottom: 1.0vw;
padding: 5px; left: 50%;
border-radius: 10vw; transform: translateX(-50%);
transition: background-color 0.5s; font-family: monospace;
display: flex; font-size: 1.5vw;
align-items: center; font-weight: bold;
align-content: center; pointer-events: none;
justify-content: center; }
justify-items: center; `}</style>
flex-wrap: wrap; </div>
} );
`}</style>
</div>
);
}; };
export default PitView; export default PitView;

View File

@ -2019,10 +2019,10 @@ uuid@^10.0.0:
resolved "https://registry.yarnpkg.com/uuid/-/uuid-10.0.0.tgz#5a95aa454e6e002725c79055fd42aaba30ca6294" resolved "https://registry.yarnpkg.com/uuid/-/uuid-10.0.0.tgz#5a95aa454e6e002725c79055fd42aaba30ca6294"
integrity sha512-8XkAphELsDnEGrDxUOHB3RGvXz6TeuYSGEZBOjtTtPm2lwhGBjLgOzLHB63IUWfBpNucQjND6d3AOudO+H3RWQ== integrity sha512-8XkAphELsDnEGrDxUOHB3RGvXz6TeuYSGEZBOjtTtPm2lwhGBjLgOzLHB63IUWfBpNucQjND6d3AOudO+H3RWQ==
uuid@^8.3.2: uuid@^11.0.3:
version "8.3.2" version "11.1.1"
resolved "https://registry.yarnpkg.com/uuid/-/uuid-8.3.2.tgz#80d5b5ced271bb9af6c445f21a1a04c606cefbe2" resolved "https://registry.yarnpkg.com/uuid/-/uuid-11.1.1.tgz#f6d81d2e1c65d00762e5e29b16c5d2d995e208ad"
integrity sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg== integrity sha512-vIYxrBCC/N/K+Js3qSN88go7kIfNPssr/hHCesKCQNAjmgvYS2oqr69kIufEG+O4+PfezOH4EbIeHCfFov8ZgQ==
v8-compile-cache@^2.0.0: v8-compile-cache@^2.0.0:
version "2.3.0" version "2.3.0"

View File

@ -17,9 +17,9 @@ const BoardView: FunctionComponent<{
boardViewModel: BoardViewModel; boardViewModel: BoardViewModel;
revert: boolean; revert: boolean;
onPitSelect: (index: number, pit: Pit) => void; 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 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 boardMargin = 0;
const boardPadding = 10; const boardPadding = 10;
@ -33,19 +33,22 @@ const BoardView: FunctionComponent<{
const createPitView = (key: any, pit: Pit, pitViewModel: PitViewModel) => { const createPitView = (key: any, pit: Pit, pitViewModel: PitViewModel) => {
const stones = [...Util.range(pitViewModel.stoneCount)].map((i, index) => ( const stones = [...Util.range(pitViewModel.stoneCount)].map((i, index) => (
<StoneView key={index} color={pitViewModel.stoneColor} style={{width: pitWidth / 10, height: pitWidth / 10}}/> <StoneView key={index} color={pitViewModel.stoneColor} style={{ width: pitWidth / 10, height: pitWidth / 10 }} />
)); ));
return <PitView return (
key={key} <PitView
pitViewModel={pitViewModel} key={key}
context={context} pitViewModel={pitViewModel}
onClick={() => onPitSelect(pit.index, pit)} context={context}
style={{width: pitWidth, height: pitWidth}} onClick={() => onPitSelect(pit.index, pit)}
fontSize={pitWidth / 5} style={{ width: pitWidth, height: pitWidth }}
> fontSize={pitWidth / 5} // keep original divisor as per revert request
{stones} >
</PitView>; {stones}
</PitView>
);
}; };
const createPitViewList = (pits: Pit[]) => pits.map((pit, index) => createPitView(index, pit, boardViewModel.pits[pit.index])); const createPitViewList = (pits: Pit[]) => pits.map((pit, index) => createPitView(index, pit, boardViewModel.pits[pit.index]));
const player1Pits = createPitViewList(mancalaGame?.board.player1Pits); const player1Pits = createPitViewList(mancalaGame?.board.player1Pits);
@ -57,52 +60,60 @@ const BoardView: FunctionComponent<{
const primaryStoreViewModel = revert ? player1BankViewModel : player2BankViewModel; const primaryStoreViewModel = revert ? player1BankViewModel : player2BankViewModel;
const secondaryStoreViewModel = revert ? player2BankViewModel : player1BankViewModel; const secondaryStoreViewModel = revert ? player2BankViewModel : player1BankViewModel;
const stonesPrimaryStore = [...Util.range(primaryStoreViewModel.stoneCount)].map((i, index) => ( const stonesPrimaryStore = [...Util.range(primaryStoreViewModel.stoneCount)].map((i, index) => (
<StoneView key={index} color={primaryStoreViewModel.stoneColor} style={{width: pitWidth / 10, height: pitWidth / 10}}/> <StoneView key={index} color={primaryStoreViewModel.stoneColor} style={{ width: pitWidth / 10, height: pitWidth / 10 }} />
)); ));
const stonesSecondaryStore = [...Util.range(secondaryStoreViewModel.stoneCount)].map((i, index) => ( const stonesSecondaryStore = [...Util.range(secondaryStoreViewModel.stoneCount)].map((i, index) => (
<StoneView key={index} color={secondaryStoreViewModel.stoneColor} style={{width: pitWidth / 10, height: pitWidth / 10}} /> <StoneView key={index} color={secondaryStoreViewModel.stoneColor} style={{ width: pitWidth / 10, height: pitWidth / 10 }} />
)); ));
return ( return (
<View style={{ <View
backgroundColor: theme.boardColor, style={{
padding: boardPadding, backgroundColor: theme.boardColor,
borderRadius: 20, padding: boardPadding,
flexDirection: "row", borderRadius: 20,
gap: gap, flexDirection: "row",
height: "auto", gap: gap,
}}> height: "auto",
}}
>
<StoreView <StoreView
context={context} context={context}
pitViewModel={primaryStoreViewModel} pitViewModel={primaryStoreViewModel}
style={{width: pitWidth, height: pitWidth * 2 + gap}} style={{ width: pitWidth, height: pitWidth * 2 + gap }}
fontSize={pitWidth / 5} fontSize={pitWidth / 5}
> >
{stonesPrimaryStore} {stonesPrimaryStore}
</StoreView> </StoreView>
<View style={{flex: 6}}> <View style={{ flex: 6 }}>
<View style={{ <View
flexDirection: "row", style={{
width: '100%', flexDirection: "row",
flex: 1, width: "100%",
gap: gap flex: 1,
}}> gap: gap,
}}
>
{revert ? player1Pits?.reverse() : player2Pits?.reverse()} {revert ? player1Pits?.reverse() : player2Pits?.reverse()}
</View> </View>
<View style={{ <View
flexDirection: "row", style={{
width: '100%', flexDirection: "row",
flex: 1, width: "100%",
gap: gap flex: 1,
}}> gap: gap,
}}
>
{revert ? player2Pits : player1Pits} {revert ? player2Pits : player1Pits}
</View> </View>
</View> </View>
<StoreView <StoreView
context={context} context={context}
pitViewModel={secondaryStoreViewModel} pitViewModel={secondaryStoreViewModel}
style={{width: pitWidth, height: pitWidth * 2 + gap}} style={{ width: pitWidth, height: pitWidth * 2 + gap }}
fontSize={pitWidth / 5} fontSize={pitWidth / 5}
> >
{stonesSecondaryStore} {stonesSecondaryStore}

View File

@ -3,50 +3,50 @@ import { FunctionComponent } from "react";
import { PitViewModel, getColorByBrightness } from "@mancala/core"; import { PitViewModel, getColorByBrightness } from "@mancala/core";
import { Context } from "../../context/context"; import { Context } from "../../context/context";
import { Pressable, View, ViewStyle, Text } from "react-native"; import { Pressable, View, ViewStyle, Text } from "react-native";
import Util from "../../util/Util";
import StoneView from "./StoneView";
const PitView: FunctionComponent<{ interface PitViewProps {
pitViewModel: PitViewModel; pitViewModel: PitViewModel;
context: Context; context: Context;
onClick: () => void; onClick: () => void;
style: ViewStyle, style: ViewStyle;
fontSize: number; fontSize: number;
children: React.ReactNode }
}> = ({ pitViewModel, context, onClick, style, fontSize, children }) => {
const textColor = getColorByBrightness( const PitView: FunctionComponent<PitViewProps> = ({ pitViewModel, context, onClick, style, fontSize }) => {
pitViewModel.pitColor, const textColor = getColorByBrightness(
context.themeManager.theme.textColor, pitViewModel.pitColor,
context.themeManager.theme.textLightColor context.themeManager.theme.textColor,
); context.themeManager.theme.textLightColor
return ( );
<View style={[style, { backgroundColor: pitViewModel.pitColor, borderRadius: 100, position: 'relative' }] }>
<Pressable onPress={onClick} style={{ const stones = [...Util.range(pitViewModel.stoneCount)].map((i, index) => (
width: "100%", <StoneView key={index} color={pitViewModel.stoneColor} style={{ width: style.width ? style.width / 10 : 10, height: style.width ? style.width / 10 : 10 }} />
height: "100%", ));
padding: 5,
display: 'flex', return (
alignItems: 'center', <View style={[style, { backgroundColor: pitViewModel.pitColor, borderRadius: 100, position: "relative" }] }>
alignContent: 'center', <Pressable onPress={onClick} style={{ width: "100%", height: "100%", padding: 5, display: "flex", alignItems: "center", alignContent: "center", justifyContent: "center", flexDirection: "row", flexWrap: "wrap" }}>
justifyContent: 'center', {stones}
flexDirection: "row", </Pressable>
flexWrap: "wrap" {pitViewModel.stoneCount > 0 && (
}}> <Text
{children} style={{
</Pressable> color: textColor,
{pitViewModel.stoneCount > 0 && ( position: "absolute",
<Text style={{ bottom: fontSize / 2,
color: textColor, alignSelf: "center",
position: 'absolute', fontFamily: "monospace",
bottom: fontSize / 2, fontWeight: "bold",
alignSelf: 'center', fontSize: fontSize,
fontFamily: 'monospace', }}
fontWeight: 'bold', >
fontSize: fontSize {pitViewModel.stoneCount}
}}> </Text>
{pitViewModel.stoneCount} )}
</Text> </View>
)} );
</View>
);
}; };
export default PitView; export default PitView;