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