summaryrefslogtreecommitdiff
blob: ccf3e12e1f4f91a8b85f2a9fe88ad82e09897eee (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
104
105
106
107
108
109
110
111
module ElmModule.Update exposing (update)

-- Local Module ----------------------------------------------------------------
import Struct.Event
import Struct.Model

import Update.AbortTurn
import Update.AttackWithoutMoving
import Update.ChangeScale
import Update.DisplayCharacterInfo
import Update.EndTurn
import Update.GoToMainMenu
import Update.HandleAnimationEnded
import Update.HandleServerReply
import Update.LookForCharacter
import Update.RequestDirection
import Update.SelectCharacter
import Update.SelectCharacterOrTile
import Update.SelectTab
import Update.SelectTile
import Update.SendLoadBattleRequest
import Update.SetRequestedHelp
import Update.SwitchTeam
import Update.SwitchWeapon
import Update.TestAnimation
import Update.UndoAction

--------------------------------------------------------------------------------
-- LOCAL -----------------------------------------------------------------------
--------------------------------------------------------------------------------

--------------------------------------------------------------------------------
-- EXPORTED --------------------------------------------------------------------
--------------------------------------------------------------------------------
update : (
      Struct.Event.Type ->
      Struct.Model.Type ->
      (Struct.Model.Type, (Cmd Struct.Event.Type))
   )
update event model =
   let
      new_model = (Struct.Model.clear_error model)
   in
   case event of
      Struct.Event.None -> (model, Cmd.none)

      (Struct.Event.Failed err) ->
         (
            (Struct.Model.invalidate err new_model),
            Cmd.none
         )

      Struct.Event.AttackWithoutMovingRequest ->
         (Update.AttackWithoutMoving.apply_to new_model)

      Struct.Event.AnimationEnded ->
         (Update.HandleAnimationEnded.apply_to model)

      (Struct.Event.DirectionRequested d) ->
         (Update.RequestDirection.apply_to new_model d)

      (Struct.Event.TileSelected loc) ->
         (Update.SelectTile.apply_to new_model loc)

      (Struct.Event.CharacterOrTileSelected loc) ->
         (Update.SelectCharacterOrTile.apply_to new_model loc)

      (Struct.Event.CharacterSelected char_id) ->
         (Update.SelectCharacter.apply_to new_model char_id)

      (Struct.Event.CharacterInfoRequested char_id) ->
         (Update.DisplayCharacterInfo.apply_to new_model char_id)

      (Struct.Event.LookingForCharacter char_id) ->
         (Update.LookForCharacter.apply_to new_model char_id)

      Struct.Event.TurnEnded ->
         (Update.EndTurn.apply_to new_model)

      (Struct.Event.ScaleChangeRequested mod) ->
         (Update.ChangeScale.apply_to new_model mod)

      (Struct.Event.TabSelected tab) ->
         (Update.SelectTab.apply_to new_model tab)

      Struct.Event.DebugTeamSwitchRequest ->
         (Update.SwitchTeam.apply_to new_model)

      Struct.Event.DebugTestAnimation ->
         (Update.TestAnimation.apply_to new_model)

      (Struct.Event.DebugLoadBattleRequest) ->
         (Update.SendLoadBattleRequest.apply_to new_model)

      (Struct.Event.ServerReplied result) ->
         (Update.HandleServerReply.apply_to model result)

      Struct.Event.WeaponSwitchRequest ->
         (Update.SwitchWeapon.apply_to new_model)

      Struct.Event.AbortTurnRequest ->
         (Update.AbortTurn.apply_to new_model)

      Struct.Event.UndoActionRequest ->
         (Update.UndoAction.apply_to new_model)

      (Struct.Event.RequestedHelp help_request) ->
         (Update.SetRequestedHelp.apply_to new_model help_request)

      Struct.Event.GoToMainMenu ->
         (Update.GoToMainMenu.apply_to new_model)