Skip to content

Commit c31e67d

Browse files
committed
some cleanup
1 parent 25b73e4 commit c31e67d

File tree

3 files changed

+10
-29
lines changed

3 files changed

+10
-29
lines changed

src/main/client/src/feature/game/Game.jsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ export const Game = () => {
5353
let currentPlayer = useGameStore(state => state.currentPlayer)
5454
let counting = useGameStore(state => state.counting)
5555
let currentColor = useGameStore(state => state.currentColor)
56-
let {board, forbidden: [forbidden_x, forbidden_y]} = useGameStore(state => state.gameState)
56+
let board = useGameStore(state => state.board)
57+
let [forbidden_x, forbidden_y] = useGameStore(state => state.forbidden)
5758
let canvasRef = useRef()
5859
let countingGroup = !gameHasEnded() && counting ? getCountingGroup(board, cursor_x, cursor_y) : undefined
5960

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

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ function Panel({zoom, setZoom}) {
5757
let gameHasEnded = useGameStore(state => state.gameHasEnded)
5858
let countingComplete = useGameStore(state => state.countingComplete)
5959
let currentPlayer = useGameStore(state => state.currentPlayer)
60-
let {board} = useGameStore(state => state.gameState)
60+
let board = useGameStore(state => state.board)
6161
let navigate = useNavigate()
6262
let onExit = useCallback(() => {
6363
navigate(base + "/lobby")
@@ -169,15 +169,7 @@ function Panel({zoom, setZoom}) {
169169
</>}
170170
{result && (
171171
<div className="flex-none">
172-
<div>
173-
{"w:" + result.w}
174-
</div>
175-
<div className="mt-2">
176-
{"b:" + result.b}
177-
</div>
178-
<div className="mt-2">
179-
Result: {(result.w > result.b ? "w+" : "b+") + Math.abs(result.b - result.w)}
180-
</div>
172+
{(result.w > result.b ? "W+" : "B+") + Math.abs(result.b - result.w)}
181173
</div>
182174
)}
183175
<GameChat />

src/main/client/src/store.js

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ export const useGameStore = create((set, get) => ({
6565
counting: false,
6666
queueLength: 0,
6767
lastMove: undefined,
68+
board: [],
69+
forbidden: [-1, -1],
6870
countingComplete: () => {
6971
if (!get().counting) {
7072
return false
@@ -121,20 +123,10 @@ export const useGameStore = create((set, get) => ({
121123
let move = moves[moves.length - 1]
122124
return move.action === "end"
123125
},
124-
setAgreeCounting: (agree) => {
125-
set(produce(state => {
126-
state.agreeCounting = agree
127-
}))
128-
},
129-
gameState: {
130-
board: [],
131-
forbidden: [-1, -1],
132-
},
133126
addMove: (move) => {
134127
set(produce(state => {
135128
if (move.action === "end") {
136129
state.moves.push(move)
137-
state.gameState.gameHasEnded = true
138130
return
139131
}
140132
let moves = get().moves
@@ -153,13 +145,10 @@ export const useGameStore = create((set, get) => ({
153145
}
154146
let [storedMove, updated, forbidden] = createMoveData(baseBoard, moves, move, counting, get().handicap)
155147
state.moves.push(storedMove)
156-
if (move.action !== "agreeCounting") {
157-
state.agreeCounting = false
158-
}
159148
state.lastMove = move.action === "pass" ? undefined : storedMove
160149
state.baseBoard = updated
161-
state.gameState.board = rehydrate(updated)
162-
state.gameState.forbidden = forbidden
150+
state.board = rehydrate(updated)
151+
state.forbidden = forbidden
163152
if (move.action === "pass" && moves.length && moves[moves.length - 1].action === "pass") {
164153
state.counting = true
165154
}
@@ -190,7 +179,6 @@ export const useGameStore = create((set, get) => ({
190179
for (let move of game.moves) {
191180
if (move.action === "end") {
192181
moves.push(move)
193-
state.gameState.gameHasEnded = true
194182
break
195183
}
196184
if (move.action === "pass") {
@@ -218,8 +206,8 @@ export const useGameStore = create((set, get) => ({
218206
state.dim = game.dim
219207
state.baseBoard = baseBoard
220208
state.moves = moves
221-
state.gameState.board = rehydrate(baseBoard)
222-
state.gameState.forbidden = forbidden
209+
state.board = rehydrate(baseBoard)
210+
state.forbidden = forbidden
223211
state.handicap = game.handicap
224212
state.queueLength = queueLength
225213
state.queueStatus = "up_to_date"

0 commit comments

Comments
 (0)