blob: 09b4099e4bcbfa4090bc5f0a5c0f74d864cef6f2 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
module Battlemap exposing (Battlemap, random, apply_to_tile, has_location)
import Array exposing (Array, set, get)
import Battlemap.Tile exposing (Tile, generate)
import Battlemap.Direction exposing (..)
import Battlemap.Location exposing (..)
type alias Battlemap =
{
width : Int,
height : Int,
content : (Array Tile)
}
random : Battlemap
random =
{
width = 6,
height = 6,
content = (generate 6 6)
}
location_to_index : Battlemap -> Location -> Int
location_to_index bmap loc =
((loc.y * bmap.width) + loc.x)
has_location : Battlemap -> Location -> Bool
has_location bmap loc =
(
(loc.x >= 0)
&& (loc.y >= 0)
&& (loc.x < bmap.width)
&& (loc.y < bmap.height)
)
apply_to_tile : Battlemap -> Location -> (Tile -> Tile) -> (Maybe Battlemap)
apply_to_tile bmap loc fun =
let
index = (location_to_index bmap loc)
at_index = (get index bmap.content)
in
case at_index of
Nothing ->
Nothing
(Just tile) ->
(Just
{bmap |
content =
(set
index
(fun tile)
bmap.content
)
}
)
|