@@ -12,13 +12,14 @@ local function table_has(table, value)
1212 return false
1313end
1414
15- function model :load (map )
16- self .map = map
15+ function model :load (mapName )
16+ self .mapName = mapName
17+ self .map = dofile (' data/maps/' .. mapName .. ' .lua' )
1718 self .map .positions .user = {unpack (self .map .positions .start )}
1819end
1920
2021function model :reset ()
21- self . map . positions . user = { unpack (self .map . positions . start )}
22+ self : load (self .mapName )
2223end
2324
2425function model :getSize ()
@@ -34,21 +35,46 @@ function model:getTile(x, y)
3435end
3536
3637function model :setTile (x , y , tile )
37- if self .map .components [tile ] then
38+ if self : isTileOnMap ( x , y ) and self .map .components [tile ] then
3839 self .map .data [y ][x ] = tile
3940 else
4041 error (' No component for tile id "' .. tile .. ' "' )
4142 end
4243end
4344
44- function model :isTileMovable (x , y )
45+ function model :isTileOnMap (x , y )
4546 return (x > 0 and y > 0
4647 and x <= self .map .size .width
47- and y <= self .map .size .height
48+ and y <= self .map .size .height )
49+ end
50+
51+ function model :isTileMovable (x , y )
52+ return (self :isTileOnMap (x , y )
4853 and table_has ({' grass' , ' exit' },
4954 self :getComponent (self :getTile (x , y ))))
5055end
5156
57+ function model :isTileBreakable (x , y )
58+ return (self :isTileOnMap (x , y )
59+ and table_has ({' box_closed' },
60+ self :getComponent (self :getTile (x , y ))))
61+ end
62+
63+ function model :hasArtifact (x , y )
64+ return (self .isTileOnMap (x , y ) and self .map .artifacts [y ][x ])
65+ end
66+
67+ function model :getArtifact (x , y )
68+ if self :isTileOnMap (x , y ) then
69+ if self .map .artifacts [y ] and self .map .artifacts [y ][x ] then
70+ return self .map .artifacts [y ][x ]
71+ else
72+ return self .map .artifacts .default
73+ end
74+ end
75+ return nil
76+ end
77+
5278function model :getComponent (id )
5379 return self .map .components [id ]
5480end
0 commit comments