@@ -14,28 +14,26 @@ import {
14
14
base ,
15
15
StompContext ,
16
16
BLACK ,
17
- TERRITORY ,
18
- TERRITORY_B ,
19
- REMOVED_B ,
20
- ANY_REMOVED ,
21
17
tfetch ,
22
18
doTry ,
23
- } from "./util.js"
19
+ } from "../.. /util.js"
24
20
import {
25
21
PointList ,
26
- } from "./model/PointList.js"
27
- import {
28
- GamePanel ,
29
- } from "./feature/GamePanel.jsx"
22
+ } from "../../model/PointList.js"
30
23
import {
31
24
useAuthStore ,
32
25
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"
39
37
40
38
export const Game = ( ) => {
41
39
let [ cursor_x , setCursor_x ] = useState ( - 1 )
@@ -215,7 +213,7 @@ export const Game = () => {
215
213
let style = currentColor ( ) === BLACK ?
216
214
"rgba(0,0,0,0.25)" :
217
215
"rgba(255,255,255,0.25)"
218
- showShadow ( context , cursor_x , cursor_y , style )
216
+ paintShadow ( context , cursor_x , cursor_y , style )
219
217
} , [ cursor_x , cursor_y , context , canvasRef , auth , currentColor , board , currentPlayer , counting , countingGroup , forbidden_x , forbidden_y , lastMove ] )
220
218
221
219
useEffect ( ( ) => {
@@ -262,106 +260,6 @@ export const Game = () => {
262
260
)
263
261
}
264
262
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
-
365
263
function getRadius ( radius ) {
366
264
let diameter = Math . trunc ( 2 * radius )
367
265
if ( diameter % 2 === 0 ) {
@@ -370,62 +268,14 @@ function getRadius(radius) {
370
268
return diameter / 2
371
269
}
372
270
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
-
421
271
function getCountingGroup ( board , cursor_x , cursor_y ) {
422
272
if ( cursor_x < 0 ||
423
273
cursor_x >= board . length ||
424
274
cursor_y < 0 ||
425
275
cursor_y >= board . length ) {
426
276
return undefined
427
277
}
428
- let { has, hasStone } = board [ cursor_y ] [ cursor_x ]
278
+ let { has, hasStone} = board [ cursor_y ] [ cursor_x ]
429
279
if ( ! hasStone ) {
430
280
return undefined
431
281
}
0 commit comments