summaryrefslogtreecommitdiff |
diff options
author | Nathanael Sensfelder <SpamShield0@MultiAgentSystems.org> | 2020-05-24 17:11:00 +0200 |
---|---|---|
committer | Nathanael Sensfelder <SpamShield0@MultiAgentSystems.org> | 2020-05-24 17:11:00 +0200 |
commit | f880b395bf66b12abefc15c46902464bf9d542d1 (patch) | |
tree | d1e3d31b63c9d6611b005bf353fd3957415a90df /src | |
parent | 2e2caf6cc7df607686bbd8304ef23f62cf716939 (diff) |
Working on the display effects...
Diffstat (limited to 'src')
-rw-r--r-- | src/battle/src/Constants/DisplayEffects.elm | 3 | ||||
-rw-r--r-- | src/battle/src/Struct/Character.elm | 11 | ||||
-rw-r--r-- | src/battle/src/Struct/CharacterTurn.elm | 11 | ||||
-rw-r--r-- | src/battle/src/Update/CharacterTurn/AbortTurn.elm | 106 | ||||
-rw-r--r-- | src/battle/src/Update/CharacterTurn/EndTurn.elm | 29 | ||||
-rw-r--r-- | src/battle/src/Update/CharacterTurn/ToggleTarget.elm | 18 | ||||
-rw-r--r-- | src/shared/battle-map/BattleMap/Struct/Map.elm | 27 | ||||
-rw-r--r-- | src/shared/battle-map/BattleMap/Struct/TileInstance.elm | 42 |
8 files changed, 214 insertions, 33 deletions
diff --git a/src/battle/src/Constants/DisplayEffects.elm b/src/battle/src/Constants/DisplayEffects.elm index 8846dbf..da9db9a 100644 --- a/src/battle/src/Constants/DisplayEffects.elm +++ b/src/battle/src/Constants/DisplayEffects.elm @@ -8,3 +8,6 @@ enabled_character = "enabled" target_character : String target_character = "target" + +target_tile : String +target_tile = "target" diff --git a/src/battle/src/Struct/Character.elm b/src/battle/src/Struct/Character.elm index 37fe798..df78ff3 100644 --- a/src/battle/src/Struct/Character.elm +++ b/src/battle/src/Struct/Character.elm @@ -22,6 +22,7 @@ module Struct.Character exposing get_melee_attack_range, refresh_omnimods, add_extra_display_effect, + toggle_extra_display_effect, remove_extra_display_effect, get_extra_display_effects, get_extra_display_effects_list, @@ -36,6 +37,9 @@ import Set import Json.Decode import Json.Decode.Pipeline +-- Shared ---------------------------------------------------------------------- +import Shared.Util.Set + -- Battle ---------------------------------------------------------------------- import Battle.Struct.Omnimods import Battle.Struct.Attributes @@ -243,6 +247,13 @@ add_extra_display_effect effect_name char = (Set.insert effect_name char.extra_display_effects) } +toggle_extra_display_effect : String -> Type -> Type +toggle_extra_display_effect effect_name tile = + {tile | + extra_display_effects = + (Shared.Util.Set.toggle effect_name tile.extra_display_effects) + } + remove_extra_display_effect : String -> Type -> Type remove_extra_display_effect effect_name char = {char | diff --git a/src/battle/src/Struct/CharacterTurn.elm b/src/battle/src/Struct/CharacterTurn.elm index 422c33c..decdab1 100644 --- a/src/battle/src/Struct/CharacterTurn.elm +++ b/src/battle/src/Struct/CharacterTurn.elm @@ -52,6 +52,9 @@ import Json.Encode import Set +-- Shared ---------------------------------------------------------------------- +import Shared.Util.Set + -- Battle ---------------------------------------------------------------------- import Battle.Struct.Omnimods @@ -204,9 +207,7 @@ remove_target_index ix ct = {ct | targets = (Set.remove ix ct.targets)} toggle_target_index : Int -> Type -> Type toggle_target_index ix ct = - if (Set.member ix ct.targets) - then (remove_target_index ix ct) - else (add_target_index ix ct) + {ct | targets = (Shared.Util.Set.toggle ix ct.targets)} get_target_indices : Type -> (Set.Set Int) get_target_indices ct = ct.targets @@ -226,9 +227,7 @@ remove_location ix ct = {ct | locations = (Set.remove ix ct.locations)} toggle_location : BattleMap.Struct.Location.Ref -> Type -> Type toggle_location ix ct = - if (Set.member ix ct.locations) - then (remove_location ix ct) - else (add_location ix ct) + {ct | locations = (Shared.Util.Set.toggle ix ct.locations)} get_locations : Type -> (Set.Set BattleMap.Struct.Location.Ref) get_locations ct = ct.locations diff --git a/src/battle/src/Update/CharacterTurn/AbortTurn.elm b/src/battle/src/Update/CharacterTurn/AbortTurn.elm index 01dfd3e..fbcbfc2 100644 --- a/src/battle/src/Update/CharacterTurn/AbortTurn.elm +++ b/src/battle/src/Update/CharacterTurn/AbortTurn.elm @@ -1,4 +1,12 @@ -module Update.CharacterTurn.AbortTurn exposing (apply_to) +module Update.CharacterTurn.AbortTurn exposing (apply_to, no_command_apply_to) + +-- Elm ------------------------------------------------------------------------- +import Set + +-- Battle Map ------------------------------------------------------------------ +import BattleMap.Struct.Location +import BattleMap.Struct.Map +import BattleMap.Struct.TileInstance -- Local Module ---------------------------------------------------------------- import Constants.DisplayEffects @@ -12,28 +20,92 @@ import Struct.Model -------------------------------------------------------------------------------- -- LOCAL ----------------------------------------------------------------------- -------------------------------------------------------------------------------- +remove_active_character_effects : ( + Struct.CharacterTurn.Type -> + Struct.Battle.Type -> + Struct.Battle.Type + ) +remove_active_character_effects char_turn battle = + case (Struct.CharacterTurn.maybe_get_active_character char_turn) of + Nothing -> battle + (Just char) -> + (Struct.Battle.update_character + (Struct.Character.get_index char) + (Struct.Character.remove_extra_display_effect + Constants.DisplayEffects.active_character + ) + battle + ) + +remove_target_effects : ( + Struct.CharacterTurn.Type -> + Struct.Battle.Type -> + Struct.Battle.Type + ) +remove_target_effects char_turn battle = + (Set.foldl + ( + \target_index current_battle -> + (Struct.Battle.update_character + target_index + (Struct.Character.remove_extra_display_effect + Constants.DisplayEffects.target_character + ) + current_battle + ) + ) + battle + (Struct.CharacterTurn.get_target_indices char_turn) + ) + + +remove_location_effects : ( + Struct.CharacterTurn.Type -> + Struct.Battle.Type -> + Struct.Battle.Type + ) +remove_location_effects char_turn battle = + (Struct.Battle.set_map + (Set.foldl + ( + \location_ref current_map -> + (BattleMap.Struct.Map.update_tile_at + (BattleMap.Struct.Location.from_ref location_ref) + (BattleMap.Struct.TileInstance.remove_extra_display_effect + Constants.DisplayEffects.target_tile + ) + current_map + ) + ) + (Struct.Battle.get_map battle) + (Struct.CharacterTurn.get_locations char_turn) + ) + battle + ) -------------------------------------------------------------------------------- -- EXPORTED -------------------------------------------------------------------- -------------------------------------------------------------------------------- +no_command_apply_to : Struct.Model.Type -> Struct.Model.Type +no_command_apply_to model = + {model | + char_turn = (Struct.CharacterTurn.new), + battle = + (remove_target_effects + model.char_turn + (remove_location_effects + model.char_turn + (remove_active_character_effects + model.char_turn + model.battle + ) + ) + ) + } + apply_to : Struct.Model.Type -> (Struct.Model.Type, (Cmd Struct.Event.Type)) apply_to model = ( - {model | - char_turn = (Struct.CharacterTurn.new), - battle = - case - (Struct.CharacterTurn.maybe_get_active_character model.char_turn) - of - Nothing -> model.battle - (Just char) -> - (Struct.Battle.update_character - (Struct.Character.get_index char) - (Struct.Character.remove_extra_display_effect - Constants.DisplayEffects.active_character - ) - model.battle - ) - }, + (no_command_apply_to model), Cmd.none ) diff --git a/src/battle/src/Update/CharacterTurn/EndTurn.elm b/src/battle/src/Update/CharacterTurn/EndTurn.elm index 353a685..c2348ec 100644 --- a/src/battle/src/Update/CharacterTurn/EndTurn.elm +++ b/src/battle/src/Update/CharacterTurn/EndTurn.elm @@ -3,6 +3,8 @@ module Update.CharacterTurn.EndTurn exposing (apply_to) -- Local Module ---------------------------------------------------------------- import Comm.CharacterTurn +import Constants.DisplayEffects + import Struct.Battle import Struct.Character import Struct.CharacterTurn @@ -11,6 +13,8 @@ import Struct.Event import Struct.Model import Struct.Navigator +import Update.CharacterTurn.AbortTurn + -------------------------------------------------------------------------------- -- LOCAL ----------------------------------------------------------------------- -------------------------------------------------------------------------------- @@ -30,14 +34,21 @@ apply_to model = (_, Nothing) -> (model, Cmd.none) ((Just char), (Just cmd)) -> ( - {model | - battle = - (Struct.Battle.update_character - (Struct.Character.get_index char) - (Struct.Character.set_enabled False) - model.battle - ), - char_turn = (Struct.CharacterTurn.new) - }, + (Update.CharacterTurn.AbortTurn.no_command_apply_to + {model | + battle = + (Struct.Battle.update_character + (Struct.Character.get_index char) + ( + (Struct.Character.remove_extra_display_effect + Constants.DisplayEffects.enabled_character + ) + >> + (Struct.Character.set_enabled False) + ) + model.battle + ) + } + ), cmd ) diff --git a/src/battle/src/Update/CharacterTurn/ToggleTarget.elm b/src/battle/src/Update/CharacterTurn/ToggleTarget.elm index 7b5a9a9..1fb69da 100644 --- a/src/battle/src/Update/CharacterTurn/ToggleTarget.elm +++ b/src/battle/src/Update/CharacterTurn/ToggleTarget.elm @@ -4,6 +4,8 @@ module Update.CharacterTurn.ToggleTarget exposing (apply_to, apply_to_ref) import BattleMap.Struct.Location -- Local Module ---------------------------------------------------------------- +import Constants.DisplayEffects + import Struct.Battle import Struct.Character import Struct.CharacterTurn @@ -59,6 +61,14 @@ toggle_attack_character model target_char_id = target_char_id model.char_turn ), + battle = + (Struct.Battle.update_character + target_char_id + (Struct.Character.toggle_extra_display_effect + Constants.DisplayEffects.target_character + ) + model.battle + ), ui = (Struct.UI.reset_displayed_nav (Struct.UI.reset_displayed_tab @@ -79,6 +89,14 @@ undo_attack_character model target_char_id = target_char_id model.char_turn ), + battle = + (Struct.Battle.update_character + target_char_id + (Struct.Character.remove_extra_display_effect + Constants.DisplayEffects.target_character + ) + model.battle + ), ui = (Struct.UI.reset_displayed_nav (Struct.UI.reset_displayed_tab diff --git a/src/shared/battle-map/BattleMap/Struct/Map.elm b/src/shared/battle-map/BattleMap/Struct/Map.elm index ed6c587..7b31947 100644 --- a/src/shared/battle-map/BattleMap/Struct/Map.elm +++ b/src/shared/battle-map/BattleMap/Struct/Map.elm @@ -15,6 +15,7 @@ module BattleMap.Struct.Map exposing get_width, new, set_tile_to, + update_tile_at, solve_tiles, maybe_get_tile_at ) @@ -136,12 +137,36 @@ add_marker marker_name marker map = ) } -set_tile_to : BattleMap.Struct.Location.Type -> BattleMap.Struct.TileInstance.Type -> Type -> Type +set_tile_to : ( + BattleMap.Struct.Location.Type -> + BattleMap.Struct.TileInstance.Type -> + Type -> + Type + ) set_tile_to loc tile_inst map = {map | content = (Array.set (location_to_index loc map) tile_inst map.content) } +update_tile_at : ( + BattleMap.Struct.Location.Type -> + ( + BattleMap.Struct.TileInstance.Type -> + BattleMap.Struct.TileInstance.Type + ) -> + Type -> + Type + ) +update_tile_at loc fun map = + {map | + content = + (Shared.Util.Array.update + (location_to_index loc map) + (fun) + map.content + ) + } + empty : Type empty = { diff --git a/src/shared/battle-map/BattleMap/Struct/TileInstance.elm b/src/shared/battle-map/BattleMap/Struct/TileInstance.elm index 91e3bf5..8ffeafc 100644 --- a/src/shared/battle-map/BattleMap/Struct/TileInstance.elm +++ b/src/shared/battle-map/BattleMap/Struct/TileInstance.elm @@ -24,6 +24,11 @@ module BattleMap.Struct.TileInstance exposing error, solve, set_location_from_index, + add_extra_display_effect, + remove_extra_display_effect, + get_extra_display_effects, + get_extra_display_effects_list, + reset_extra_display_effects, decoder, encode ) @@ -38,6 +43,9 @@ import Json.Encode import Json.Decode import Json.Decode.Pipeline +-- Shared ---------------------------------------------------------------------- +import Shared.Util.Set + -- Battle Map ------------------------------------------------------------------ import BattleMap.Struct.DataSet import BattleMap.Struct.Tile @@ -58,6 +66,7 @@ type alias Type = class_id : BattleMap.Struct.Tile.Ref, variant_id : BattleMap.Struct.Tile.VariantID, tags : (Set.Set String), + extra_display_effects : (Set.Set String), borders : (List Border) } @@ -100,6 +109,7 @@ default tile = crossing_cost = (BattleMap.Struct.Tile.get_cost tile), family = (BattleMap.Struct.Tile.get_family tile), tags = (Set.empty), + extra_display_effects = (Set.empty), borders = [] } @@ -112,6 +122,7 @@ error x y = family = "0", crossing_cost = Constants.Movement.cost_when_out_of_bounds, tags = (Set.empty), + extra_display_effects = (Set.empty), borders = [] } @@ -186,6 +197,7 @@ decoder = |> (Json.Decode.Pipeline.hardcoded tile_id) |> (Json.Decode.Pipeline.hardcoded variant_id) |> (Json.Decode.Pipeline.hardcoded (Set.empty)) -- tags + |> (Json.Decode.Pipeline.hardcoded (Set.empty)) -- display_effects |> (Json.Decode.Pipeline.hardcoded (list_to_borders borders []) @@ -260,3 +272,33 @@ remove_tag tag tile_inst = {tile_inst | tags = (Set.remove tag tile_inst.tags) } + +add_extra_display_effect : String -> Type -> Type +add_extra_display_effect effect_name tile = + {tile | + extra_display_effects = + (Set.insert effect_name tile.extra_display_effects) + } + +toggle_extra_display_effect : String -> Type -> Type +toggle_extra_display_effect effect_name tile = + {tile | + extra_display_effects = + (Shared.Util.Set.toggle effect_name tile.extra_display_effects) + } + +remove_extra_display_effect : String -> Type -> Type +remove_extra_display_effect effect_name tile = + {tile | + extra_display_effects = + (Set.remove effect_name tile.extra_display_effects) + } + +get_extra_display_effects : Type -> (Set.Set String) +get_extra_display_effects tile = tile.extra_display_effects + +get_extra_display_effects_list : Type -> (List String) +get_extra_display_effects_list tile = (Set.toList tile.extra_display_effects) + +reset_extra_display_effects : Type -> Type +reset_extra_display_effects tile = {tile | extra_display_effects = (Set.empty)} |