Skip to content

Commit 3d33773

Browse files
committed
refactor / rename
1 parent 655c3ef commit 3d33773

File tree

5 files changed

+181
-171
lines changed

5 files changed

+181
-171
lines changed

src/main/client/src/Router.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import {
2525
} from "./Lobby.jsx"
2626
import {
2727
Game,
28-
} from "./Game.jsx"
28+
} from "./feature/game/Game.jsx"
2929
import {
3030
base,
3131
StompContext,

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

Lines changed: 15 additions & 165 deletions
Original file line numberDiff line numberDiff line change
@@ -14,28 +14,26 @@ import {
1414
base,
1515
StompContext,
1616
BLACK,
17-
TERRITORY,
18-
TERRITORY_B,
19-
REMOVED_B,
20-
ANY_REMOVED,
2117
tfetch,
2218
doTry,
23-
} from "./util.js"
19+
} from "../../util.js"
2420
import {
2521
PointList,
26-
} from "./model/PointList.js"
27-
import {
28-
GamePanel,
29-
} from "./feature/GamePanel.jsx"
22+
} from "../../model/PointList.js"
3023
import {
3124
useAuthStore,
3225
useGameStore,
33-
} from "./store.js"
34-
35-
const kirsch = "#dfbd6d"
36-
const asch = "#8c7130"
37-
const TAU = 2 * Math.PI
38-
const decoX = ["A", "B", "C", "D", "E", "F", "G", "H", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T"]
26+
} from "../../store.js"
27+
import {
28+
paintShadow,
29+
paintGrid,
30+
paintBoardDecorations,
31+
paintStones,
32+
paintStonesCounting,
33+
} from "./paint.js"
34+
import {
35+
GamePanel,
36+
} from "./GamePanel.jsx"
3937

4038
export const Game = () => {
4139
let [cursor_x, setCursor_x] = useState(-1)
@@ -215,7 +213,7 @@ export const Game = () => {
215213
let style = currentColor() === BLACK ?
216214
"rgba(0,0,0,0.25)" :
217215
"rgba(255,255,255,0.25)"
218-
showShadow(context, cursor_x, cursor_y, style)
216+
paintShadow(context, cursor_x, cursor_y, style)
219217
}, [cursor_x, cursor_y, context, canvasRef, auth, currentColor, board, currentPlayer, counting, countingGroup, forbidden_x, forbidden_y, lastMove])
220218

