summaryrefslogtreecommitdiff |
diff options
-rw-r--r-- | src/battle/src/Comm/SetMap.elm | 2 | ||||
-rw-r--r-- | src/map-editor/src/Comm/SetMap.elm | 15 | ||||
-rw-r--r-- | src/map-editor/src/Struct/Location.elm | 13 | ||||
-rw-r--r-- | src/map-editor/src/Struct/MapMarker.elm | 97 |
4 files changed, 122 insertions, 5 deletions
diff --git a/src/battle/src/Comm/SetMap.elm b/src/battle/src/Comm/SetMap.elm index 407d214..e1cc565 100644 --- a/src/battle/src/Comm/SetMap.elm +++ b/src/battle/src/Comm/SetMap.elm @@ -5,7 +5,7 @@ import Dict import Json.Decode --- Map ------------------------------------------------------------------------- +-- Battle ---------------------------------------------------------------------- import Constants.Movement import Struct.Map diff --git a/src/map-editor/src/Comm/SetMap.elm b/src/map-editor/src/Comm/SetMap.elm index 5fceea5..5d778d6 100644 --- a/src/map-editor/src/Comm/SetMap.elm +++ b/src/map-editor/src/Comm/SetMap.elm @@ -1,12 +1,15 @@ module Comm.SetMap exposing (decode) -- Elm ------------------------------------------------------------------------- +import Dict + import Json.Decode -- Map ------------------------------------------------------------------------- import Constants.Movement import Struct.Map +import Struct.MapMarker import Struct.ServerReply import Struct.Tile @@ -18,7 +21,7 @@ type alias MapData = w : Int, h : Int, t : (List (List String)), - m : (Dict.Dict String (List Struct.Location.Type)) + m : (Dict.Dict String Struct.MapMarker.Type) } -------------------------------------------------------------------------------- @@ -94,13 +97,19 @@ decode : (Json.Decode.Decoder Struct.ServerReply.Type) decode = (Json.Decode.map internal_decoder - (Json.Decode.map3 - MapData + (Json.Decode.map4 MapData (Json.Decode.field "w" Json.Decode.int) (Json.Decode.field "h" Json.Decode.int) (Json.Decode.field "t" (Json.Decode.list (Json.Decode.list Json.Decode.string)) ) + (Json.Decode.field + "m" + (Json.Decode.map + (Dict.fromList) + (Json.Decode.keyValuePairs (Struct.MapMarker.decoder)) + ) + ) ) ) diff --git a/src/map-editor/src/Struct/Location.elm b/src/map-editor/src/Struct/Location.elm index 84025cd..dd66c5c 100644 --- a/src/map-editor/src/Struct/Location.elm +++ b/src/map-editor/src/Struct/Location.elm @@ -4,7 +4,9 @@ module Struct.Location exposing (..) import Json.Decode import Json.Decode.Pipeline --- Battlemap ------------------------------------------------------------------- +import Json.Encode + +-- Map Editor ------------------------------------------------------------------ import Struct.Direction -------------------------------------------------------------------------------- @@ -86,3 +88,12 @@ decoder = |> (Json.Decode.Pipeline.required "x" Json.Decode.int) |> (Json.Decode.Pipeline.required "y" Json.Decode.int) ) + +encode : Type -> Json.Encode.Value +encode loc = + (Json.Encode.object + [ + ( "x", (Json.Encode.int loc.x) ), + ( "y", (Json.Encode.int loc.y) ) + ] + ) diff --git a/src/map-editor/src/Struct/MapMarker.elm b/src/map-editor/src/Struct/MapMarker.elm new file mode 100644 index 0000000..7b3e5e0 --- /dev/null +++ b/src/map-editor/src/Struct/MapMarker.elm @@ -0,0 +1,97 @@ +module Struct.MapMarker exposing + ( + Type, + new, + get_locations, + is_in_locations, + decoder, + encode + ) + +-- Elm ------------------------------------------------------------------------- +import Set +import Json.Decode +import Json.Encode +import List + +-- Battle ---------------------------------------------------------------------- +import Struct.Location + +-------------------------------------------------------------------------------- +-- TYPES ----------------------------------------------------------------------- +-------------------------------------------------------------------------------- +type alias Type = + { + permissions : (Set.Set String), + locations : (Set.Set Struct.Location.Ref) + } + +-------------------------------------------------------------------------------- +-- LOCAL ----------------------------------------------------------------------- +-------------------------------------------------------------------------------- + +-------------------------------------------------------------------------------- +-- EXPORTED -------------------------------------------------------------------- +-------------------------------------------------------------------------------- + +new : Type +new = + { + permissions = (Set.empty), + locations = (Set.empty) + } + +get_locations : Type -> (Set.Set Struct.Location.Ref) +get_locations marker = marker.locations + +is_in_locations : 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 + (Struct.Location.get_ref) + (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 -> + (Struct.Location.encode (Struct.Location.from_ref e)) + ) + (Set.toList marker.locations) + ) + ) + ] + ) |