blob: 2493b5e1945b383921075127046bee27420f181b (
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
|
module BattleMap.Struct.Marker exposing
(
Type,
new,
get_locations,
set_locations,
is_in_locations,
decoder,
encode
)
-- Elm -------------------------------------------------------------------------
import Set
import Json.Decode
import Json.Encode
import List
-- Battle Map ------------------------------------------------------------------
import BattleMap.Struct.Location
--------------------------------------------------------------------------------
-- TYPES -----------------------------------------------------------------------
--------------------------------------------------------------------------------
type alias Type =
{
permissions : (Set.Set String),
locations : (Set.Set BattleMap.Struct.Location.Ref)
}
--------------------------------------------------------------------------------
-- LOCAL -----------------------------------------------------------------------
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
-- EXPORTED --------------------------------------------------------------------
--------------------------------------------------------------------------------
new : Type
new =
{
permissions = (Set.empty),
locations = (Set.empty)
}
get_locations : Type -> (Set.Set BattleMap.Struct.Location.Ref)
get_locations marker = marker.locations
set_locations : (Set.Set BattleMap.Struct.Location.Ref) -> Type -> Type
set_locations locations marker = {marker | locations = locations}
is_in_locations : BattleMap.Struct.Location.Ref -> Type -> Bool
is_in_locations loc_ref marker =
(Set.member loc_ref marker.locations)
decoder : (Json.Decode.Decoder Type)
decoder =
(Json.Decode.map2
Type
(Json.Decode.field
"p"
(Json.Decode.map
(Set.fromList)
(Json.Decode.list (Json.Decode.string))
)
)
(Json.Decode.field
"l"
(Json.Decode.map
(Set.fromList)
(Json.Decode.list
(Json.Decode.map
(BattleMap.Struct.Location.get_ref)
(BattleMap.Struct.Location.decoder)
)
)
)
)
)
encode : Type -> Json.Encode.Value
encode marker =
(Json.Encode.object
[
(
"p",
(Json.Encode.list
(Json.Encode.string)
(Set.toList marker.permissions)
)
),
(
"l",
(Json.Encode.list
(\e ->
(BattleMap.Struct.Location.encode
(BattleMap.Struct.Location.from_ref e)
)
)
(Set.toList marker.locations)
)
)
]
)
|