From af452e14397afb04d207628f568238a09989478d Mon Sep 17 00:00:00 2001 From: nsensfel Date: Tue, 7 May 2019 17:23:44 +0200 Subject: Working on markers... --- src/shared/battle-map/BattleMap/Struct/Marker.elm | 95 ++++++++++++++++++----- 1 file changed, 74 insertions(+), 21 deletions(-) diff --git a/src/shared/battle-map/BattleMap/Struct/Marker.elm b/src/shared/battle-map/BattleMap/Struct/Marker.elm index 2493b5e..21a1731 100644 --- a/src/shared/battle-map/BattleMap/Struct/Marker.elm +++ b/src/shared/battle-map/BattleMap/Struct/Marker.elm @@ -21,25 +21,61 @@ import BattleMap.Struct.Location -------------------------------------------------------------------------------- -- TYPES ----------------------------------------------------------------------- -------------------------------------------------------------------------------- +type alias MeleeAttackZoneStruct = + { + character_ix : Int + } + +type alias SpawnZoneStruct = + { + player_ix : Int + } + +type DataType = + MeleeAttackZone MeleeAttackZoneStruct + | SpawnZone SpawnZoneStruct + | None + type alias Type = { - permissions : (Set.Set String), - locations : (Set.Set BattleMap.Struct.Location.Ref) + locations : (Set.Set BattleMap.Struct.Location.Ref), + data : DataType } -------------------------------------------------------------------------------- -- LOCAL ----------------------------------------------------------------------- -------------------------------------------------------------------------------- +decoder_internals : String -> (Json.Decode.Decoder DataType) +decoder_internals t = + case t of + "matk" -> + (Json.Decode.map + (\e -> (MeleeAttackZone e)) + (Json.Decode.map + MeleeAttackZoneStruct + (Json.Decode.field "cix" (Json.Decode.int)) + ) + ) + + "spawn" -> + (Json.Decode.map + (\e -> (SpawnZone e)) + (Json.Decode.map + SpawnZoneStruct + (Json.Decode.field "pix" (Json.Decode.int)) + ) + ) + + _ -> (Json.Decode.succeed None) -------------------------------------------------------------------------------- -- EXPORTED -------------------------------------------------------------------- -------------------------------------------------------------------------------- - new : Type new = { - permissions = (Set.empty), - locations = (Set.empty) + locations = (Set.empty), + data = None } get_locations : Type -> (Set.Set BattleMap.Struct.Location.Ref) @@ -49,20 +85,12 @@ set_locations : (Set.Set BattleMap.Struct.Location.Ref) -> Type -> Type set_locations locations marker = {marker | locations = locations} is_in_locations : BattleMap.Struct.Location.Ref -> Type -> Bool -is_in_locations loc_ref marker = - (Set.member loc_ref marker.locations) +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 @@ -75,19 +103,16 @@ decoder = ) ) ) + (Json.Decode.andThen + (decoder_internals) + (Json.Decode.field "t" (Json.Decode.string)) + ) ) 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 @@ -98,6 +123,34 @@ encode marker = ) (Set.toList marker.locations) ) + ), + ( + "d", + ( + case marker.data of + SpawnZone zone -> + (Json.Encode.object + [ + ("t", (Json.Encode.string "spawn")), + ("pix", (Json.Encode.int zone.player_ix)) + ] + ) + + MeleeAttackZone zone -> + (Json.Encode.object + [ + ("t", (Json.Encode.string "matk")), + ("cix", (Json.Encode.int zone.character_ix)) + ] + ) + + None -> + (Json.Encode.object + [ + ("t", (Json.Encode.string "none")) + ] + ) + ) ) ] ) -- cgit v1.2.3-70-g09d2