Skip to content

Commit

Permalink
Base the disable of the accept score button on the state of accepted
Browse files Browse the repository at this point in the history
  • Loading branch information
GreenAsJade committed Sep 12, 2024
1 parent 9eea67f commit b1f545c
Showing 1 changed file with 20 additions and 9 deletions.
29 changes: 20 additions & 9 deletions src/views/Game/PlayControls.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -157,13 +157,12 @@ export function PlayControls({
const [white_accepted, set_white_accepted] = React.useState(
stoneRemovalAccepted(goban, "white"),
);
const [stone_removal_string, set_stone_removal_string] = React.useState(
goban.engine.getStoneRemovalString(),
);

// Setup: when there's a new goban in play, we need to make sure we have the current
// state of acceptance captured
React.useEffect(() => {
const syncStoneRemovalAcceptance = () => {
if (goban.engine.phase === "stone removal") {
set_stone_removal_string(goban.engine.getStoneRemovalString());
set_black_accepted(stoneRemovalAccepted(goban, "black"));
set_white_accepted(stoneRemovalAccepted(goban, "white"));
}
Expand All @@ -176,6 +175,7 @@ export function PlayControls({
syncStoneRemovalAcceptance,
);
}, [goban]);

React.useEffect(() => {
const syncNeedsSealing = (locs?: JGOFSealingIntersection[]) => {
setNeedsSealing(locs);
Expand Down Expand Up @@ -222,12 +222,25 @@ export function PlayControls({
goban.off("stone-removal.auto-scoring-complete", onAutoScoringComplete);
};
}, [goban]);

/*
React.useEffect(() => {
setStoneRemovalAcceptDisabled(true);
const timeout = setTimeout(() => setStoneRemovalAcceptDisabled(false), 1500);
const timeout = setTimeout(() => {
console.log("setting false");
setStoneRemovalAcceptDisabled(false);
}, 1500);
return () => clearTimeout(timeout);
}, [stone_removal_string]);
*/

React.useEffect(() => {
const player_accepted =
goban.engine?.playerColor(user.id) === "black" ? black_accepted : white_accepted;

setStoneRemovalAcceptDisabled(player_accepted ?? false);
}, [black_accepted, white_accepted]);

const paused = usePaused(goban);
const show_undo_requested = useShowUndoRequested(goban);
Expand Down Expand Up @@ -302,13 +315,11 @@ export function PlayControls({
});
return false;
};
const onStoneRemovalAccept = () => {
const onStoneRemovalAccept = (): void => {
goban.acceptRemovedStones();
return false;
};
const onStoneRemovalAutoScore = () => {
const onStoneRemovalAutoScore = (): void => {
goban.performStoneRemovalAutoScoring();
return false;
};

const sse = engine.stalling_score_estimate;
Expand Down

0 comments on commit b1f545c

Please sign in to comment.