Skip to content

Commit 1212eeb

Browse files
committed
fix a reload issue
1 parent 51a0ab4 commit 1212eeb

File tree

3 files changed

+13
-12
lines changed

3 files changed

+13
-12
lines changed

src/main/client/src/Game.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ export const Game = () => {
166166
y: cursor_y,
167167
}),
168168
})
169-
}, [context, currentPlayer, currentColor, auth, board, gameId, stompClient, counting, forbidden_x, forbidden_y, gameHasEnded])
169+
}, [context, currentPlayer, currentColor, auth, board, stompClient, counting, forbidden_x, forbidden_y, gameHasEnded, movesLength])
170170

171171
useEffect(() => {
172172
if (!board.length) {

src/main/client/src/feature/GamePanel.jsx

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import {
33
useContext,
44
} from "react"
55
import {
6-
useParams,
76
useNavigate,
87
} from "react-router-dom"
98
import {
@@ -46,11 +45,11 @@ export const GamePanel = ({zoom, setZoom}) => {
4645
}
4746

4847
function Panel({zoom, setZoom}) {
49-
let { gameId } = useParams()
5048
let stompClient = useContext(StompContext)
5149
let auth = useAuthStore(state => state.auth)
5250
let black = useGameStore(state => state.black)
5351
let white = useGameStore(state => state.white)
52+
let isSelfPlay = black === white
5453
let queueLength = useGameStore(state => state.queueLength)
5554
let movesLength = useGameStore(state => state.moves.length)
5655
let counting = useGameStore(state => state.counting)
@@ -71,7 +70,7 @@ function Panel({zoom, setZoom}) {
7170
action: "pass",
7271
}),
7372
})
74-
}, [stompClient, gameId, movesLength])
73+
}, [stompClient, movesLength])
7574
let onResetCounting = useCallback(() => {
7675
stompClient.publish({
7776
destination: "/app/game/move",
@@ -80,7 +79,7 @@ function Panel({zoom, setZoom}) {
8079
action: "resetCounting",
8180
}),
8281
})
83-
}, [stompClient, gameId, movesLength])
82+
}, [stompClient, movesLength])
8483
let onCountingAgree = useCallback(() => {
8584
setAgreeCounting(true)
8685
stompClient.publish({
@@ -90,7 +89,7 @@ function Panel({zoom, setZoom}) {
9089
action: "agreeCounting",
9190
}),
9291
})
93-
}, [stompClient, gameId, movesLength])
92+
}, [stompClient, movesLength, setAgreeCounting])
9493
if (!board.length) {
9594
return <span>Loading...</span>
9695
}
@@ -162,7 +161,7 @@ function Panel({zoom, setZoom}) {
162161
</div>
163162
<div className="flex-none">
164163
<Button
165-
disabled={agreeCounting || gameHasEnded || !countingComplete()}
164+
disabled={(!isSelfPlay && agreeCounting) || gameHasEnded || !countingComplete()}
166165
className="py-1 px-4"
167166
onClick={onCountingAgree}>
168167
OK

src/main/client/src/store.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -119,10 +119,6 @@ export const useGameStore = create((set, get) => ({
119119
state.gameState.gameHasEnded = true
120120
return
121121
}
122-
if (move.action === "agreeCounting") {
123-
return
124-
}
125-
state.agreeCounting = false
126122
let moves = get().moves
127123
let baseBoard = get().baseBoard
128124
if (move.n < moves.length) {
@@ -139,6 +135,9 @@ export const useGameStore = create((set, get) => ({
139135
}
140136
let [storedMove, updated, forbidden] = createMoveData(baseBoard, moves, move, counting, get().handicap)
141137
state.moves.push(storedMove)
138+
if (move.action !== "agreeCounting") {
139+
state.agreeCounting = false
140+
}
142141
state.lastMove = move.action === "pass" ? undefined : move
143142
state.baseBoard = updated
144143
state.gameState.board = rehydrate(updated)
@@ -167,7 +166,7 @@ export const useGameStore = create((set, get) => ({
167166
state.gameState.gameHasEnded = true
168167
break
169168
}
170-
if (move.pass) {
169+
if (move.action === "pass") {
171170
if (passes) {
172171
counting = true
173172
queueLength = move.n
@@ -201,6 +200,9 @@ export const useGameStore = create((set, get) => ({
201200

202201
function createMoveData(baseBoard, moves, colorlessMove, counting, handicap) {
203202
let move = {...colorlessMove, color: nextMoveColor(moves, handicap)}
203+
if (move.action === "agreeCounting") {
204+
return [move, baseBoard, [-1, -1]]
205+
}
204206
if (move.action === "pass" && moves.length && moves[moves.length - 1].action === "pass") {
205207
return [move, count(baseBoard), [-1, -1]]
206208
}

0 commit comments

Comments
 (0)