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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
|
module BattleCharacters.Struct.Character exposing
(
Type,
Unresolved,
get_name,
set_name,
get_equipment,
set_equipment,
dirty_set_equipment,
get_omnimods,
set_extra_omnimods,
dirty_set_extra_omnimods,
get_attributes,
get_statistics,
get_active_weapon,
get_inactive_weapon,
switch_weapons,
dirty_switch_weapons,
decoder,
encode,
resolve
)
-- Elm -------------------------------------------------------------------------
import Json.Decode
import Json.Decode.Pipeline
import Json.Encode
-- Battle ----------------------------------------------------------------------
import Battle.Struct.Omnimods
import Battle.Struct.Attributes
import Battle.Struct.Statistics
-- Battle Characters -----------------------------------------------------------
import BattleCharacters.Struct.Armor
import BattleCharacters.Struct.Equipment
import BattleCharacters.Struct.Weapon
import BattleCharacters.Struct.GlyphBoard
--------------------------------------------------------------------------------
-- TYPES -----------------------------------------------------------------------
--------------------------------------------------------------------------------
type alias Type =
{
name : String,
equipment : BattleCharacters.Struct.Equipment.Type,
attributes : Battle.Struct.Attributes.Type,
statistics : Battle.Struct.Statistics.Type,
is_using_secondary : Bool,
omnimods : Battle.Struct.Omnimods.Type,
extra_omnimods : Battle.Struct.Omnimods.Type
}
type alias Unresolved =
{
name : String,
equipment : BattleCharacters.Struct.Equipment.Unresolved,
is_using_secondary : Bool
}
--------------------------------------------------------------------------------
-- LOCAL -----------------------------------------------------------------------
--------------------------------------------------------------------------------
refresh_omnimods : Type -> Type
refresh_omnimods char =
let
equipment = char.equipment
omnimods =
(Battle.Struct.Omnimods.merge
(Battle.Struct.Omnimods.merge
(Battle.Struct.Omnimods.merge
char.extra_omnimods
(BattleCharacters.Struct.Weapon.get_omnimods
(get_active_weapon char)
)
)
(BattleCharacters.Struct.Armor.get_omnimods
(BattleCharacters.Struct.Equipment.get_armor equipment)
)
)
(BattleCharacters.Struct.GlyphBoard.get_omnimods_with_glyphs
(BattleCharacters.Struct.Equipment.get_glyphs equipment)
(BattleCharacters.Struct.Equipment.get_glyph_board equipment)
)
)
attributes =
(Battle.Struct.Omnimods.apply_to_attributes
omnimods
(Battle.Struct.Attributes.default)
)
statistics =
(Battle.Struct.Omnimods.apply_to_statistics
omnimods
(Battle.Struct.Statistics.new_raw attributes)
)
in
{char |
attributes = attributes,
statistics = statistics,
omnimods = omnimods
}
--------------------------------------------------------------------------------
-- EXPORTED --------------------------------------------------------------------
--------------------------------------------------------------------------------
get_active_weapon : Type -> BattleCharacters.Struct.Weapon.Type
get_active_weapon char =
if (char.is_using_secondary)
then (BattleCharacters.Struct.Equipment.get_secondary_weapon char.equipment)
else (BattleCharacters.Struct.Equipment.get_primary_weapon char.equipment)
get_inactive_weapon : Type -> BattleCharacters.Struct.Weapon.Type
get_inactive_weapon char =
if (char.is_using_secondary)
then (BattleCharacters.Struct.Equipment.get_primary_weapon char.equipment)
else (BattleCharacters.Struct.Equipment.get_secondary_weapon char.equipment)
get_name : Type -> String
get_name c = c.name
set_name : String -> Type -> Type
set_name name char = {char | name = name}
get_equipment : Type -> BattleCharacters.Struct.Equipment.Type
get_equipment c = c.equipment
set_equipment : BattleCharacters.Struct.Equipment.Type -> Type -> Type
set_equipment equipment char = (refresh_omnimods {char | equipment = equipment})
dirty_set_equipment : BattleCharacters.Struct.Equipment.Type -> Type -> Type
dirty_set_equipment equipment char = {char | equipment = equipment}
get_omnimods : Type -> Battle.Struct.Omnimods.Type
get_omnimods char = char.omnimods
set_extra_omnimods : Battle.Struct.Omnimods.Type -> Type -> Type
set_extra_omnimods om char = (refresh_omnimods {char | extra_omnimods = om})
dirty_set_extra_omnimods : Battle.Struct.Omnimods.Type -> Type -> Type
dirty_set_extra_omnimods om char = {char | extra_omnimods = om}
get_attributes : Type -> Battle.Struct.Attributes.Type
get_attributes char = char.attributes
get_statistics : Type -> Battle.Struct.Statistics.Type
get_statistics char = char.statistics
switch_weapons : Type -> Type
switch_weapons char =
(refresh_omnimods
{char | is_using_secondary = (not char.is_using_secondary)}
)
dirty_switch_weapons : Type -> Type
dirty_switch_weapons char =
{char | is_using_secondary = (not char.is_using_secondary)}
decoder : (Json.Decode.Decoder Unresolved)
decoder =
(Json.Decode.succeed
Unresolved
|> (Json.Decode.Pipeline.required "nam" Json.Decode.string)
|>
(Json.Decode.Pipeline.required
"eq"
BattleCharacters.Struct.Equipment.decoder
)
|> (Json.Decode.Pipeline.required "sec" Json.Decode.bool)
)
to_unresolved : Type -> Unresolved
to_unresolved char =
{
name = char.name,
equipment =
(BattleCharacters.Struct.Equipment.to_unresolved char.equipment),
is_using_secondary = char.is_using_secondary
}
encode : Unresolved -> Json.Encode.Value
encode ref =
(Json.Encode.object
[
("nam", (Json.Encode.string ref.name)),
("eq", (BattleCharacters.Struct.Equipment.encode ref.equipment)),
("sec", (Json.Encode.bool ref.is_using_secondary))
]
)
resolve : (
(
BattleCharacters.Struct.Equipment.Unresolved ->
BattleCharacters.Struct.Equipment.Type
) ->
Battle.Struct.Omnimods.Type ->
Unresolved ->
Type
)
resolve resolve_equipment extra_omnimods ref =
let default_attributes = (Battle.Struct.Attributes.default) in
(refresh_omnimods
{
name = ref.name,
equipment = (resolve_equipment ref.equipment),
attributes = default_attributes,
statistics = (Battle.Struct.Statistics.new_raw default_attributes),
is_using_secondary = ref.is_using_secondary,
omnimods = (Battle.Struct.Omnimods.none),
extra_omnimods = extra_omnimods
}
)
|