blob: d9375dd85cd7ffcf23bb9856c219b1c91b57e079 (
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
|
module Update.SwitchWeapon exposing (apply_to)
-- Elm -------------------------------------------------------------------------
import Array
-- Map -------------------------------------------------------------------
import Struct.Map
import Struct.Character
import Struct.CharacterTurn
import Struct.Error
import Struct.Event
import Struct.Model
import Struct.Navigator
import Struct.Statistics
import Struct.Weapon
import Struct.WeaponSet
--------------------------------------------------------------------------------
-- LOCAL -----------------------------------------------------------------------
--------------------------------------------------------------------------------
make_it_so : Struct.Model.Type -> Struct.Model.Type
make_it_so model =
case (Struct.CharacterTurn.try_getting_active_character model.char_turn) of
(Just char) ->
let
new_weapons =
(Struct.WeaponSet.switch_weapons
(Struct.Character.get_weapons char)
)
new_char = (Struct.Character.set_weapons new_weapons char)
in
{model |
char_turn =
(Struct.CharacterTurn.set_has_switched_weapons
True
(Struct.CharacterTurn.lock_path
(Struct.CharacterTurn.set_navigator
(Struct.Navigator.new
(Struct.Character.get_location new_char)
(Struct.Statistics.get_movement_points
(Struct.Character.get_statistics new_char)
)
(Struct.Weapon.get_attack_range
(Struct.WeaponSet.get_active_weapon new_weapons)
)
(Struct.Weapon.get_defense_range
(Struct.WeaponSet.get_active_weapon new_weapons)
)
(Struct.Map.get_movement_cost_function
model.map
(Struct.Character.get_location new_char)
(Array.toList model.characters)
)
)
(Struct.CharacterTurn.set_active_character
new_char
model.char_turn
)
)
)
)
}
_ ->
(Struct.Model.invalidate
(Struct.Error.new
Struct.Error.Programming
(
"CharacterTurn structure in the 'SelectedCharacter' state"
++ " without character being selected."
)
)
model
)
--------------------------------------------------------------------------------
-- EXPORTED --------------------------------------------------------------------
--------------------------------------------------------------------------------
apply_to : (
Struct.Model.Type ->
(Struct.Model.Type, (Cmd Struct.Event.Type))
)
apply_to model =
case (Struct.CharacterTurn.get_state model.char_turn) of
Struct.CharacterTurn.SelectedCharacter ->
((make_it_so model), Cmd.none)
_ ->
(
(Struct.Model.invalidate
(Struct.Error.new
Struct.Error.Programming
(
"Attempt to switch weapons as a secondary action or"
++ " without character being selected."
)
)
model
),
Cmd.none
)
|