summaryrefslogtreecommitdiff |
diff options
author | Nathanael Sensfelder <SpamShield0@MultiAgentSystems.org> | 2019-06-12 18:08:31 +0200 |
---|---|---|
committer | Nathanael Sensfelder <SpamShield0@MultiAgentSystems.org> | 2019-06-12 18:08:31 +0200 |
commit | 9eaf4c0a006e2a08fdd1e2248978c4ac5cdaef3b (patch) | |
tree | 8fdb40547999938c4bd055bdae09443dd681293a /src/shared/battle-map/BattleMap/Struct/TileInstance.elm | |
parent | f3f09c301fdb1acf9fb7e77db92bfed3147ab215 (diff) |
Working on Attacks of Opportunity...
I think that the use of map markers to handle attacks of opportunity is
justified on the client: quick and cheap detection is key for the path finding
algorithm, and we don't need to propagate the changes to another copy of
the data.
Diffstat (limited to 'src/shared/battle-map/BattleMap/Struct/TileInstance.elm')
-rw-r--r-- | src/shared/battle-map/BattleMap/Struct/TileInstance.elm | 35 |
1 files changed, 30 insertions, 5 deletions
diff --git a/src/shared/battle-map/BattleMap/Struct/TileInstance.elm b/src/shared/battle-map/BattleMap/Struct/TileInstance.elm index c8b4f09..87d2762 100644 --- a/src/shared/battle-map/BattleMap/Struct/TileInstance.elm +++ b/src/shared/battle-map/BattleMap/Struct/TileInstance.elm @@ -15,6 +15,9 @@ module BattleMap.Struct.TileInstance exposing get_border_variant_id, get_border_class_id, get_local_variant_ix, + remove_trigger, + add_trigger, + get_triggers, error, solve, set_location_from_index, @@ -25,6 +28,8 @@ module BattleMap.Struct.TileInstance exposing -- Elm ------------------------------------------------------------------------- import Dict +import Set + import Json.Encode import Json.Decode @@ -49,7 +54,7 @@ type alias Type = family : BattleMap.Struct.Tile.FamilyID, class_id : BattleMap.Struct.Tile.Ref, variant_id : BattleMap.Struct.Tile.VariantID, - triggers : (List String), + triggers : (Set.Set String), borders : (List Border) } @@ -91,7 +96,7 @@ default tile = variant_id = "0", crossing_cost = (BattleMap.Struct.Tile.get_cost tile), family = (BattleMap.Struct.Tile.get_family tile), - triggers = [], + triggers = (Set.empty), borders = [] } @@ -103,7 +108,7 @@ error x y = variant_id = "0", family = "0", crossing_cost = Constants.Movement.cost_when_out_of_bounds, - triggers = [], + triggers = (Set.empty), borders = [] } @@ -192,7 +197,10 @@ decoder = |> (Json.Decode.Pipeline.required "t" - (Json.Decode.list (Json.Decode.string)) + (Json.Decode.map + (Set.fromList) + (Json.Decode.list (Json.Decode.string)) + ) ) |> (Json.Decode.Pipeline.hardcoded @@ -246,8 +254,25 @@ encode tile_inst = ), ( "t", - (Json.Encode.list (Json.Encode.string) tile_inst.triggers) + (Json.Encode.list + (Json.Encode.string) + (Set.toList tile_inst.triggers) + ) ) ] ) +get_triggers : Type -> (Set.Set String) +get_triggers tile_inst = tile_inst.triggers + +add_trigger : String -> Type -> Type +add_trigger trigger tile_inst = + {tile_inst | + triggers = (Set.insert trigger tile_inst.triggers) + } + +remove_trigger : String -> Type -> Type +remove_trigger trigger tile_inst = + {tile_inst | + triggers = (Set.remove trigger tile_inst.triggers) + } |