@@ -66,7 +66,10 @@ export function paintBoardDecorations({width, margin, canvasRef, grid}) {
66
66
}
67
67
}
68
68
69
- export function paintShadow ( { canvasRef, grid, stoneRadius} , grid_x , grid_y , style ) {
69
+ export function paintShadow ( { canvasRef, grid, stoneRadius} , grid_x , grid_y , color ) {
70
+ let style = ( color & ( BLACK | REMOVED_B ) ) ?
71
+ "rgba(0,0,0,0.25)" :
72
+ "rgba(255,255,255,0.25)"
70
73
let [ x , y ] = grid [ grid_y ] [ grid_x ]
71
74
let ctx = canvasRef . current . getContext ( "2d" )
72
75
ctx . fillStyle = style
@@ -75,27 +78,33 @@ export function paintShadow({canvasRef, grid, stoneRadius}, grid_x, grid_y, styl
75
78
ctx . fill ( )
76
79
}
77
80
78
- export function paintStones ( context , board , lastMove ) {
79
- let showMoveNumbers = context . showMoveNumbersRef . current
81
+ export function paintStones ( context , board , showMoveNumbers ) {
82
+ let cursor_x = context . cursorXref . current
83
+ let cursor_y = context . cursorYref . current
80
84
for ( let grid_y = 0 ; grid_y < board . length ; grid_y ++ ) {
81
85
for ( let grid_x = 0 ; grid_x < board . length ; grid_x ++ ) {
82
- let { hasStone, color, n} = board [ grid_y ] [ grid_x ]
83
- if ( hasStone ) {
84
- let style = color === BLACK ?
85
- "rgba(0,0,0)" :
86
- "rgba(255,255,255)"
87
- paintStone ( context , grid_x , grid_y , style )
88
- if ( showMoveNumbers ) {
89
- let antiStyle = color === BLACK ?
90
- "rgba(255,255,255)" :
91
- "rgba(0,0,0)"
92
- paintMoveNumber ( context , grid_x , grid_y , antiStyle , n + 1 )
93
- }
86
+ let { hasStone, color} = board [ grid_y ] [ grid_x ]
87
+ if ( ! hasStone ) {
88
+ continue
89
+ }
90
+ if ( showMoveNumbers && grid_x === cursor_x && grid_y === cursor_y ) {
91
+ paintShadow ( context , grid_x , grid_y , color )
92
+ } else {
93
+ paintStone ( context , grid_x , grid_y , color )
94
94
}
95
95
}
96
96
}
97
- if ( ! showMoveNumbers ) {
98
- paintLastMove ( context , lastMove )
97
+ }
98
+
99
+ export function paintMoveNumbers ( context , board ) {
100
+ for ( let grid_y = 0 ; grid_y < board . length ; grid_y ++ ) {
101
+ for ( let grid_x = 0 ; grid_x < board . length ; grid_x ++ ) {
102
+ let { hasStone, color, n} = board [ grid_y ] [ grid_x ]
103
+ if ( ! hasStone ) {
104
+ continue
105
+ }
106
+ paintMoveNumber ( context , grid_x , grid_y , color , n + 1 )
107
+ }
99
108
}
100
109
}
101
110
@@ -105,22 +114,13 @@ export function paintStonesCounting(context, board, countingGroup) {
105
114
let { hasStone, color } = board [ grid_y ] [ grid_x ]
106
115
if ( hasStone ) {
107
116
if ( countingGroup && countingGroup ( grid_x , grid_y ) ) {
108
- let style = color & BLACK ?
109
- "rgba(0,0,0,0.25)" :
110
- "rgba(255,255,255,0.25)"
111
- paintShadow ( context , grid_x , grid_y , style )
117
+ paintShadow ( context , grid_x , grid_y , color )
112
118
} else {
113
- let style = color & BLACK ?
114
- "rgba(0,0,0)" :
115
- "rgba(255,255,255)"
116
- paintStone ( context , grid_x , grid_y , style )
119
+ paintStone ( context , grid_x , grid_y , color )
117
120
}
118
121
}
119
122
if ( color & ANY_REMOVED ) {
120
- let style = ( color & ANY_REMOVED ) === REMOVED_B ?
121
- "rgba(0,0,0,0.25)" :
122
- "rgba(255,255,255,0.25)"
123
- paintShadow ( context , grid_x , grid_y , style )
123
+ paintShadow ( context , grid_x , grid_y , color )
124
124
}
125
125
if ( color & TERRITORY ) {
126
126
let style = ( color & TERRITORY ) === TERRITORY_B ?
@@ -141,7 +141,10 @@ function paintTerritory({canvasRef, grid, territoryRadius}, grid_x, grid_y, styl
141
141
ctx . fill ( )
142
142
}
143
143
144
- function paintStone ( { canvasRef, grid, stoneRadius} , grid_x , grid_y , style ) {
144
+ function paintStone ( { canvasRef, grid, stoneRadius} , grid_x , grid_y , color ) {
145
+ let style = color === BLACK ?
146
+ "rgba(0,0,0)" :
147
+ "rgba(255,255,255)"
145
148
let [ x , y ] = grid [ grid_y ] [ grid_x ]
146
149
let ctx = canvasRef . current . getContext ( "2d" )
147
150
ctx . fillStyle = style
@@ -150,7 +153,10 @@ function paintStone({canvasRef, grid, stoneRadius}, grid_x, grid_y, style) {
150
153
ctx . fill ( )
151
154
}
152
155
153
- function paintMoveNumber ( { stoneRadius, canvasRef, grid} , grid_x , grid_y , style , n ) {
156
+ function paintMoveNumber ( { stoneRadius, canvasRef, grid} , grid_x , grid_y , color , n ) {
157
+ let style = color === BLACK ?
158
+ "rgba(255,255,255)" :
159
+ "rgba(0,0,0)"
154
160
let [ x , y ] = grid [ grid_y ] [ grid_x ]
155
161
let size = Math . trunc ( stoneRadius * 0.75 )
156
162
let ctx = canvasRef . current . getContext ( "2d" )
@@ -161,7 +167,7 @@ function paintMoveNumber({stoneRadius, canvasRef, grid}, grid_x, grid_y, style,
161
167
ctx . fillText ( n , x , y )
162
168
}
163
169
164
- function paintLastMove ( { isCursorInBounds, canvasRef, grid, stoneRadius} , lastMove ) {
170
+ export function paintLastMove ( { isCursorInBounds, canvasRef, grid, stoneRadius} , lastMove ) {
165
171
if ( ! lastMove ) {
166
172
return
167
173
}
0 commit comments