aboutsummaryrefslogtreecommitdiff
blob: 7007d478416e9beea721b7e4ba86e1dd723d150f (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
module Update.SetGlyph exposing (apply_to)

-- Elm -------------------------------------------------------------------------
import Dict

-- Battle Characters -----------------------------------------------------------
import BattleCharacters.Struct.Glyph
import BattleCharacters.Struct.Equipment
import BattleCharacters.Struct.Character

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

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

--------------------------------------------------------------------------------
-- EXPORTED --------------------------------------------------------------------
--------------------------------------------------------------------------------
apply_to : (
      Struct.Model.Type ->
      BattleCharacters.Struct.Glyph.Ref ->
      (Struct.Model.Type, (Cmd Struct.Event.Type))
   )
apply_to model ref =
   (
      (
         case (model.edited_char, (Dict.get ref model.glyphs)) of
            ((Just char), (Just glyph)) ->
               let
                  base_char = (Struct.Character.get_base_character char)
                  updated_equipment =
                     (BattleCharacters.Struct.Equipment.set_glyph
                        (Struct.UI.get_glyph_slot model.ui)
                        glyph
                        (BattleCharacters.Struct.Character.get_equipment
                           base_char
                        )
                     )
               in
               {model |
                  edited_char =
                     (Just
                        (Struct.Character.set_invalid_glyph_family_indices
                           updated_equipment
                           (Struct.Character.set_base_character
                              (BattleCharacters.Struct.Character.set_equipment
                                 updated_equipment
                                 base_char
                              )
                              char
                           )
                        )
                     ),
                  ui =
                     (Struct.UI.set_displayed_tab
                        Struct.UI.GlyphManagementTab
                        model.ui
                     )
               }

            _ -> model
      ),
      Cmd.none
   )