@@ -11,8 +11,10 @@ type MyTexture = PIXI.Texture;
11
11
12
12
type NeighborCount = 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 ;
13
13
14
- // todo rename to neighborcount
15
- function numberToValueNumber ( value : number ) : NeighborCount {
14
+ export function numberToNeighborCount (
15
+ value : number | null ,
16
+ ) : NeighborCount | null {
17
+ if ( value === null ) return value ;
16
18
assert ( value % 1 === 0 ) ;
17
19
assert ( value >= 0 ) ;
18
20
assert ( value <= 8 ) ;
@@ -21,17 +23,17 @@ function numberToValueNumber(value: number): NeighborCount {
21
23
}
22
24
23
25
export class CellSprite {
24
- private value : NeighborCount | null ;
26
+ public neighborCount : NeighborCount | null ;
25
27
private back : PIXI . Sprite ;
26
28
private front : PIXI . Sprite ;
27
29
28
30
public constructor (
29
31
cell : Cell ,
30
- value : number | null ,
32
+ neighborCount : NeighborCount | null ,
31
33
parent : PIXI . Container ,
32
34
playAnimation : boolean ,
33
35
) {
34
- this . value = value === null ? null : numberToValueNumber ( value ) ;
36
+ this . neighborCount = neighborCount ;
35
37
const cellTexture = this . getCellTexture ( cell ) ;
36
38
this . back = new PIXI . Sprite ( cellTexture . back ) ;
37
39
this . front = new PIXI . Sprite ( cellTexture . front ) ;
@@ -50,8 +52,6 @@ export class CellSprite {
50
52
this . front . y = y ;
51
53
this . back . x = x ;
52
54
this . back . y = y ;
53
- this . back . name = "bg" ;
54
- this . front . name = "fg" ;
55
55
this . back . zIndex = 1 ;
56
56
this . front . zIndex = 2 ;
57
57
parent . addChild ( this . back , this . front ) ;
@@ -80,20 +80,19 @@ export class CellSprite {
80
80
back : MyTexture ;
81
81
front : MyTexture ;
82
82
} {
83
- // todo create a getter, maybe call load every time
84
83
const textures = getTextures ( ) ;
85
84
86
- let back ;
87
- let front ;
85
+ let back : PIXI . Texture ;
86
+ let front : PIXI . Texture ;
88
87
89
88
if ( cell . isOpen ) {
90
89
back = textures . open ;
91
90
if ( cell . isMine ) front = textures . mineWrong ;
92
- else if ( this . value !== null && this . value > 0 )
93
- front = textures [ this . value as 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 ] ;
91
+ else if ( this . neighborCount !== null && this . neighborCount > 0 )
92
+ front = textures [ this . neighborCount as 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 ] ;
94
93
else front = PIXI . Texture . EMPTY ;
95
94
} else {
96
- back = textures . closed ;
95
+ back = PIXI . Texture . EMPTY ;
97
96
front = cell . isFlagged ? textures . flag : PIXI . Texture . EMPTY ;
98
97
}
99
98
0 commit comments