summaryrefslogtreecommitdiff |
diff options
Diffstat (limited to 'src/shared/battle-map/BattleMap/Struct')
-rw-r--r-- | src/shared/battle-map/BattleMap/Struct/Direction.elm | 12 | ||||
-rw-r--r-- | src/shared/battle-map/BattleMap/Struct/Map.elm | 34 | ||||
-rw-r--r-- | src/shared/battle-map/BattleMap/Struct/Marker.elm | 99 | ||||
-rw-r--r-- | src/shared/battle-map/BattleMap/Struct/TileInstance.elm | 16 |
4 files changed, 127 insertions, 34 deletions
diff --git a/src/shared/battle-map/BattleMap/Struct/Direction.elm b/src/shared/battle-map/BattleMap/Struct/Direction.elm index 4620e29..0418d31 100644 --- a/src/shared/battle-map/BattleMap/Struct/Direction.elm +++ b/src/shared/battle-map/BattleMap/Struct/Direction.elm @@ -1,10 +1,10 @@ module BattleMap.Struct.Direction exposing -( - Type(..), - opposite_of, - to_string, - decoder -) + ( + Type(..), + opposite_of, + to_string, + decoder + ) -- Elm ------------------------------------------------------------------------- import Json.Decode diff --git a/src/shared/battle-map/BattleMap/Struct/Map.elm b/src/shared/battle-map/BattleMap/Struct/Map.elm index aa166d4..97f0ae8 100644 --- a/src/shared/battle-map/BattleMap/Struct/Map.elm +++ b/src/shared/battle-map/BattleMap/Struct/Map.elm @@ -27,10 +27,13 @@ import Battle.Struct.Omnimods -- Battle Map ------------------------------------------------------------------ import BattleMap.Struct.Location -import BattleMap.Struct.MapMarker +import BattleMap.Struct.Marker import BattleMap.Struct.Tile import BattleMap.Struct.TileInstance +-- Local Module ---------------------------------------------------------------- +import Constants.Movement + -------------------------------------------------------------------------------- -- TYPES ----------------------------------------------------------------------- -------------------------------------------------------------------------------- @@ -39,7 +42,7 @@ type alias Type = width : Int, height : Int, content : (Array.Array BattleMap.Struct.TileInstance.Type), - markers : (Dict.Dict String BattleMap.Struct.MapMarker.Type) + markers : (Dict.Dict String BattleMap.Struct.Marker.Type) } -------------------------------------------------------------------------------- @@ -70,7 +73,7 @@ get_height map = map.height get_tiles : Type -> (Array.Array BattleMap.Struct.TileInstance.Type) get_tiles map = map.content -get_markers : Type -> (Dict.Dict String BattleMap.Struct.MapMarker.Type) +get_markers : Type -> (Dict.Dict String BattleMap.Struct.Marker.Type) get_markers map = map.markers set_tile_to : BattleMap.Struct.Location.Type -> BattleMap.Struct.TileInstance.Type -> Type -> Type @@ -163,7 +166,7 @@ decoder = (Json.Decode.map (Dict.fromList) (Json.Decode.keyValuePairs - (BattleMap.Struct.MapMarker.decoder) + (BattleMap.Struct.Marker.decoder) ) ) ) @@ -174,32 +177,19 @@ decoder = get_movement_cost_function : ( Type -> + (List BattleMap.Struct.Location.Type) -> BattleMap.Struct.Location.Type -> - (List BattleMap.Struct.Character.Type) -> BattleMap.Struct.Location.Type -> Int ) -get_movement_cost_function bmap start_loc char_list loc = +get_movement_cost_function bmap occupied_tiles start_loc loc = if (has_location loc bmap) then case (Array.get (location_to_index loc bmap) bmap.content) of (Just tile) -> - if - (List.any - ( - \c -> - ( - ((BattleMap.Struct.Character.get_location c) == loc) - && (loc /= start_loc) - && (BattleMap.Struct.Character.is_alive c) - ) - ) - char_list - ) - then - Constants.Movement.cost_when_occupied_tile - else - (BattleMap.Struct.TileInstance.get_cost tile) + if ((loc /= start_loc) && (List.member loc occupied_tiles)) + then Constants.Movement.cost_when_occupied_tile + else (BattleMap.Struct.TileInstance.get_cost tile) Nothing -> Constants.Movement.cost_when_out_of_bounds else diff --git a/src/shared/battle-map/BattleMap/Struct/Marker.elm b/src/shared/battle-map/BattleMap/Struct/Marker.elm new file mode 100644 index 0000000..9af3ece --- /dev/null +++ b/src/shared/battle-map/BattleMap/Struct/Marker.elm @@ -0,0 +1,99 @@ +module BattleMap.Struct.Marker exposing + ( + Type, + new, + get_locations, + is_in_locations, + decoder, + encode + ) + +-- Elm ------------------------------------------------------------------------- +import Set +import Json.Decode +import Json.Encode +import List + +-- Battle Map ------------------------------------------------------------------ +import BattleMap.Struct.Location + +-------------------------------------------------------------------------------- +-- TYPES ----------------------------------------------------------------------- +-------------------------------------------------------------------------------- +type alias Type = + { + permissions : (Set.Set String), + locations : (Set.Set BattleMap.Struct.Location.Ref) + } + +-------------------------------------------------------------------------------- +-- LOCAL ----------------------------------------------------------------------- +-------------------------------------------------------------------------------- + +-------------------------------------------------------------------------------- +-- EXPORTED -------------------------------------------------------------------- +-------------------------------------------------------------------------------- + +new : Type +new = + { + permissions = (Set.empty), + locations = (Set.empty) + } + +get_locations : Type -> (Set.Set BattleMap.Struct.Location.Ref) +get_locations marker = marker.locations + +is_in_locations : BattleMap.Struct.Location.Ref -> Type -> Bool +is_in_locations loc_ref marker = + (Set.member loc_ref marker.locations) + +decoder : (Json.Decode.Decoder Type) +decoder = + (Json.Decode.map2 + Type + (Json.Decode.field + "p" + (Json.Decode.map + (Set.fromList) + (Json.Decode.list (Json.Decode.string)) + ) + ) + (Json.Decode.field + "l" + (Json.Decode.map + (Set.fromList) + (Json.Decode.list + (Json.Decode.map + (BattleMap.Struct.Location.get_ref) + (BattleMap.Struct.Location.decoder) + ) + ) + ) + ) + ) + +encode : Type -> Json.Encode.Value +encode marker = + (Json.Encode.object + [ + ( + "p", + (Json.Encode.list + (Json.Encode.string) + (Set.toList marker.permissions) + ) + ), + ( + "l", + (Json.Encode.list + (\e -> + (BattleMap.Struct.Location.encode + (BattleMap.Struct.Location.from_ref e) + ) + ) + (Set.toList marker.locations) + ) + ) + ] + ) diff --git a/src/shared/battle-map/BattleMap/Struct/TileInstance.elm b/src/shared/battle-map/BattleMap/Struct/TileInstance.elm index 8c39371..c8b4f09 100644 --- a/src/shared/battle-map/BattleMap/Struct/TileInstance.elm +++ b/src/shared/battle-map/BattleMap/Struct/TileInstance.elm @@ -72,7 +72,11 @@ noise_function a b c = clone : BattleMap.Struct.Location.Type -> Type -> Type clone loc inst = {inst | location = loc} -new_border : BattleMap.Struct.Tile.Ref -> BattleMap.Struct.Tile.VariantID -> Border +new_border : ( + BattleMap.Struct.Tile.Ref -> + BattleMap.Struct.Tile.VariantID -> + Border + ) new_border class_id variant_id = { class_id = class_id, @@ -83,10 +87,10 @@ default : BattleMap.Struct.Tile.Type -> Type default tile = { location = {x = 0, y = 0}, - class_id = (Struct.Tile.get_id tile), + class_id = (BattleMap.Struct.Tile.get_id tile), variant_id = "0", - crossing_cost = (Struct.Tile.get_cost tile), - family = (Struct.Tile.get_family tile), + crossing_cost = (BattleMap.Struct.Tile.get_cost tile), + family = (BattleMap.Struct.Tile.get_family tile), triggers = [], borders = [] } @@ -147,8 +151,8 @@ solve tiles tile_inst = case (Dict.get tile_inst.class_id tiles) of (Just tile) -> {tile_inst | - crossing_cost = (Struct.Tile.get_cost tile), - family = (Struct.Tile.get_family tile) + crossing_cost = (BattleMap.Struct.Tile.get_cost tile), + family = (BattleMap.Struct.Tile.get_family tile) } Nothing -> |