221219
useEffect(() => {
@@ -262,106 +260,6 @@ export const Game = () => {
262260
)
263261
}
264262

265-
function showTerritory({ canvasRef, grid, territoryRadius }, grid_x, grid_y, style) {
266-
let [x, y] = grid[grid_y][grid_x]
267-
let ctx = canvasRef.current.getContext("2d")
268-
ctx.fillStyle = style
269-
ctx.beginPath()
270-
ctx.arc(x, y, territoryRadius, 0, TAU)
271-
ctx.fill()
272-
}
273-
274-
function showStone({ canvasRef, grid, stoneRadius }, grid_x, grid_y, style) {
275-
let [x, y] = grid[grid_y][grid_x]
276-
let ctx = canvasRef.current.getContext("2d")
277-
ctx.fillStyle = style
278-
ctx.beginPath()
279-
ctx.arc(x, y, stoneRadius, 0, TAU)
280-
ctx.fill()
281-
}
282-
283-
function paintLastMove({isCursorInBounds, canvasRef, grid, stoneRadius}, lastMove) {
284-
if (!lastMove) {
285-
return
286-
}
287-
let {x: grid_x, y: grid_y, color} = lastMove
288-
if (!isCursorInBounds(grid_x, grid_y)) {
289-
return
290-
}
291-
let style = color === BLACK ?
292-
"rgba(255,255,255)" :
293-
"rgba(0,0,0)"
294-
let [x, y] = grid[grid_y][grid_x]
295-
let ctx = canvasRef.current.getContext("2d")
296-
let length = stoneRadius * 0.875
297-
ctx.fillStyle = style
298-
ctx.beginPath()
299-
ctx.moveTo(x, y)
300-
ctx.lineTo(x + length, y)
301-
ctx.lineTo(x , y + length)
302-
ctx.fill()
303-
}
304-
305-
function showShadow({ canvasRef, grid, stoneRadius }, grid_x, grid_y, style) {
306-
let [x, y] = grid[grid_y][grid_x]
307-
let ctx = canvasRef.current.getContext("2d")
308-
ctx.fillStyle = style
309-
ctx.beginPath()
310-
ctx.arc(x, y, stoneRadius, 0, TAU)
311-
ctx.fill()
312-
}
313-
314-
function paintGrid({width, margin, canvasRef, grid, hoshis, hoshiRadius, boardDecorations}) {
315-
let ctx = canvasRef.current.getContext("2d")
316-
ctx.fillStyle = kirsch
317-
if (boardDecorations) {
318-
ctx.fillRect(0.625 * margin, 0.625 * margin, width - 1.25 * margin, width - 1.25 * margin)
319-
} else {
320-
ctx.fillRect(0, 0, width, width)
321-
}
322-
ctx.strokeStyle = asch
323-
for (let y = 0; y < grid.length; y++) {
324-
let [source_x, source_y] = grid[y][0]
325-
let [target_x, target_y] = grid[y][grid.length - 1]
326-
ctx.beginPath()
327-
ctx.moveTo(source_x, source_y)
328-
ctx.lineTo(target_x, target_y)
329-
ctx.stroke()
330-
}
331-
for (let x = 0; x < grid.length; x++) {
332-
let [source_x, source_y] = grid[0][x]
333-
let [target_x, target_y] = grid[grid.length - 1][x]
334-
ctx.beginPath()
335-
ctx.moveTo(source_x, source_y)
336-
ctx.lineTo(target_x, target_y)
337-
ctx.stroke()
338-
}
339-
hoshis.forEach((grid_x, grid_y) => {
340-
let [x, y] = grid[grid_y][grid_x]
341-
ctx.fillStyle = asch
342-
ctx.beginPath()
343-
ctx.arc(x, y, hoshiRadius, 0, TAU)
344-
ctx.fill()
345-
})
346-
}
347-
348-
function paintBoardDecorations({width, margin, canvasRef, grid}) {
349-
let ctx = canvasRef.current.getContext("2d")
350-
ctx.fillStyle = kirsch
351-
ctx.fillRect(0, 0, width, width)
352-
ctx.fillStyle = asch
353-
for (let grid_x = 0; grid_x < grid.length; grid_x++) {
354-
let [x] = grid[0][grid_x]
355-
ctx.fillText(decoX[grid_x], x, 0.25 * margin)
356-
ctx.fillText(decoX[grid_x], x, width - 0.25 * margin)
357-
}
358-
for (let grid_y = 0; grid_y < grid.length; grid_y++) {
359-
let [, y] = grid[grid.length - grid_y - 1][0]
360-
ctx.fillText(grid_y + 1, 0.25 * margin, y)
361-
ctx.fillText(grid_y + 1, width - 0.25 * margin, y)
362-
}
363-
}
364-
365263
function getRadius(radius) {
366264
let diameter = Math.trunc(2 * radius)
367265
if (diameter % 2 === 0) {
@@ -370,62 +268,14 @@ function getRadius(radius) {
370268
return diameter / 2
371269
}
372270

373-
function paintStones(context, board, lastMove) {
374-
for (let grid_y = 0; grid_y < board.length; grid_y++) {
375-
for (let grid_x = 0; grid_x < board.length; grid_x++) {
376-
let { hasStone, color } = board[grid_y][grid_x]
377-
if (hasStone) {
378-
let style = color === BLACK ?
379-
"rgba(0,0,0)" :
380-
"rgba(255,255,255)"
381-
showStone(context, grid_x, grid_y, style)
382-
}
383-
}
384-
}
385-
paintLastMove(context, lastMove)
386-
}
387-
388-
function paintStonesCounting(context, board, countingGroup) {
389-
for (let grid_y = 0; grid_y < board.length; grid_y++) {
390-
for (let grid_x = 0; grid_x < board.length; grid_x++) {
391-
let { hasStone, color } = board[grid_y][grid_x]
392-
if (hasStone) {
393-
if (countingGroup && countingGroup(grid_x, grid_y)) {
394-
let style = color & BLACK ?
395-
"rgba(0,0,0,0.25)" :
396-
"rgba(255,255,255,0.25)"
397-
showShadow(context, grid_x, grid_y, style)
398-
} else {
399-
let style = color & BLACK ?
400-
"rgba(0,0,0)" :
401-
"rgba(255,255,255)"
402-
showStone(context, grid_x, grid_y, style)
403-
}
404-
}
405-
if (color & ANY_REMOVED) {
406-
let style = (color & ANY_REMOVED) === REMOVED_B ?
407-
"rgba(0,0,0,0.25)" :
408-
"rgba(255,255,255,0.25)"
409-
showShadow(context, grid_x, grid_y, style)
410-
}
411-
if (color & TERRITORY) {
412-
let style = (color & TERRITORY) === TERRITORY_B ?
413-
"rgba(0,0,0)" :
414-
"rgba(255,255,255)"
415-
showTerritory(context, grid_x, grid_y, style)
416-
}
417-
}
418-
}
419-
}
420-
421271
function getCountingGroup(board, cursor_x, cursor_y) {
422272
if (cursor_x < 0 ||
423273
cursor_x >= board.length ||
424274
cursor_y < 0 ||
425275
cursor_y >= board.length ) {
426276
return undefined
427277
}
428-
let { has, hasStone } = board[cursor_y][cursor_x]
278+
let {has, hasStone} = board[cursor_y][cursor_x]
429279
if (!hasStone) {
430280
return undefined
431281
}

src/main/client/src/feature/GameChat.jsx renamed to src/main/client/src/feature/game/GameChat.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ import {
1010
} from "react-router-dom"
1111
import {
1212
useAuthStore,
13-
} from "./../store.js"
13+
} from "../../store.js"
1414
import {
1515
StompContext,
1616
tfetch,
1717
doTry,
18-
} from "./../util.js"
18+
} from "../../util.js"
1919

2020
export const GameChat = () => {
2121
let [messages, setMessages] = useState([])

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,14 @@ import {
2222
TERRITORY_B,
2323
TERRITORY_W,
2424
base,
25-
} from "../util.js"
25+
} from "../../util.js"
2626
import {
2727
Button,
28-
} from "../component/Button.jsx"
28+
} from "../../component/Button.jsx"
2929
import {
3030
useAuthStore,
3131
useGameStore,
32-
} from "../store.js"
32+
} from "../../store.js"
3333
import {
3434
GameChat,
3535
} from "./GameChat.jsx"

0 commit comments

Comments
 (0)