From 9a2d8f37dea8e14afa57affb135def13954df547 Mon Sep 17 00:00:00 2001 From: Nathanael Sensfelder Date: Fri, 15 Sep 2017 09:52:54 +0200 Subject: Satisfied with Elm so far, let's go with it. --- client/elm/battlemap/src/Battlemap.elm | 47 ++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 client/elm/battlemap/src/Battlemap.elm (limited to 'client/elm/battlemap/src/Battlemap.elm') diff --git a/client/elm/battlemap/src/Battlemap.elm b/client/elm/battlemap/src/Battlemap.elm new file mode 100644 index 0000000..dbf797a --- /dev/null +++ b/client/elm/battlemap/src/Battlemap.elm @@ -0,0 +1,47 @@ +module Battlemap exposing (Battlemap, random, apply_to_tile) + +import Array exposing (Array, set, get) + +import Battlemap.Tile exposing (Tile, generate) +import Battlemap.Direction exposing (..) +import Battlemap.Location exposing (..) + +type alias Battlemap = + { + width : Int, + height : Int, + content : (Array Tile) + } + +random : Battlemap +random = + { + width = 6, + height = 6, + content = (generate 6 6) + } + +location_to_index : Battlemap -> Location -> Int +location_to_index bmap loc = + ((loc.y * bmap.width) + loc.x) + +apply_to_tile : Battlemap -> Location -> (Tile -> Tile) -> (Maybe Battlemap) +apply_to_tile bmap loc fun = + let + index = (location_to_index bmap loc) + at_index = (get index bmap.content) + in + case at_index of + Nothing -> + Nothing + (Just tile) -> + (Just + {bmap | + content = + (set + index + (fun tile) + bmap.content + ) + } + ) -- cgit v1.2.3-70-g09d2