From e406ed71954166f0d71294a9ca8a9527df98265b Mon Sep 17 00:00:00 2001 From: nsensfel Date: Mon, 20 Nov 2017 13:11:08 +0100 Subject: Tiles are ref by IDs, not (icon, cost) tuples. --- src/battlemap/src/Data/Tile.elm | 15 ++++++++++ .../src/Model/HandleServerReply/SetMap.elm | 32 ++++++++-------------- 2 files changed, 27 insertions(+), 20 deletions(-) create mode 100644 src/battlemap/src/Data/Tile.elm (limited to 'src') diff --git a/src/battlemap/src/Data/Tile.elm b/src/battlemap/src/Data/Tile.elm new file mode 100644 index 0000000..f87cb07 --- /dev/null +++ b/src/battlemap/src/Data/Tile.elm @@ -0,0 +1,15 @@ +module Data.Tile exposing (..) + +import Constants.Movement + +get_icon : Int -> String +get_icon i = + toString(i) + +get_cost : Int -> Int +get_cost i = + if (i <= 200) + then + i + else + Constants.Movement.cost_when_out_of_bounds diff --git a/src/battlemap/src/Model/HandleServerReply/SetMap.elm b/src/battlemap/src/Model/HandleServerReply/SetMap.elm index f07e9d7..9f422f1 100644 --- a/src/battlemap/src/Model/HandleServerReply/SetMap.elm +++ b/src/battlemap/src/Model/HandleServerReply/SetMap.elm @@ -9,6 +9,8 @@ import Json.Decode import Battlemap import Battlemap.Tile +import Data.Tile + import Model -------------------------------------------------------------------------------- @@ -18,28 +20,20 @@ type alias MapData = { width : Int, height : Int, - content : (List (List Int)) + content : (List Int) } -------------------------------------------------------------------------------- -- LOCAL ----------------------------------------------------------------------- -------------------------------------------------------------------------------- -deserialize_tile : Int -> Int -> (List Int) -> Battlemap.Tile.Type -deserialize_tile map_width index data = - case data of - [icon_id, cost] -> - (Battlemap.Tile.new - (index % map_width) - (index // map_width) - (toString icon_id) - cost - ) - - _ -> - (Battlemap.Tile.error_tile - (index % map_width) - (index // map_width) - ) +deserialize_tile : Int -> Int -> Int -> Battlemap.Tile.Type +deserialize_tile map_width index id = + (Battlemap.Tile.new + (index % map_width) + (index // map_width) + (Data.Tile.get_icon id) + (Data.Tile.get_cost id) + ) -------------------------------------------------------------------------------- -- EXPORTED -------------------------------------------------------------------- @@ -53,9 +47,7 @@ apply_to model serialized_map = (Json.Decode.field "height" Json.Decode.int) (Json.Decode.field "content" - (Json.Decode.list - (Json.Decode.list Json.Decode.int) - ) + (Json.Decode.list Json.Decode.int) ) ) serialized_map -- cgit v1.2.3-70-g09d2