Compare commits
2 Commits
bb1c750080
...
c1d47601b4
| Author | SHA1 | Date | |
|---|---|---|---|
| c1d47601b4 | |||
| cffd206cc7 |
@ -14,12 +14,23 @@ 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 mancalaGame = game?.mancalaGame;
|
const mancalaGame = game?.mancalaGame;
|
||||||
const theme = context.themeManager.theme;
|
const theme = context.themeManager.theme;
|
||||||
|
|
||||||
|
// 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) => {
|
const createPitView = (key: any, pit: Pit, pitViewModel: PitViewModel) => {
|
||||||
return <PitView key={key} pitViewModel={pitViewModel} onClick={() => onPitSelect(pit.index, pit)} />;
|
return (
|
||||||
|
<PitView
|
||||||
|
key={key}
|
||||||
|
pitViewModel={pitViewModel}
|
||||||
|
context={context}
|
||||||
|
onClick={() => onPitSelect(pit.index, pit)}
|
||||||
|
fontSize={pitWidth / 5}
|
||||||
|
/>
|
||||||
|
);
|
||||||
};
|
};
|
||||||
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]));
|
||||||
|
|
||||||
@ -36,12 +47,14 @@ const BoardView: FunctionComponent<{
|
|||||||
pitViewModel={revert ? player2BankViewModel : player1BankViewModel}
|
pitViewModel={revert ? player2BankViewModel : player1BankViewModel}
|
||||||
gridColumn="8 / 9"
|
gridColumn="8 / 9"
|
||||||
gridRow="1 / 3"
|
gridRow="1 / 3"
|
||||||
|
fontSize={pitWidth / 6}
|
||||||
/>
|
/>
|
||||||
<StoreView
|
<StoreView
|
||||||
context={context}
|
context={context}
|
||||||
pitViewModel={revert ? player1BankViewModel : player2BankViewModel}
|
pitViewModel={revert ? player1BankViewModel : player2BankViewModel}
|
||||||
gridColumn="1 / 2"
|
gridColumn="1 / 2"
|
||||||
gridRow="1 / 3"
|
gridRow="1 / 3"
|
||||||
|
fontSize={pitWidth / 6}
|
||||||
/>
|
/>
|
||||||
{revert ? player1Pits?.reverse() : player2Pits?.reverse()}
|
{revert ? player1Pits?.reverse() : player2Pits?.reverse()}
|
||||||
{revert ? player2Pits : player1Pits}
|
{revert ? player2Pits : player1Pits}
|
||||||
|
|||||||
@ -1,20 +1,50 @@
|
|||||||
import * as React from "react";
|
import * as React from "react";
|
||||||
import { FunctionComponent } from "react";
|
import { FunctionComponent } from "react";
|
||||||
import Util from "../../util/Util";
|
import Util from "../../util/Util";
|
||||||
import { PitViewModel } from "@mancala/core";
|
import { PitViewModel, getColorByBrightness } from "@mancala/core";
|
||||||
|
import { Context } from "../../context/context";
|
||||||
import StoneView from "./StoneView";
|
import StoneView from "./StoneView";
|
||||||
|
|
||||||
const PitView: FunctionComponent<{
|
const PitView: FunctionComponent<{
|
||||||
pitViewModel: PitViewModel;
|
pitViewModel: PitViewModel;
|
||||||
|
context: Context;
|
||||||
onClick: () => void;
|
onClick: () => void;
|
||||||
}> = ({ pitViewModel, onClick }) => {
|
fontSize: number;
|
||||||
|
}> = ({ pitViewModel, context, onClick, fontSize }) => {
|
||||||
const stones = [...Util.range(pitViewModel.stoneCount)].map((i, index) => (
|
const stones = [...Util.range(pitViewModel.stoneCount)].map((i, index) => (
|
||||||
<StoneView key={index} color={pitViewModel.stoneColor} />
|
<StoneView key={index} color={pitViewModel.stoneColor} />
|
||||||
));
|
));
|
||||||
|
const textColor = getColorByBrightness(
|
||||||
|
pitViewModel.pitColor,
|
||||||
|
context.themeManager.theme.textColor,
|
||||||
|
context.themeManager.theme.textLightColor
|
||||||
|
);
|
||||||
return (
|
return (
|
||||||
<div className="pit" onClick={onClick} style={{ background: pitViewModel.pitColor }}>
|
<div
|
||||||
|
className="pit"
|
||||||
|
onClick={onClick}
|
||||||
|
style={{
|
||||||
|
background: pitViewModel.pitColor,
|
||||||
|
position: "relative",
|
||||||
|
}}
|
||||||
|
>
|
||||||
{stones}
|
{stones}
|
||||||
|
{pitViewModel.stoneCount > 0 && (
|
||||||
|
<span
|
||||||
|
style={{
|
||||||
|
color: textColor,
|
||||||
|
position: "absolute",
|
||||||
|
bottom: fontSize / 2,
|
||||||
|
left: "50%",
|
||||||
|
transform: "translateX(-50%)",
|
||||||
|
fontFamily: "monospace",
|
||||||
|
fontWeight: "bold",
|
||||||
|
fontSize: fontSize,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{pitViewModel.stoneCount}
|
||||||
|
</span>
|
||||||
|
)}
|
||||||
<style jsx>{`
|
<style jsx>{`
|
||||||
.pit {
|
.pit {
|
||||||
margin: 5px;
|
margin: 5px;
|
||||||
|
|||||||
@ -21,8 +21,8 @@
|
|||||||
"react-i18next": "^14.1.0",
|
"react-i18next": "^14.1.0",
|
||||||
"react-native": "0.82.1",
|
"react-native": "0.82.1",
|
||||||
"react-native-get-random-values": "^1.11.0",
|
"react-native-get-random-values": "^1.11.0",
|
||||||
"react-native-mmkv": "^4.0.0",
|
"react-native-mmkv": "^4.3.2",
|
||||||
"react-native-nitro-modules": "^0.31.6",
|
"react-native-nitro-modules": "^0.36.1",
|
||||||
"react-native-safe-area-context": "^5.5.2",
|
"react-native-safe-area-context": "^5.5.2",
|
||||||
"react-native-screens": "^4.18.0",
|
"react-native-screens": "^4.18.0",
|
||||||
"react-native-snackbar": "^2.6.2",
|
"react-native-snackbar": "^2.6.2",
|
||||||
|
|||||||
@ -38,8 +38,11 @@ const BoardView: FunctionComponent<{
|
|||||||
return <PitView
|
return <PitView
|
||||||
key={key}
|
key={key}
|
||||||
pitViewModel={pitViewModel}
|
pitViewModel={pitViewModel}
|
||||||
|
context={context}
|
||||||
onClick={() => onPitSelect(pit.index, pit)}
|
onClick={() => onPitSelect(pit.index, pit)}
|
||||||
style={{width: pitWidth, height: pitWidth}} >
|
style={{width: pitWidth, height: pitWidth}}
|
||||||
|
fontSize={pitWidth / 5}
|
||||||
|
>
|
||||||
{stones}
|
{stones}
|
||||||
</PitView>;
|
</PitView>;
|
||||||
};
|
};
|
||||||
|
|||||||
@ -1,20 +1,24 @@
|
|||||||
import * as React from "react";
|
import * as React from "react";
|
||||||
import { FunctionComponent } from "react";
|
import { FunctionComponent } from "react";
|
||||||
import { PitViewModel } from "@mancala/core";
|
import { PitViewModel, getColorByBrightness } from "@mancala/core";
|
||||||
import { Pressable, View, ViewStyle } from "react-native";
|
import { Context } from "../../context/context";
|
||||||
|
import { Pressable, View, ViewStyle, Text } from "react-native";
|
||||||
|
|
||||||
const PitView: FunctionComponent<{
|
const PitView: FunctionComponent<{
|
||||||
pitViewModel: PitViewModel;
|
pitViewModel: PitViewModel;
|
||||||
|
context: Context;
|
||||||
onClick: () => void;
|
onClick: () => void;
|
||||||
style: ViewStyle,
|
style: ViewStyle,
|
||||||
|
fontSize: number;
|
||||||
children: React.ReactNode
|
children: React.ReactNode
|
||||||
}> = ({ pitViewModel, onClick, style, children }) => {
|
}> = ({ pitViewModel, context, onClick, style, fontSize, children }) => {
|
||||||
|
const textColor = getColorByBrightness(
|
||||||
|
pitViewModel.pitColor,
|
||||||
|
context.themeManager.theme.textColor,
|
||||||
|
context.themeManager.theme.textLightColor
|
||||||
|
);
|
||||||
return (
|
return (
|
||||||
<View style={[style, {
|
<View style={[style, { backgroundColor: pitViewModel.pitColor, borderRadius: 100, position: 'relative' }] }>
|
||||||
backgroundColor: pitViewModel.pitColor,
|
|
||||||
borderRadius: 100,
|
|
||||||
//justifyItems: 'center',
|
|
||||||
}]}>
|
|
||||||
<Pressable onPress={onClick} style={{
|
<Pressable onPress={onClick} style={{
|
||||||
width: "100%",
|
width: "100%",
|
||||||
height: "100%",
|
height: "100%",
|
||||||
@ -28,8 +32,20 @@ const PitView: FunctionComponent<{
|
|||||||
}}>
|
}}>
|
||||||
{children}
|
{children}
|
||||||
</Pressable>
|
</Pressable>
|
||||||
|
{pitViewModel.stoneCount > 0 && (
|
||||||
|
<Text style={{
|
||||||
|
color: textColor,
|
||||||
|
position: 'absolute',
|
||||||
|
bottom: fontSize / 2,
|
||||||
|
alignSelf: 'center',
|
||||||
|
fontFamily: 'monospace',
|
||||||
|
fontWeight: 'bold',
|
||||||
|
fontSize: fontSize
|
||||||
|
}}>
|
||||||
|
{pitViewModel.stoneCount}
|
||||||
|
</Text>
|
||||||
|
)}
|
||||||
</View>
|
</View>
|
||||||
|
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
6715
apps/mobile/yarn.lock
Normal file
6715
apps/mobile/yarn.lock
Normal file
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user