summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornsensfel <SpamShield0@noot-noot.org>2019-02-26 18:04:55 +0100
committernsensfel <SpamShield0@noot-noot.org>2019-02-26 18:04:55 +0100
commit3d945fe5726bf8da486973328a5e8f58f15d3663 (patch)
tree86fd707fe51baad576302d90ab79ed6bf89c063d
parent12f4b4b01426871577c620df6060c946866131a4 (diff)
Splits Tile & TileInstance (Map Editor only).
-rw-r--r--src/map-editor/src/Comm/SendMapUpdate.elm28
-rw-r--r--src/map-editor/src/Comm/SetMap.elm49
-rw-r--r--src/map-editor/src/Struct/Tile.elm191
-rw-r--r--src/map-editor/src/Struct/TileInstance.elm70
-rw-r--r--src/map-editor/src/Struct/TilePattern.elm11
-rw-r--r--src/map-editor/src/Update/PrettifySelectedTiles.elm2
-rw-r--r--src/map-editor/src/Update/SetToolboxTemplate.elm1
-rw-r--r--src/map-editor/src/View/Map/Tile.elm5
-rw-r--r--src/map-editor/src/View/SubMenu/Tiles.elm3
9 files changed, 81 insertions, 279 deletions
diff --git a/src/map-editor/src/Comm/SendMapUpdate.elm b/src/map-editor/src/Comm/SendMapUpdate.elm
index c324ee5..d2ae2c9 100644
--- a/src/map-editor/src/Comm/SendMapUpdate.elm
+++ b/src/map-editor/src/Comm/SendMapUpdate.elm
@@ -13,7 +13,7 @@ import Comm.Send
import Struct.Event
import Struct.Map
import Struct.Model
-import Struct.Tile
+import Struct.TileInstance
--------------------------------------------------------------------------------
-- TYPES ------------------------------------------------------------------------
@@ -22,30 +22,6 @@ import Struct.Tile
--------------------------------------------------------------------------------
-- LOCAL -----------------------------------------------------------------------
--------------------------------------------------------------------------------
-encode_tile_border_values : Struct.Tile.Border -> (List String)
-encode_tile_border_values border =
- [
- (Struct.Tile.get_border_type_id border),
- (Struct.Tile.get_border_variant_id border)
- ]
-
-encode_tile_instance : Struct.Tile.Instance -> Json.Encode.Value
-encode_tile_instance tile_inst =
- (Json.Encode.list
- (Json.Encode.string)
- (
- [
- (Struct.Tile.get_type_id tile_inst),
- (Struct.Tile.get_variant_id tile_inst)
- ]
- ++
- (List.concatMap
- (encode_tile_border_values)
- (Struct.Tile.get_borders tile_inst)
- )
- )
- )
-
encode_map : Struct.Model.Type -> (Maybe Json.Encode.Value)
encode_map model =
(Just
@@ -59,7 +35,7 @@ encode_map model =
(
"t",
(Json.Encode.list
- (encode_tile_instance)
+ (Struct.TileInstance.encode)
(Array.toList (Struct.Map.get_tiles model.map))
)
)
diff --git a/src/map-editor/src/Comm/SetMap.elm b/src/map-editor/src/Comm/SetMap.elm
index 62e33a4..06fa34c 100644
--- a/src/map-editor/src/Comm/SetMap.elm
+++ b/src/map-editor/src/Comm/SetMap.elm
@@ -21,55 +21,6 @@ import Struct.TileInstance
--------------------------------------------------------------------------------
-- LOCAL -----------------------------------------------------------------------
--------------------------------------------------------------------------------
-deserialize_tile_borders : (
- (List String) ->
- (List Struct.Tile.Border) ->
- (List Struct.Tile.Border)
- )
-deserialize_tile_borders rem_ints current_borders =
- case rem_ints of
- [] -> (List.reverse current_borders)
- (a :: (b :: c)) ->
- (deserialize_tile_borders
- c
- ((Struct.Tile.new_border a b) :: current_borders)
- )
-
- _ -> []
-
-deserialize_tile_instance : (
- Int ->
- Int ->
- (List String) ->
- Struct.Tile.Instance
- )
-deserialize_tile_instance map_width index t =
- case t of
- (a :: (b :: c)) ->
- (Struct.Tile.new_instance
- {
- x = (modBy map_width index),
- y = (index // map_width)
- }
- a
- b
- Constants.Movement.cost_when_out_of_bounds
- "-1"
- (deserialize_tile_borders c [])
- )
-
- _ ->
- (Struct.Tile.new_instance
- {
- x = (modBy map_width index),
- y = (index // map_width)
- }
- "0"
- "0"
- Constants.Movement.cost_when_out_of_bounds
- "-1"
- []
- )
--------------------------------------------------------------------------------
-- EXPORTED --------------------------------------------------------------------
diff --git a/src/map-editor/src/Struct/Tile.elm b/src/map-editor/src/Struct/Tile.elm
index d2c75fc..04896da 100644
--- a/src/map-editor/src/Struct/Tile.elm
+++ b/src/map-editor/src/Struct/Tile.elm
@@ -4,29 +4,11 @@ module Struct.Tile exposing
VariantID,
FamilyID,
Type,
- Instance,
- Border,
new,
- clone_instance,
- new_instance,
- default_instance,
- new_border,
- error_tile_instance,
get_id,
get_name,
- set_borders,
- get_borders,
- get_border_type_id,
- get_border_variant_id,
get_cost,
- get_instance_cost,
- get_location,
- get_type_id,
get_family,
- get_instance_family,
- get_variant_id,
- get_local_variant_ix,
- solve_tile_instance,
decoder
)
@@ -49,15 +31,6 @@ type alias Ref = String
type alias VariantID = String
type alias FamilyID = String
-type alias PartiallyDecoded =
- {
- id : Ref,
- nam : String,
- ct : Int,
- fa : FamilyID,
- de : Int
- }
-
type alias Type =
{
id : Ref,
@@ -67,52 +40,9 @@ type alias Type =
depth : Int
}
-type alias Border =
- {
- type_id : Ref,
- variant_id : VariantID
- }
-
-type alias Instance =
- {
- location : Struct.Location.Type,
- crossing_cost : Int,
- family : FamilyID,
- type_id : Ref,
- variant_id : VariantID,
- borders : (List Border)
- }
-
--------------------------------------------------------------------------------
-- LOCAL -----------------------------------------------------------------------
--------------------------------------------------------------------------------
-noise_function : Int -> Int -> Int -> Int
-noise_function a b c =
- let
- af = (toFloat a)
- bf = (toFloat b)
- cf = (toFloat c)
- (df, ef) = (toPolar (af, bf))
- (ff, gf) = (toPolar (bf, af))
- (hf, jf) = (toPolar (bf, cf))
- (kf, lf) = (toPolar (cf, bf))
- (mf, nf) = (toPolar (af, cf))
- (qf, rf) = (toPolar (cf, af))
- (resA, resB) = (fromPolar ((df + qf), (ef + nf)))
- (resC, resD) = (fromPolar ((hf + mf), (jf + gf)))
- (resE, resF) = (toPolar ((resA - resC), (resB - resD)))
- in
- (round (resE - resF))
-
-finish_decoding : PartiallyDecoded -> Type
-finish_decoding add_tile =
- {
- id = add_tile.id,
- name = add_tile.nam,
- crossing_cost = add_tile.ct,
- family = add_tile.fa,
- depth = add_tile.de
- }
--------------------------------------------------------------------------------
-- EXPORTED --------------------------------------------------------------------
@@ -127,132 +57,25 @@ new id name crossing_cost family depth =
depth = depth
}
-clone_instance : Struct.Location.Type -> Instance -> Instance
-clone_instance loc inst = {inst | location = loc}
-
-new_border : Ref -> VariantID -> Border
-new_border type_id variant_id =
- {
- type_id = type_id,
- variant_id = variant_id
- }
-
-default_instance : Type -> Instance
-default_instance tile =
- (new_instance
- {x = 0, y = 0}
- tile.id
- "0"
- tile.crossing_cost
- tile.family
- []
- )
-
-new_instance : (
- Struct.Location.Type ->
- Ref ->
- VariantID ->
- Int ->
- FamilyID ->
- (List Border) ->
- Instance
- )
-new_instance location type_id variant_id crossing_cost family borders =
- {
- location = location,
- type_id = type_id,
- variant_id = variant_id,
- crossing_cost = crossing_cost,
- family = family,
- borders = borders
- }
-
-error_tile_instance : Int -> Int -> Instance
-error_tile_instance x y =
- {
- location = {x = x, y = y},
- type_id = "0",
- variant_id = "0",
- family = "0",
- crossing_cost = Constants.Movement.cost_when_out_of_bounds,
- borders = []
- }
-
get_id : Type -> Ref
get_id tile = tile.id
get_cost : Type -> Int
get_cost tile = tile.crossing_cost
-get_instance_cost : Instance -> Int
-get_instance_cost tile_inst = tile_inst.crossing_cost
-
get_name : Type -> String
get_name tile = tile.name
-get_location : Instance -> Struct.Location.Type
-get_location tile_inst = tile_inst.location
-
-get_type_id : Instance -> Ref
-get_type_id tile_inst = tile_inst.type_id
-
-get_border_type_id : Border -> Ref
-get_border_type_id tile_border = tile_border.type_id
-
get_family : Type -> FamilyID
get_family tile = tile.family
-set_borders : (List Border) -> Instance -> Instance
-set_borders borders tile_inst = {tile_inst | borders = borders}
-
-get_borders : Instance -> (List Border)
-get_borders tile_inst = tile_inst.borders
-
-get_instance_family : Instance -> FamilyID
-get_instance_family tile_inst = tile_inst.family
-
-get_variant_id : Instance -> VariantID
-get_variant_id tile_inst = tile_inst.variant_id
-
-get_border_variant_id : Border -> VariantID
-get_border_variant_id tile_border = tile_border.variant_id
-
-get_local_variant_ix : Instance -> Int
-get_local_variant_ix tile_inst =
- (modBy
- Constants.UI.local_variants_per_tile
- (noise_function
- tile_inst.location.x
- tile_inst.location.y
- tile_inst.crossing_cost
- )
- )
-
-solve_tile_instance : (Dict.Dict Ref Type) -> Instance -> Instance
-solve_tile_instance tiles tile_instance =
- case (Dict.get tile_instance.type_id tiles) of
- (Just tile) ->
- {tile_instance |
- crossing_cost = tile.crossing_cost,
- family = tile.family
- }
-
- Nothing ->
- {tile_instance |
- crossing_cost = -1,
- family = "-1"
- }
-
decoder : (Json.Decode.Decoder Type)
decoder =
- (Json.Decode.map
- (finish_decoding)
- (Json.Decode.succeed
- PartiallyDecoded
- |> (Json.Decode.Pipeline.required "id" Json.Decode.string)
- |> (Json.Decode.Pipeline.required "nam" Json.Decode.string)
- |> (Json.Decode.Pipeline.required "ct" Json.Decode.int)
- |> (Json.Decode.Pipeline.required "fa" Json.Decode.string)
- |> (Json.Decode.Pipeline.required "de" Json.Decode.int)
- )
+ (Json.Decode.succeed
+ Type
+ |> (Json.Decode.Pipeline.required "id" Json.Decode.string)
+ |> (Json.Decode.Pipeline.required "nam" Json.Decode.string)
+ |> (Json.Decode.Pipeline.required "ct" Json.Decode.int)
+ |> (Json.Decode.Pipeline.required "fa" Json.Decode.string)
+ |> (Json.Decode.Pipeline.required "de" Json.Decode.int)
)
diff --git a/src/map-editor/src/Struct/TileInstance.elm b/src/map-editor/src/Struct/TileInstance.elm
index 6ea4c4a..4d03630 100644
--- a/src/map-editor/src/Struct/TileInstance.elm
+++ b/src/map-editor/src/Struct/TileInstance.elm
@@ -3,19 +3,30 @@ module Struct.TileInstance exposing
Type,
Border,
clone,
+ get_location,
get_class_id,
get_family,
+ get_cost,
default,
+ set_borders,
+ get_borders,
new_border,
+ get_variant_id,
+ get_border_variant_id,
+ get_border_class_id,
+ get_local_variant_ix,
error,
solve,
set_location_from_index,
- decoder
+ decoder,
+ encode
)
-- Elm -------------------------------------------------------------------------
import Dict
+import Json.Encode
+
import Json.Decode
import Json.Decode.Pipeline
@@ -34,7 +45,7 @@ type alias Type =
location : Struct.Location.Type,
crossing_cost : Int,
family : Struct.Tile.FamilyID,
- type_id : Struct.Tile.Ref,
+ class_id : Struct.Tile.Ref,
variant_id : Struct.Tile.VariantID,
triggers : (List String),
borders : (List Border)
@@ -42,7 +53,7 @@ type alias Type =
type alias Border =
{
- type_id : Struct.Tile.Ref,
+ class_id : Struct.Tile.Ref,
variant_id : Struct.Tile.VariantID
}
@@ -74,9 +85,9 @@ clone : Struct.Location.Type -> Type -> Type
clone loc inst = {inst | location = loc}
new_border : Struct.Tile.Ref -> Struct.Tile.VariantID -> Border
-new_border type_id variant_id =
+new_border class_id variant_id =
{
- type_id = type_id,
+ class_id = class_id,
variant_id = variant_id
}
@@ -84,7 +95,7 @@ default : Struct.Tile.Type -> Type
default tile =
{
location = {x = 0, y = 0},
- type_id = (Struct.Tile.get_id tile),
+ class_id = (Struct.Tile.get_id tile),
variant_id = "0",
crossing_cost = (Struct.Tile.get_cost tile),
family = (Struct.Tile.get_family tile),
@@ -96,7 +107,7 @@ error : Int -> Int -> Type
error x y =
{
location = {x = x, y = y},
- type_id = "0",
+ class_id = "0",
variant_id = "0",
family = "0",
crossing_cost = Constants.Movement.cost_when_out_of_bounds,
@@ -105,7 +116,7 @@ error x y =
}
get_class_id : Type -> Struct.Tile.Ref
-get_class_id inst = inst.type_id
+get_class_id inst = inst.class_id
get_cost : Type -> Int
get_cost inst = inst.crossing_cost
@@ -141,7 +152,7 @@ get_local_variant_ix tile_inst =
solve : (Dict.Dict Struct.Tile.Ref Struct.Tile.Type) -> Type -> Type
solve tiles tile_inst =
- case (Dict.get tile_inst.type_id tiles) of
+ case (Dict.get tile_inst.class_id tiles) of
(Just tile) ->
{tile_inst |
crossing_cost = (Struct.Tile.get_cost tile),
@@ -165,7 +176,7 @@ list_to_borders list borders =
(a :: (b :: c)) ->
(list_to_borders
c
- ({ type_id = a, variant_id = b } :: borders)
+ ({ class_id = a, variant_id = b } :: borders)
)
_ -> (List.reverse borders)
@@ -197,8 +208,8 @@ decoder =
(Json.Decode.field "b" (Json.Decode.list (Json.Decode.string)))
)
-get_border_type_id : Border -> Struct.Tile.Ref
-get_border_type_id tile_border = tile_border.type_id
+get_border_class_id : Border -> Struct.Tile.Ref
+get_border_class_id tile_border = tile_border.class_id
set_location_from_index : Int -> Int -> Type -> Type
set_location_from_index map_width index tile_inst =
@@ -209,3 +220,38 @@ set_location_from_index map_width index tile_inst =
y = (index // map_width)
}
}
+
+encode : Type -> Json.Encode.Value
+encode tile_inst =
+ (Json.Encode.object
+ [
+ (
+ "b",
+ (Json.Encode.list
+ (Json.Encode.string)
+ (
+ tile_inst.class_id
+ ::
+ (
+ tile_inst.variant_id
+ ::
+ (List.concatMap
+ (\border ->
+ [
+ border.class_id,
+ border.variant_id
+ ]
+ )
+ tile_inst.borders
+ )
+ )
+ )
+ )
+ ),
+ (
+ "t",
+ (Json.Encode.list (Json.Encode.string) tile_inst.triggers)
+ )
+ ]
+ )
+
diff --git a/src/map-editor/src/Struct/TilePattern.elm b/src/map-editor/src/Struct/TilePattern.elm
index 71a3af1..d2d005c 100644
--- a/src/map-editor/src/Struct/TilePattern.elm
+++ b/src/map-editor/src/Struct/TilePattern.elm
@@ -16,8 +16,9 @@ import List
import Json.Decode
import Json.Decode.Pipeline
--- Battlemap -------------------------------------------------------------------
+-- Map Editor ------------------------------------------------------------------
import Struct.Tile
+import Struct.TileInstance
--------------------------------------------------------------------------------
-- TYPES -----------------------------------------------------------------------
@@ -38,12 +39,16 @@ type alias Type =
--------------------------------------------------------------------------------
-- EXPORTED --------------------------------------------------------------------
--------------------------------------------------------------------------------
-get_pattern_for : Struct.Tile.FamilyID -> (List Struct.Tile.Instance) -> Actual
+get_pattern_for : (
+ Struct.Tile.FamilyID ->
+ (List Struct.TileInstance.Type) ->
+ Actual
+ )
get_pattern_for source_fa neighborhood =
(List.foldl
(\t -> \acc ->
let
- t_fa = (Struct.Tile.get_instance_family t)
+ t_fa = (Struct.TileInstance.get_family t)
in
if ((t_fa == "-1") || (t_fa == source_fa))
then (acc ++ "1")
diff --git a/src/map-editor/src/Update/PrettifySelectedTiles.elm b/src/map-editor/src/Update/PrettifySelectedTiles.elm
index 625c47c..f409da8 100644
--- a/src/map-editor/src/Update/PrettifySelectedTiles.elm
+++ b/src/map-editor/src/Update/PrettifySelectedTiles.elm
@@ -23,7 +23,7 @@ import Util.List
neighborhood_tile_instances : (
Struct.Location.Type ->
Struct.Map.Type ->
- (List Struct.Tile.Instance)
+ (List Struct.TileInstance.Type)
)
neighborhood_tile_instances loc map =
(List.map
diff --git a/src/map-editor/src/Update/SetToolboxTemplate.elm b/src/map-editor/src/Update/SetToolboxTemplate.elm
index 9ec374d..439a8e7 100644
--- a/src/map-editor/src/Update/SetToolboxTemplate.elm
+++ b/src/map-editor/src/Update/SetToolboxTemplate.elm
@@ -1,6 +1,7 @@
module Update.SetToolboxTemplate exposing (apply_to)
-- Elm -------------------------------------------------------------------------
+import Dict
-- Map Editor ------------------------------------------------------------------
import Struct.Event
diff --git a/src/map-editor/src/View/Map/Tile.elm b/src/map-editor/src/View/Map/Tile.elm
index 996dd3a..b5e3505 100644
--- a/src/map-editor/src/View/Map/Tile.elm
+++ b/src/map-editor/src/View/Map/Tile.elm
@@ -11,7 +11,6 @@ import Constants.IO
import Struct.Event
import Struct.Location
-import Struct.Tile
import Struct.TileInstance
import Struct.Toolbox
@@ -20,7 +19,7 @@ import Struct.Toolbox
--------------------------------------------------------------------------------
get_layer_html : (
Int ->
- Struct.TileInstancec.Border ->
+ Struct.TileInstance.Border ->
(Html.Html Struct.Event.Type)
)
get_layer_html index border =
@@ -90,7 +89,7 @@ get_content_html tile =
::
(List.indexedMap
(get_layer_html)
- (Struct.Tile.get_borders tile)
+ (Struct.TileInstance.get_borders tile)
)
)
)
diff --git a/src/map-editor/src/View/SubMenu/Tiles.elm b/src/map-editor/src/View/SubMenu/Tiles.elm
index 8d97269..5ef324f 100644
--- a/src/map-editor/src/View/SubMenu/Tiles.elm
+++ b/src/map-editor/src/View/SubMenu/Tiles.elm
@@ -11,6 +11,7 @@ import Html.Events
import Struct.Event
import Struct.Model
import Struct.Tile
+import Struct.TileInstance
import View.Map.Tile
@@ -32,7 +33,7 @@ get_icon_html (ref, tile) =
(Struct.Event.TemplateRequested ((Struct.Tile.get_id tile), "0"))
)
]
- (View.Map.Tile.get_content_html (Struct.Tile.default_instance tile))
+ (View.Map.Tile.get_content_html (Struct.TileInstance.default tile))
)
--------------------------------------------------------------------------------