summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/roster-editor/src/ElmModule/Update.elm12
-rw-r--r--src/roster-editor/src/Update/ToggleBattleIndex.elm82
-rw-r--r--src/shared/elm/Util/Array.elm8
3 files changed, 95 insertions, 7 deletions
diff --git a/src/roster-editor/src/ElmModule/Update.elm b/src/roster-editor/src/ElmModule/Update.elm
index 88d059d..923b552 100644
--- a/src/roster-editor/src/ElmModule/Update.elm
+++ b/src/roster-editor/src/ElmModule/Update.elm
@@ -13,12 +13,13 @@ import Update.SelectCharacter
import Update.SelectTab
import Update.SendRoster
import Update.SetArmor
-import Update.SetName
import Update.SetGlyph
import Update.SetGlyphBoard
+import Update.SetName
import Update.SetPortrait
import Update.SetRequestedHelp
import Update.SetWeapon
+import Update.ToggleBattleIndex
--------------------------------------------------------------------------------
-- LOCAL -----------------------------------------------------------------------
@@ -53,11 +54,10 @@ update event model =
)
(Struct.Event.ToggleCharacterBattleIndex char_id) ->
- (new_model, Cmd.none)
- -- (Update.ToggleCharacterBattleIndex.apply_to
- -- (Struct.Model.save_character new_model)
- -- char_id
- -- )
+ (Update.ToggleBattleIndex.apply_to
+ (Struct.Model.save_character new_model)
+ char_id
+ )
(Struct.Event.TabSelected tab) ->
(Update.SelectTab.apply_to
diff --git a/src/roster-editor/src/Update/ToggleBattleIndex.elm b/src/roster-editor/src/Update/ToggleBattleIndex.elm
new file mode 100644
index 0000000..42d8374
--- /dev/null
+++ b/src/roster-editor/src/Update/ToggleBattleIndex.elm
@@ -0,0 +1,82 @@
+module Update.ToggleBattleIndex exposing (apply_to)
+
+-- Elm -------------------------------------------------------------------------
+import Array
+
+-- Roster Editor ---------------------------------------------------------------
+import Util.Array
+
+import Struct.Character
+import Struct.Event
+import Struct.Model
+
+--------------------------------------------------------------------------------
+-- LOCAL -----------------------------------------------------------------------
+--------------------------------------------------------------------------------
+remove_battle_index : (
+ Struct.Model.Type ->
+ Struct.Character.Type->
+ Int ->
+ Struct.Model.Type
+ )
+remove_battle_index model char index =
+ {model |
+ edited_char = Nothing,
+ used_indices =
+ (Array.set
+ (Struct.Character.get_battle_index char)
+ False
+ model.used_indices
+ ),
+ characters =
+ (Array.set
+ index
+ (Struct.Character.set_battle_index -1 char)
+ model.characters
+ )
+ }
+
+give_battle_index : (
+ Struct.Model.Type ->
+ Struct.Character.Type->
+ Int ->
+ Struct.Model.Type
+ )
+give_battle_index model char index =
+ case (Util.Array.indexed_search (\e -> (not e)) model.used_indices) of
+ Nothing -> model
+ (Just (battle_index, _)) ->
+ {model |
+ edited_char = Nothing,
+ used_indices = (Array.set battle_index True model.used_indices),
+ characters =
+ (Array.set
+ index
+ (Struct.Character.set_battle_index battle_index char)
+ model.characters
+ )
+ }
+
+--------------------------------------------------------------------------------
+-- EXPORTED --------------------------------------------------------------------
+--------------------------------------------------------------------------------
+apply_to : (
+ Struct.Model.Type ->
+ Int ->
+ (Struct.Model.Type, (Cmd Struct.Event.Type))
+ )
+apply_to model index =
+ case (Array.get index model.characters) of
+ Nothing ->
+ -- TODO: error
+ (model, Cmd.none)
+
+ (Just char) ->
+ (
+ (
+ if ((Struct.Character.get_battle_index char) == -1)
+ then (give_battle_index model char index)
+ else (remove_battle_index model char index)
+ ),
+ Cmd.none
+ )
diff --git a/src/shared/elm/Util/Array.elm b/src/shared/elm/Util/Array.elm
index 9e57c18..362c924 100644
--- a/src/shared/elm/Util/Array.elm
+++ b/src/shared/elm/Util/Array.elm
@@ -2,7 +2,8 @@ module Util.Array exposing
(
update,
update_unsafe,
- filter_first
+ filter_first,
+ indexed_search
)
import Array
@@ -32,3 +33,8 @@ update_unsafe index fun array =
filter_first : (t -> Bool) -> (Array.Array t) -> (Maybe t)
filter_first fun array =
(Array.get 0 (Array.filter fun array))
+
+indexed_search : (t -> Bool) -> (Array.Array t) -> (Maybe (Int, t))
+indexed_search fun array =
+ -- TODO
+ Nothing