aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornsensfel <SpamShield0@noot-noot.org>2019-05-07 17:23:44 +0200
committernsensfel <SpamShield0@noot-noot.org>2019-05-07 17:23:44 +0200
commitaf452e14397afb04d207628f568238a09989478d (patch)
tree7e199f3991166aa56b68f61e3f36ae33e0b9c995
parent30d48f413b6a2178631ca20a4381c8b4e6bcd24d (diff)
downloadtacticians-client-af452e14397afb04d207628f568238a09989478d.zip
tacticians-client-af452e14397afb04d207628f568238a09989478d.tar.bz2
Working on markers...
-rw-r--r--src/shared/battle-map/BattleMap/Struct/Marker.elm95
1 files 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,21 +85,13 @@ 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
(Set.fromList)
@@ -75,6 +103,10 @@ decoder =
)
)
)
+ (Json.Decode.andThen
+ (decoder_internals)
+ (Json.Decode.field "t" (Json.Decode.string))
+ )
)
encode : Type -> Json.Encode.Value
@@ -82,13 +114,6 @@ encode marker =
(Json.Encode.object
[
(
- "p",
- (Json.Encode.list
- (Json.Encode.string)
- (Set.toList marker.permissions)
- )
- ),
- (
"l",
(Json.Encode.list
(\e ->
@@ -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"))
+ ]
+ )
+ )
)
]
)