summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNathanael Sensfelder <SpamShield0@MultiAgentSystems.org>2017-09-27 10:31:16 +0200
committerNathanael Sensfelder <SpamShield0@MultiAgentSystems.org>2017-09-27 10:31:16 +0200
commit2c9b2af9ac011a871c5c02d3e2258fca73a98880 (patch)
tree653db3959f444f1065f05658650c6ec81863d627 /elm/battlemap/src/Battlemap.elm
parent33e57128d48a012533c42635f52037fcdedd4c56 (diff)
Splits client and server into two repositories.
Diffstat (limited to 'elm/battlemap/src/Battlemap.elm')
-rw-r--r--elm/battlemap/src/Battlemap.elm91
1 files changed, 91 insertions, 0 deletions
diff --git a/elm/battlemap/src/Battlemap.elm b/elm/battlemap/src/Battlemap.elm
new file mode 100644
index 0000000..309b538
--- /dev/null
+++ b/elm/battlemap/src/Battlemap.elm
@@ -0,0 +1,91 @@
+module Battlemap exposing
+ (
+ Type,
+ apply_to_tile,
+ apply_to_tile_unsafe,
+ has_location,
+ apply_to_all_tiles
+ )
+
+import Array
+
+import Battlemap.Tile
+import Battlemap.Direction
+import Battlemap.Location
+
+type alias Type =
+ {
+ width : Int,
+ height : Int,
+ content : (Array.Array Battlemap.Tile.Type)
+ }
+
+location_to_index : Type -> Battlemap.Location.Type -> Int
+location_to_index bmap loc =
+ ((loc.y * bmap.width) + loc.x)
+
+has_location : Type -> Battlemap.Location.Type -> Bool
+has_location bmap loc =
+ (
+ (loc.x >= 0)
+ && (loc.y >= 0)
+ && (loc.x < bmap.width)
+ && (loc.y < bmap.height)
+ )
+
+apply_to_all_tiles : (
+ Type -> (Battlemap.Tile.Type -> Battlemap.Tile.Type) -> Type
+ )
+apply_to_all_tiles bmap fun =
+ {bmap |
+ content = (Array.map fun bmap.content)
+ }
+
+apply_to_tile : (
+ Type ->
+ Battlemap.Location.Type ->
+ (Battlemap.Tile.Type -> Battlemap.Tile.Type) ->
+ (Maybe Type)
+ )
+apply_to_tile bmap loc fun =
+ let
+ index = (location_to_index bmap loc)
+ at_index = (Array.get index bmap.content)
+ in
+ case at_index of
+ Nothing ->
+ Nothing
+ (Just tile) ->
+ (Just
+ {bmap |
+ content =
+ (Array.set
+ index
+ (fun tile)
+ bmap.content
+ )
+ }
+ )
+
+apply_to_tile_unsafe : (
+ Type ->
+ Battlemap.Location.Type ->
+ (Battlemap.Tile.Type -> Battlemap.Tile.Type) ->
+ Type
+ )
+apply_to_tile_unsafe bmap loc fun =
+ let
+ index = (location_to_index bmap loc)
+ at_index = (Array.get index bmap.content)
+ in
+ case at_index of
+ Nothing -> bmap
+ (Just tile) ->
+ {bmap |
+ content =
+ (Array.set
+ index
+ (fun tile)
+ bmap.content
+ )
+ }