2022-07-14 08:53:26 +03:00
|
|
|
import * as React from "react";
|
|
|
|
|
import { FunctionComponent } from "react";
|
2026-05-26 00:31:59 +03:00
|
|
|
import { getColorByBrightness } from "@mancala/core";
|
|
|
|
|
import { Context } from "../../context/context";
|
2022-07-14 08:53:26 +03:00
|
|
|
import Util from "../../util/Util";
|
2024-06-18 00:24:45 +03:00
|
|
|
import { PitViewModel } from "@mancala/core";
|
2022-07-14 08:53:26 +03:00
|
|
|
import StoneView from "./StoneView";
|
|
|
|
|
|
|
|
|
|
const PitView: FunctionComponent<{
|
|
|
|
|
pitViewModel: PitViewModel;
|
|
|
|
|
onClick: () => void;
|
2026-05-26 00:31:59 +03:00
|
|
|
context: Context;
|
|
|
|
|
}> = ({ pitViewModel, onClick, context }) => {
|
|
|
|
|
const textColor = getColorByBrightness(
|
|
|
|
|
pitViewModel.pitColor,
|
|
|
|
|
context.themeManager.theme.textColor,
|
|
|
|
|
context.themeManager.theme.textLightColor
|
|
|
|
|
);
|
2022-07-14 08:53:26 +03:00
|
|
|
const stones = [...Util.range(pitViewModel.stoneCount)].map((i, index) => (
|
|
|
|
|
<StoneView key={index} color={pitViewModel.stoneColor} />
|
|
|
|
|
));
|
|
|
|
|
|
|
|
|
|
return (
|
2022-07-14 23:17:34 +03:00
|
|
|
<div className="pit" onClick={onClick} style={{ background: pitViewModel.pitColor }}>
|
2022-07-14 08:53:26 +03:00
|
|
|
{stones}
|
2026-05-26 00:31:59 +03:00
|
|
|
<span className="stone-count">{pitViewModel.stoneCount}</span>
|
2022-07-14 23:17:34 +03:00
|
|
|
<style jsx>{`
|
|
|
|
|
.pit {
|
|
|
|
|
margin: 5px;
|
|
|
|
|
padding: 5px;
|
|
|
|
|
border-radius: 10vw;
|
|
|
|
|
transition: background-color 0.5s;
|
|
|
|
|
display: flex;
|
|
|
|
|
align-items: center;
|
|
|
|
|
align-content: center;
|
|
|
|
|
justify-content: center;
|
|
|
|
|
justify-items: center;
|
|
|
|
|
flex-wrap: wrap;
|
2026-05-26 00:31:59 +03:00
|
|
|
position: relative;
|
|
|
|
|
}
|
|
|
|
|
.stone-count {
|
|
|
|
|
position: absolute;
|
|
|
|
|
bottom: 1.0vw;
|
|
|
|
|
left: 50%;
|
|
|
|
|
transform: translateX(-50%);
|
|
|
|
|
font-family: monospace;
|
|
|
|
|
font-size: 1.5vw;
|
|
|
|
|
font-weight: bold;
|
|
|
|
|
color: ${textColor};
|
|
|
|
|
|
|
|
|
|
pointer-events: none;
|
2022-07-14 23:17:34 +03:00
|
|
|
}
|
|
|
|
|
`}</style>
|
2022-07-14 08:53:26 +03:00
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default PitView;
|