summaryrefslogtreecommitdiff |
diff options
author | nsensfel <SpamShield0@noot-noot.org> | 2019-03-15 18:41:39 +0100 |
---|---|---|
committer | nsensfel <SpamShield0@noot-noot.org> | 2019-03-15 18:41:39 +0100 |
commit | 8103bf80277b759bb9c3b1e032612721f132f256 (patch) | |
tree | a1b1858483281e61a0dcb9cb42fb6df38214c06a /src/shared | |
parent | 6678cfe464ed9ee595f4f3dd7398dec1416454c9 (diff) |
[Broken] Got 'battle' to compile again.
Diffstat (limited to 'src/shared')
-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 | ||||
-rw-r--r-- | src/shared/battle-map/BattleMap/View/Tile.elm | 10 | ||||
-rw-r--r-- | src/shared/battle/Battle/Struct/Omnimods.elm | 62 |
6 files changed, 191 insertions, 42 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 -> diff --git a/src/shared/battle-map/BattleMap/View/Tile.elm b/src/shared/battle-map/BattleMap/View/Tile.elm index 6039ff4..d2bf044 100644 --- a/src/shared/battle-map/BattleMap/View/Tile.elm +++ b/src/shared/battle-map/BattleMap/View/Tile.elm @@ -1,4 +1,9 @@ -module BattleMap.View.Tile exposing (get_html, get_html_extra, get_content_html) +module BattleMap.View.Tile exposing + ( + get_html, + get_html_with_extra, + get_content_html + ) -- Elm ------------------------------------------------------------------------- import Html @@ -66,6 +71,7 @@ get_content_html tile = ] [] ) + :: (Html.div [ (Html.Attributes.class "tile-icon-bg"), @@ -173,7 +179,7 @@ get_html display_cost tile = get_html_with_extra : ( Bool -> - (List Html.Attributes.Attribute) -> + (List (Html.Attribute Struct.Event.Type)) -> BattleMap.Struct.TileInstance.Type -> (Html.Html Struct.Event.Type) ) diff --git a/src/shared/battle/Battle/Struct/Omnimods.elm b/src/shared/battle/Battle/Struct/Omnimods.elm index 46843b2..fd0088b 100644 --- a/src/shared/battle/Battle/Struct/Omnimods.elm +++ b/src/shared/battle/Battle/Struct/Omnimods.elm @@ -3,6 +3,7 @@ module Battle.Struct.Omnimods exposing Type, new, merge, + none, apply_to_attributes, apply_to_statistics, get_attack_damage, @@ -11,6 +12,8 @@ module Battle.Struct.Omnimods exposing get_statistics_mods, get_attack_mods, get_defense_mods, + get_all_mods, + scale, decoder ) @@ -47,7 +50,7 @@ type alias GenericMod = generic_mods_decoder : (Json.Decode.Decoder (Dict.Dict String Int)) generic_mods_decoder = (Json.Decode.map - (Dict.fromList) + ((Dict.fromList) >> (Dict.remove "none")) (Json.Decode.list (Json.Decode.map (\gm -> (gm.t, gm.v)) @@ -75,6 +78,9 @@ merge_mods a_mods b_mods = (Dict.empty) ) +scale_dict_value : Float -> String -> Int -> Int +scale_dict_value modifier entry_name value = + (ceiling ((toFloat value) * modifier)) -------------------------------------------------------------------------------- -- EXPORTED -------------------------------------------------------------------- -------------------------------------------------------------------------------- @@ -103,6 +109,15 @@ new attribute_mods statistic_mods attack_mods defense_mods = defense = (Dict.fromList defense_mods) } +none : Type +none = + { + attributes = (Dict.empty), + statistics = (Dict.empty), + attack = (Dict.empty), + defense = (Dict.empty) + } + merge : Type -> Type -> Type merge omni_a omni_b = { @@ -112,18 +127,32 @@ merge omni_a omni_b = defense = (merge_mods omni_a.defense omni_b.defense) } -apply_to_attributes : Type -> Battle.Struct.Attributes.Type -> Battle.Struct.Attributes.Type +apply_to_attributes : ( + Type -> + Battle.Struct.Attributes.Type + -> Battle.Struct.Attributes.Type + ) apply_to_attributes omnimods attributes = (Dict.foldl - ((Battle.Struct.Attributes.decode_category) >> (Battle.Struct.Attributes.mod)) + ( + (Battle.Struct.Attributes.decode_category) + >> (Battle.Struct.Attributes.mod) + ) attributes omnimods.attributes ) -apply_to_statistics : Type -> Battle.Struct.Statistics.Type -> Battle.Struct.Statistics.Type +apply_to_statistics : ( + Type -> + Battle.Struct.Statistics.Type -> + Battle.Struct.Statistics.Type + ) apply_to_statistics omnimods statistics = (Dict.foldl - ((Battle.Struct.Statistics.decode_category) >> (Battle.Struct.Statistics.mod)) + ( + (Battle.Struct.Statistics.decode_category) + >> (Battle.Struct.Statistics.mod) + ) statistics omnimods.statistics ) @@ -139,7 +168,9 @@ get_attack_damage dmg_modifier atk_omni def_omni = ( case (Dict.get - (Battle.Struct.DamageType.encode Battle.Struct.DamageType.Base) + (Battle.Struct.DamageType.encode + Battle.Struct.DamageType.Base + ) def_omni.defense ) of @@ -167,6 +198,16 @@ get_attack_damage dmg_modifier atk_omni def_omni = atk_omni.attack ) +scale : Float -> Type -> Type +scale multiplier omnimods = + {omnimods | + attributes = (Dict.map (scale_dict_value multiplier) omnimods.attributes), + statistics = (Dict.map (scale_dict_value multiplier) omnimods.statistics), + attack = (Dict.map (scale_dict_value multiplier) omnimods.attack), + defense = + (Dict.map (scale_dict_value multiplier) omnimods.defense) + } + get_attributes_mods : Type -> (List (String, Int)) get_attributes_mods omnimods = (Dict.toList omnimods.attributes) @@ -178,3 +219,12 @@ get_attack_mods omnimods = (Dict.toList omnimods.attack) get_defense_mods : Type -> (List (String, Int)) get_defense_mods omnimods = (Dict.toList omnimods.defense) + +get_all_mods : Type -> (List (String, Int)) +get_all_mods omnimods = + ( + (get_attributes_mods omnimods) + ++ (get_statistics_mods omnimods) + ++ (get_attack_mods omnimods) + ++ (get_defense_mods omnimods) + ) |