@@ -10,6 +10,7 @@ import { MazeState } from '../../models/maze';
10
10
import { SpaceState } from '../../models/space' ;
11
11
12
12
import './Maze.scss' ;
13
+ import { makeWall , makeEmpty } from '../../actions/mazeActions' ;
13
14
14
15
const CameraController = ( ) => {
15
16
const { camera, gl } = useThree ( ) ;
@@ -38,7 +39,9 @@ const CameraController = () => {
38
39
39
40
const populateMaze = (
40
41
mazeSize : { x : number ; y : number } ,
41
- mazeInfo : { [ key : number ] : SpaceState [ ] }
42
+ mazeInfo : { [ key : number ] : SpaceState [ ] } ,
43
+ makeWall : ( data : { x : number ; y : number } , type : string ) => void ,
44
+ makeEmpty : ( data : { x : number ; y : number } , type : string ) => void
42
45
) => {
43
46
console . log ( mazeInfo ) ;
44
47
let list = [ ] ;
@@ -49,15 +52,23 @@ const populateMaze = (
49
52
key ++ ;
50
53
console . log ( 'visited: ' + mazeInfo [ j ] [ i ] . visited ) ;
51
54
list . push (
52
- < Space type = { mazeInfo [ j ] [ i ] . type } visited = { mazeInfo [ j ] [ i ] . visited } path = { mazeInfo [ i ] [ j ] . path } position = { [ i , 0 , j ] } key = { key } />
55
+ < Space type = { mazeInfo [ j ] [ i ] . type } visited = { mazeInfo [ j ] [ i ] . visited } path = { mazeInfo [ i ] [ j ] . path } position = { [ i , 0 , j ] } key = { key }
56
+ onSetWall = { ( ) => makeWall ( { x :i , y :j } , "empty" ) }
57
+ onSetEmpty = { ( ) => makeEmpty ( { x :i , y :j } , "wall" ) }
58
+ />
53
59
) ;
54
60
}
55
61
}
56
62
57
63
return list ;
58
64
} ;
59
65
60
- const Maze : React . FC < MazeState > = props => {
66
+ interface Props extends MazeState {
67
+ makeWall : any ;
68
+ makeEmpty : any ;
69
+ }
70
+
71
+ const Maze : React . FC < Props > = props => {
61
72
const { mazeInfo } = props ;
62
73
const mazeSize = {
63
74
x : mazeInfo [ 0 ] . length ,
@@ -86,7 +97,7 @@ const Maze: React.FC<MazeState> = props => {
86
97
< planeBufferGeometry attach = "geometry" args = { [ 100 , 100 , 100 , 100 ] } />
87
98
< meshPhongMaterial attach = "material" wireframe = { true } color = { 'grey' } />
88
99
</ mesh >
89
- { populateMaze ( mazeSize , mazeInfo ) }
100
+ { populateMaze ( mazeSize , mazeInfo , props . makeWall , props . makeEmpty ) }
90
101
</ Canvas >
91
102
) ;
92
103
} ;
0 commit comments