summaryrefslogtreecommitdiff |
diff options
author | nsensfel <SpamShield0@noot-noot.org> | 2018-12-06 19:17:01 +0100 |
---|---|---|
committer | nsensfel <SpamShield0@noot-noot.org> | 2018-12-06 19:17:01 +0100 |
commit | f7f0adb73cecbcb2154c20d81e2b42705bcfbe56 (patch) | |
tree | 9990db68d814a580d84b8b9a77d74359f1dcd4d9 | |
parent | 31cef45c4b972c1b2b393b4a7decf95c52bc54e6 (diff) |
...
-rw-r--r-- | src/roster-editor/src/ElmModule/Update.elm | 12 | ||||
-rw-r--r-- | src/roster-editor/src/Update/ToggleBattleIndex.elm | 82 | ||||
-rw-r--r-- | src/shared/elm/Util/Array.elm | 8 |
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 |