1
1
// @flow
2
2
3
3
import type { Move , Coordinate } from 'go-lib'
4
+ import { BLACK } from '../../constants'
4
5
5
6
const LINE_WIDTH_FACTOR = 20
6
7
const FONT_SIZE_FACTOR = 2.5
@@ -84,17 +85,19 @@ class BoardDrawer {
84
85
ctx . lineWidth = lineWidth * 2
85
86
86
87
moves . forEach ( ( move , index ) => {
88
+ const moveX = move . coordinate . x + 1
89
+ const moveY = move . coordinate . y + 1
87
90
const isLastMove = index === moves . length - 1
88
- const fillStyle = move . color === 'B'
91
+ const fillStyle = move . color === BLACK
89
92
? colorBlack ( opacity )
90
93
: colorWhite ( opacity )
91
94
92
95
// Draw stone
93
96
ctx . fillStyle = fillStyle
94
97
ctx . beginPath ( )
95
98
ctx . arc (
96
- move . coordinate . x * boxSize ,
97
- move . coordinate . y * boxSize ,
99
+ moveX * boxSize ,
100
+ moveY * boxSize ,
98
101
boxSize / 2 - lineWidth ,
99
102
0 ,
100
103
2 * Math . PI ,
@@ -106,20 +109,14 @@ class BoardDrawer {
106
109
107
110
// Mark last move
108
111
if ( isLastMove && ! isHover ) {
109
- const strokeStyle = move . color === 'B'
112
+ const strokeStyle = move . color === BLACK
110
113
? colorWhite ( opacity )
111
114
: colorBlack ( opacity )
112
115
113
116
ctx . beginPath ( )
114
117
ctx . strokeStyle = strokeStyle
115
118
ctx . lineWidth = lineWidth
116
- ctx . arc (
117
- move . coordinate . x * boxSize ,
118
- move . coordinate . y * boxSize ,
119
- boxSize / 3.5 ,
120
- 0 ,
121
- 2 * Math . PI ,
122
- )
119
+ ctx . arc ( moveX * boxSize , moveY * boxSize , boxSize / 3.5 , 0 , 2 * Math . PI )
123
120
ctx . stroke ( )
124
121
}
125
122
} )
@@ -196,8 +193,8 @@ class BoardDrawer {
196
193
197
194
// calculateCoordinateFromMousePosition convert's a canvas mouse position to a board coordinate
198
195
calculateCoordinateFromMousePosition ( mousePosition : Coordinate ) : Coordinate {
199
- const x = Math . round ( mousePosition . x / this . boxSize )
200
- const y = Math . round ( mousePosition . y / this . boxSize )
196
+ const x = Math . round ( mousePosition . x / this . boxSize ) - 1
197
+ const y = Math . round ( mousePosition . y / this . boxSize ) - 1
201
198
202
199
return { x, y }
203
200
}
0 commit comments