summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNathanael Sensfelder <SpamShield0@MultiAgentSystems.org>2017-09-22 13:46:32 +0200
committerNathanael Sensfelder <SpamShield0@MultiAgentSystems.org>2017-09-22 13:46:32 +0200
commit2d20dc042a386bc9f66bc5f535403227f9acf1b1 (patch)
tree49e529ff4e12841d160627d9853c088ba0dd637b
parent0d5fba42a1597e5a43266c071776e7acf58071e2 (diff)
No more import ... exposing.
It got too confusing.
-rw-r--r--client/elm/battlemap/src/Battlemap.elm55
-rw-r--r--client/elm/battlemap/src/Battlemap/Direction.elm6
-rw-r--r--client/elm/battlemap/src/Battlemap/Html.elm75
-rw-r--r--client/elm/battlemap/src/Battlemap/Location.elm22
-rw-r--r--client/elm/battlemap/src/Battlemap/Navigator.elm88
-rw-r--r--client/elm/battlemap/src/Battlemap/Tile.elm51
-rw-r--r--client/elm/battlemap/src/Character.elm15
-rw-r--r--client/elm/battlemap/src/Main.elm14
-rw-r--r--client/elm/battlemap/src/Model.elm64
-rw-r--r--client/elm/battlemap/src/Shim/Battlemap.elm11
-rw-r--r--client/elm/battlemap/src/Shim/Battlemap/Tile.elm40
-rw-r--r--client/elm/battlemap/src/Shim/Model.elm50
-rw-r--r--client/elm/battlemap/src/Update.elm65
-rw-r--r--client/elm/battlemap/src/View.elm76
14 files changed, 347 insertions, 285 deletions
diff --git a/client/elm/battlemap/src/Battlemap.elm b/client/elm/battlemap/src/Battlemap.elm
index ef24c80..309b538 100644
--- a/client/elm/battlemap/src/Battlemap.elm
+++ b/client/elm/battlemap/src/Battlemap.elm
@@ -1,39 +1,30 @@
module Battlemap exposing
(
- Battlemap,
- random,
+ Type,
apply_to_tile,
apply_to_tile_unsafe,
has_location,
apply_to_all_tiles
)
-import Array exposing (Array, set, get, map)
+import Array
-import Battlemap.Tile exposing (Tile, generate)
-import Battlemap.Direction exposing (Direction(..))
-import Battlemap.Location exposing (Location)
+import Battlemap.Tile
+import Battlemap.Direction
+import Battlemap.Location
-type alias Battlemap =
+type alias Type =
{
width : Int,
height : Int,
- content : (Array Tile)
+ content : (Array.Array Battlemap.Tile.Type)
}
-random : Battlemap
-random =
- {
- width = 6,
- height = 6,
- content = (generate 6 6)
- }
-
-location_to_index : Battlemap -> Location -> Int
+location_to_index : Type -> Battlemap.Location.Type -> Int
location_to_index bmap loc =
((loc.y * bmap.width) + loc.x)
-has_location : Battlemap -> Location -> Bool
+has_location : Type -> Battlemap.Location.Type -> Bool
has_location bmap loc =
(
(loc.x >= 0)
@@ -42,17 +33,24 @@ has_location bmap loc =
&& (loc.y < bmap.height)
)
-apply_to_all_tiles : Battlemap -> (Tile -> Tile) -> Battlemap
+apply_to_all_tiles : (
+ Type -> (Battlemap.Tile.Type -> Battlemap.Tile.Type) -> Type
+ )
apply_to_all_tiles bmap fun =
{bmap |
- content = (map fun bmap.content)
+ content = (Array.map fun bmap.content)
}
-apply_to_tile : Battlemap -> Location -> (Tile -> Tile) -> (Maybe Battlemap)
+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 = (get index bmap.content)
+ at_index = (Array.get index bmap.content)
in
case at_index of
Nothing ->
@@ -61,7 +59,7 @@ apply_to_tile bmap loc fun =
(Just
{bmap |
content =
- (set
+ (Array.set
index
(fun tile)
bmap.content
@@ -69,18 +67,23 @@ apply_to_tile bmap loc fun =
}
)
-apply_to_tile_unsafe : Battlemap -> Location -> (Tile -> Tile) -> Battlemap
+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 = (get index bmap.content)
+ at_index = (Array.get index bmap.content)
in
case at_index of
Nothing -> bmap
(Just tile) ->
{bmap |
content =
- (set
+ (Array.set
index
(fun tile)
bmap.content
diff --git a/client/elm/battlemap/src/Battlemap/Direction.elm b/client/elm/battlemap/src/Battlemap/Direction.elm
index e301177..5aad141 100644
--- a/client/elm/battlemap/src/Battlemap/Direction.elm
+++ b/client/elm/battlemap/src/Battlemap/Direction.elm
@@ -1,13 +1,13 @@
-module Battlemap.Direction exposing (Direction(..), opposite_of)
+module Battlemap.Direction exposing (Type(..), opposite_of)
-type Direction =
+type Type =
None
| Left
| Right
| Up
| Down
-opposite_of : Direction -> Direction
+opposite_of : Type -> Type
opposite_of d =
case d of
Left -> Right
diff --git a/client/elm/battlemap/src/Battlemap/Html.elm b/client/elm/battlemap/src/Battlemap/Html.elm
index dc90ed4..01937e0 100644
--- a/client/elm/battlemap/src/Battlemap/Html.elm
+++ b/client/elm/battlemap/src/Battlemap/Html.elm
@@ -1,52 +1,51 @@
module Battlemap.Html exposing (view)
-import Html exposing (Html, text, table, tr, td)
-import Html.Events exposing (onClick)
+import Array
--- import List as Lt exposing (map)
-import Array as Ay exposing (foldr)
+import Html
+import Html.Events
-import Update exposing (Msg(..))
-import Model exposing (Model)
+import Battlemap
+import Battlemap.Tile
+import Battlemap.Direction
-import Battlemap exposing (Battlemap, random)
-import Battlemap.Tile exposing (Tile)
-import Battlemap.Direction exposing (Direction(..))
+import Update
+import Model
-view_battlemap_cell : Tile -> (Html Msg)
+view_battlemap_cell : Battlemap.Tile.Type -> (Html.Html Update.Type)
view_battlemap_cell t =
case t.char_level of
Nothing ->
- (td
+ (Html.td
[]
[
- (text "[_]"),
- (text
+ (Html.text "[_]"),
+ (Html.text
(
(case t.nav_level of
- Right -> "R"
- Left -> "L"
- Up -> "U"
- Down -> "D"
- None -> (toString t.floor_level)
+ Battlemap.Direction.Right -> "R"
+ Battlemap.Direction.Left -> "L"
+ Battlemap.Direction.Up -> "U"
+ Battlemap.Direction.Down -> "D"
+ Battlemap.Direction.None -> (toString t.floor_level)
)
)
)
]
)
(Just char_id) ->
- (td
- [ (onClick (SelectCharacter char_id)) ]
+ (Html.td
+ [ (Html.Events.onClick (Update.SelectCharacter char_id)) ]
[
- (text ("[" ++ char_id ++ "]")),
- (text
+ (Html.text ("[" ++ char_id ++ "]")),
+ (Html.text
(
(case t.nav_level of
- Right -> "R"
- Left -> "L"
- Up -> "U"
- Down -> "D"
- None -> (toString t.floor_level)
+ Battlemap.Direction.Right -> "R"
+ Battlemap.Direction.Left -> "L"
+ Battlemap.Direction.Up -> "U"
+ Battlemap.Direction.Down -> "D"
+ Battlemap.Direction.None -> (toString t.floor_level)
)
)
)
@@ -55,13 +54,13 @@ view_battlemap_cell t =
type alias GridBuilder =
{
- row : (List (Html Msg)),
- columns : (List (Html Msg)),
+ row : (List (Html.Html Update.Type)),
+ columns : (List (Html.Html Update.Type)),
row_size : Int,
- bmap : Battlemap
+ bmap : Battlemap.Type
}
-foldr_to_html : Tile -> GridBuilder -> GridBuilder
+foldr_to_html : Battlemap.Tile.Type -> GridBuilder -> GridBuilder
foldr_to_html t gb =
if (gb.row_size == gb.bmap.width)
then
@@ -70,7 +69,7 @@ foldr_to_html t gb =
row_size = 1,
columns =
(
- (tr [] gb.row) :: gb.columns
+ (Html.tr [] gb.row) :: gb.columns
)
}
else
@@ -79,7 +78,7 @@ foldr_to_html t gb =
row_size = (gb.row_size + 1)
}
-grid_builder_to_html : GridBuilder -> (List (Html Msg))
+grid_builder_to_html : GridBuilder -> (List (Html.Html Update.Type))
grid_builder_to_html gb =
if (gb.row_size == 0)
then
@@ -91,17 +90,17 @@ grid_builder_to_html gb =
row_size = 0,
columns =
(
- (tr [] gb.row) :: gb.columns
+ (Html.tr [] gb.row) :: gb.columns
)
}
)
-view_battlemap : Battlemap -> (Html Msg)
+view_battlemap : Battlemap.Type -> (Html.Html Update.Type)
view_battlemap battlemap =
- (table
+ (Html.table
[]
(grid_builder_to_html
- (Ay.foldr
+ (Array.foldr
(foldr_to_html)
{
row = [],
@@ -115,6 +114,6 @@ view_battlemap battlemap =
)
-view : Model -> (Html Msg)
+view : Model.Type -> (Html.Html Update.Type)
view m =
(view_battlemap m.battlemap)
diff --git a/client/elm/battlemap/src/Battlemap/Location.elm b/client/elm/battlemap/src/Battlemap/Location.elm
index 5c7bc48..4f70e49 100644
--- a/client/elm/battlemap/src/Battlemap/Location.elm
+++ b/client/elm/battlemap/src/Battlemap/Location.elm
@@ -1,24 +1,24 @@
module Battlemap.Location exposing (..)
-import Battlemap.Direction exposing (Direction(..))
+import Battlemap.Direction
-type alias Location =
+type alias Type =
{
x : Int,
y : Int
}
-type alias LocationRef = (Int, Int)
+type alias Ref = (Int, Int)
-neighbor : Location -> Direction -> Location
+neighbor : Type -> Battlemap.Direction.Type -> Type
neighbor loc dir =
case dir of
- Right -> {loc | x = (loc.x + 1)}
- Left -> {loc | x = (loc.x - 1)}
- Up -> {loc | y = (loc.y - 1)}
- Down -> {loc | y = (loc.y + 1)}
- None -> loc
+ Battlemap.Direction.Right -> {loc | x = (loc.x + 1)}
+ Battlemap.Direction.Left -> {loc | x = (loc.x - 1)}
+ Battlemap.Direction.Up -> {loc | y = (loc.y - 1)}
+ Battlemap.Direction.Down -> {loc | y = (loc.y + 1)}
+ Battlemap.Direction.None -> loc
-to_comparable : Location -> (Int, Int)
-to_comparable l =
+get_ref : Type -> Ref
+get_ref l =
(l.x, l.y)
diff --git a/client/elm/battlemap/src/Battlemap/Navigator.elm b/client/elm/battlemap/src/Battlemap/Navigator.elm
index 3cabf8e..41593c5 100644
--- a/client/elm/battlemap/src/Battlemap/Navigator.elm
+++ b/client/elm/battlemap/src/Battlemap/Navigator.elm
@@ -1,81 +1,87 @@
module Battlemap.Navigator exposing
(
- Navigator,
+ Type,
new_navigator,
reset_navigation,
go
)
-import Set exposing (Set, member, empty, insert, remove)
-import List as Lt exposing (head, tail)
+import Set -- exposing (Set, member, empty, insert, remove)
+import List -- exposing (head, tail)
-import Battlemap exposing (Battlemap, has_location, apply_to_tile)
-import Battlemap.Direction exposing (Direction(..), opposite_of)
-import Battlemap.Tile exposing (Tile, set_direction)
-import Character exposing (Character)
+import Battlemap
+import Battlemap.Direction
+import Battlemap.Location
+import Battlemap.Tile
-import Battlemap.Location exposing
- (
- Location,
- LocationRef,
- neighbor,
- to_comparable
- )
+import Character
-type alias Navigator =
+type alias Type =
{
- current_location : Location,
- visited_locations : (Set LocationRef),
- previous_directions : (List Direction),
+ current_location : Battlemap.Location.Type,
+ visited_locations : (Set.Set Battlemap.Location.Ref),
+ previous_directions : (List Battlemap.Direction.Type),
remaining_points : Int
}
-new_navigator : Location -> Int -> Navigator
+new_navigator : Battlemap.Location.Type -> Int -> Type
new_navigator start points =
{
current_location = start,
- visited_locations = empty,
+ visited_locations = Set.empty,
previous_directions = [],
remaining_points = points
}
-reset_navigation : Tile -> Tile
+reset_navigation : Battlemap.Tile.Type -> Battlemap.Tile.Type
reset_navigation t =
{t |
- nav_level = None
+ nav_level = Battlemap.Direction.None
}
-go : Battlemap -> Navigator -> Direction -> (List Character) -> (Battlemap, Navigator)
+go : (
+ Battlemap.Type ->
+ Type ->
+ Battlemap.Direction.Type ->
+ (List Character.Type) ->
+ (Battlemap.Type, Type)
+ )
go battlemap nav dir char_list =
let
- next_location = (neighbor nav.current_location dir)
- is_occupied = (Lt.any (\c -> (c.location == next_location)) char_list)
+ next_location = (Battlemap.Location.neighbor nav.current_location dir)
+ is_occupied = (List.any (\c -> (c.location == next_location)) char_list)
in
if
(
(not is_occupied)
&& (nav.remaining_points > 0)
- && (has_location battlemap next_location)
+ && (Battlemap.has_location battlemap next_location)
&& (nav.current_location /= next_location)
- && (not (member (to_comparable next_location) nav.visited_locations))
+ &&
+ (not
+ (Set.member
+ (Battlemap.Location.get_ref next_location)
+ nav.visited_locations
+ )
+ )
)
then
(
(case
- (apply_to_tile
+ (Battlemap.apply_to_tile
battlemap
nav.current_location
- (set_direction dir)
+ (Battlemap.Tile.set_direction dir)
)
of
Nothing -> battlemap
(Just bmap0) ->
(case
- (apply_to_tile
+ (Battlemap.apply_to_tile
bmap0
next_location
- (set_direction dir)
+ (Battlemap.Tile.set_direction dir)
)
of
Nothing -> battlemap
@@ -85,8 +91,8 @@ go battlemap nav dir char_list =
{nav |
current_location = next_location,
visited_locations =
- (insert
- (to_comparable nav.current_location)
+ (Set.insert
+ (Battlemap.Location.get_ref nav.current_location)
nav.visited_locations
),
previous_directions = (dir :: nav.previous_directions),
@@ -97,21 +103,23 @@ go battlemap nav dir char_list =
then
case
(
- (Lt.head nav.previous_directions),
- (Lt.tail nav.previous_directions)
+ (List.head nav.previous_directions),
+ (List.tail nav.previous_directions)
)
of
(Nothing, _) -> (battlemap, nav)
(_ , Nothing) -> (battlemap, nav)
((Just prev_dir), (Just prev_dir_list)) ->
- if (dir == (opposite_of prev_dir))
+ if (dir == (Battlemap.Direction.opposite_of prev_dir))
then
(
(case
- (apply_to_tile
+ (Battlemap.apply_to_tile
battlemap
nav.current_location
- (set_direction None)
+ (Battlemap.Tile.set_direction
+ Battlemap.Direction.None
+ )
)
of
Nothing -> battlemap
@@ -120,8 +128,8 @@ go battlemap nav dir char_list =
{nav |
current_location = next_location,
visited_locations =
- (remove
- (to_comparable next_location)
+ (Set.remove
+ (Battlemap.Location.get_ref next_location)
nav.visited_locations
),
previous_directions = prev_dir_list,
diff --git a/client/elm/battlemap/src/Battlemap/Tile.elm b/client/elm/battlemap/src/Battlemap/Tile.elm
index 70268bf..dca7a64 100644
--- a/client/elm/battlemap/src/Battlemap/Tile.elm
+++ b/client/elm/battlemap/src/Battlemap/Tile.elm
@@ -1,55 +1,18 @@
-module Battlemap.Tile exposing (Tile, generate, set_direction)
+module Battlemap.Tile exposing (Type, set_direction)
-import Battlemap.Direction exposing (Direction(..))
-import Character exposing (CharacterRef)
+import Battlemap.Direction
+import Character
-import List exposing (map)
-import Array exposing (Array, fromList)
-import Set exposing (Set)
-
-type alias Tile =
+type alias Type =
{
floor_level : Int,
- nav_level : Direction,
- char_level : (Maybe CharacterRef)
+ nav_level : Battlemap.Direction.Type,
+ char_level : (Maybe Character.Ref)
-- mod_level : (Set TileModifier)
}
-set_direction : Direction -> Tile -> Tile
+set_direction : Battlemap.Direction.Type -> Type -> Type
set_direction d t =
{t |
nav_level = d
}
-
-from_int : Int -> Tile
-from_int i =
- if (i >= 10)
- then
- {
- floor_level = (i - 10),
- nav_level = None,
- char_level = (Just (toString (i - 10)))
- }
- else
- {
- floor_level = i,
- nav_level = None,
- char_level = Nothing
- }
-
-
-generate : Int -> Int -> (Array Tile)
-generate width height =
- (fromList
- (map
- (from_int)
- [
- 10, 1, 1, 2, 2, 2,
- 1, 0, 0, 0, 11, 2,
- 1, 0, 1, 2, 0, 2,
- 3, 0, 3, 4, 0, 4,
- 3, 12, 0, 0, 0, 4,
- 3, 3, 3, 4, 4, 4
- ]
- )
- )
diff --git a/client/elm/battlemap/src/Character.elm b/client/elm/battlemap/src/Character.elm
index 5c64d45..6b6a7c7 100644
--- a/client/elm/battlemap/src/Character.elm
+++ b/client/elm/battlemap/src/Character.elm
@@ -1,18 +1,19 @@
-module Character exposing (Character, CharacterRef, to_comparable)
+module Character exposing (Type, Ref, get_ref)
-import Battlemap.Location exposing (Location)
+import Battlemap.Location
-type alias Character =
+type alias Type =
{
id : String,
name : String,
icon : String,
portrait : String,
- location : Location,
+ location : Battlemap.Location.Type,
movement_points : Int
}
-type alias CharacterRef = String
-to_comparable : Character -> CharacterRef
-to_comparable c =
+type alias Ref = String
+
+get_ref : Type -> Ref
+get_ref c =
c.id
diff --git a/client/elm/battlemap/src/Main.elm b/client/elm/battlemap/src/Main.elm
index d7fb8e2..c92f59c 100644
--- a/client/elm/battlemap/src/Main.elm
+++ b/client/elm/battlemap/src/Main.elm
@@ -1,13 +1,13 @@
-import Html exposing (Html)
-import View exposing (view)
-import Model exposing (model)
-import Update exposing (update)
+import Html
+import View
+import Shim.Model
+import Update
main =
(Html.beginnerProgram
{
- model = model,
- view = view,
- update = update
+ model = Shim.Model.generate,
+ view = View.view,
+ update = Update.update
}
)
diff --git a/client/elm/battlemap/src/Model.elm b/client/elm/battlemap/src/Model.elm
index 85b123b..b8782f2 100644
--- a/client/elm/battlemap/src/Model.elm
+++ b/client/elm/battlemap/src/Model.elm
@@ -1,60 +1,22 @@
-module Model exposing (Model, model)
+module Model exposing (Type)
-import Battlemap as Bp exposing (Battlemap, random, apply_to_all_tiles)
-import Battlemap.Navigator as Nr exposing (Navigator, new_navigator)
+import Dict
-import Character exposing (Character, CharacterRef)
+import Battlemap
+import Battlemap.Navigator
-import Dict exposing (Dict, empty, insert)
+import Character
+
+import Shim.Model
-- MODEL
-type alias Model =
+type alias Type =
{
- battlemap: Bp.Battlemap,
- navigator: (Maybe Nr.Navigator),
+ battlemap: Battlemap.Type,
+ navigator: (Maybe Battlemap.Navigator.Type),
selection: (Maybe String),
- characters: (Dict CharacterRef Character)
+ characters: (Dict.Dict Character.Ref Character.Type)
}
-model : Model
-model =
- {
- battlemap = (Bp.random),
- navigator = Nothing,
- selection = Nothing,
- characters =
- (insert
- "2"
- {
- id = "2",
- name = "Char2",
- icon = "Icon2",
- portrait = "Portrait2",
- location = {x = 1, y = 4},
- movement_points = 6
- }
- (insert
- "1"
- {
- id = "1",
- name = "Char1",
- icon = "Icon1",
- portrait = "Portrait1",
- location = {x = 4, y = 1},
- movement_points = 10
- }
- (insert
- "0"
- {
- id = "0",
- name = "Char0",
- icon = "Icon0",
- portrait = "Portrait0",
- location = {x = 0, y = 0},
- movement_points = 16
- }
- empty
- )
- )
- )
- }
+model : Type
+model = (Shim.Model.generate)
diff --git a/client/elm/battlemap/src/Shim/Battlemap.elm b/client/elm/battlemap/src/Shim/Battlemap.elm
new file mode 100644
index 0000000..820ceec
--- /dev/null
+++ b/client/elm/battlemap/src/Shim/Battlemap.elm
@@ -0,0 +1,11 @@
+module Shim.Battlemap exposing (generate)
+
+import Shim.Battlemap.Tile
+
+--generate : Battlemap.Type
+generate =
+ {
+ width = 6,
+ height = 6,
+ content = (Shim.Battlemap.Tile.generate)
+ }
diff --git a/client/elm/battlemap/src/Shim/Battlemap/Tile.elm b/client/elm/battlemap/src/Shim/Battlemap/Tile.elm
new file mode 100644
index 0000000..e3ab7bb
--- /dev/null
+++ b/client/elm/battlemap/src/Shim/Battlemap/Tile.elm
@@ -0,0 +1,40 @@
+module Shim.Battlemap.Tile exposing (generate)
+
+import Array
+import List
+
+import Battlemap.Direction
+import Battlemap.Tile
+
+from_int : Int -> Battlemap.Tile.Type
+from_int i =
+ if (i >= 10)
+ then
+ {
+ floor_level = (i - 10),
+ nav_level = Battlemap.Direction.None,
+ char_level = (Just (toString (i - 10)))
+ }
+ else
+ {
+ floor_level = i,
+ nav_level = Battlemap.Direction.None,
+ char_level = Nothing
+ }
+
+
+generate : (Array.Array Battlemap.Tile.Type)
+generate =
+ (Array.fromList
+ (List.map
+ (from_int)
+ [
+ 10, 1, 1, 2, 2, 2,
+ 1, 0, 0, 0, 11, 2,
+ 1, 0, 1, 2, 0, 2,
+ 3, 0, 3, 4, 0, 4,
+ 3, 12, 0, 0, 0, 4,
+ 3, 3, 3, 4, 4, 4
+ ]
+ )
+ )
diff --git a/client/elm/battlemap/src/Shim/Model.elm b/client/elm/battlemap/src/Shim/Model.elm
new file mode 100644
index 0000000..517f80d
--- /dev/null
+++ b/client/elm/battlemap/src/Shim/Model.elm
@@ -0,0 +1,50 @@
+module Shim.Model exposing (generate)
+
+import Dict
+
+--import Model
+
+import Shim.Battlemap
+
+--generate : Model.Type
+generate =
+ {
+ battlemap = (Shim.Battlemap.generate),
+ navigator = Nothing,
+ selection = Nothing,
+ characters =
+ (Dict.insert
+ "2"
+ {
+ id = "2",
+ name = "Char2",
+ icon = "Icon2",
+ portrait = "Portrait2",
+ location = {x = 1, y = 4},
+ movement_points = 6
+ }
+ (Dict.insert
+ "1"
+ {
+ id = "1",
+ name = "Char1",
+ icon = "Icon1",
+ portrait = "Portrait1",
+ location = {x = 4, y = 1},
+ movement_points = 10
+ }
+ (Dict.insert
+ "0"
+ {
+ id = "0",
+ name = "Char0",
+ icon = "Icon0",
+ portrait = "Portrait0",
+ location = {x = 0, y = 0},
+ movement_points = 16
+ }
+ Dict.empty
+ )
+ )
+ )
+ }
diff --git a/client/elm/battlemap/src/Update.elm b/client/elm/battlemap/src/Update.elm
index 0fef667..2abddb5 100644
--- a/client/elm/battlemap/src/Update.elm
+++ b/client/elm/battlemap/src/Update.elm
@@ -1,23 +1,25 @@
-module Update exposing (update, Msg(..))
+module Update exposing (update, Type(..))
-import Model exposing (Model, model)
+import Model
-import Battlemap exposing (apply_to_all_tiles, apply_to_tile_unsafe)
-import Battlemap.Direction exposing (Direction)
+import Battlemap
+import Battlemap.Direction
+import Battlemap.Navigator
-import Battlemap.Navigator as Nr exposing (go, reset_navigation)
+import Dict
-import Dict as Dt exposing (get, update, values)
+import Character
-import Character exposing (CharacterRef)
-
-
-type Msg =
- DirectionRequest Direction
- | SelectCharacter CharacterRef
+type Type =
+ DirectionRequest Battlemap.Direction.Type
+ | SelectCharacter Character.Ref
| EndTurn
-handle_direction_request : Model -> Direction -> Model
+handle_direction_request : (
+ Model.Type ->
+ Battlemap.Direction.Type ->
+ Model.Type
+ )
handle_direction_request model dir =
(case (model.selection, model.navigator) of
(Nothing, _) -> model
@@ -25,11 +27,11 @@ handle_direction_request model dir =
((Just char_id), (Just nav)) ->
let
(new_bmap, new_nav) =
- (Nr.go
+ (Battlemap.Navigator.go
model.battlemap
nav
dir
- (Dt.values model.characters)
+ (Dict.values model.characters)
)
in
{model |
@@ -38,44 +40,49 @@ handle_direction_request model dir =
}
)
-handle_select_character : Model -> CharacterRef -> Model
+handle_select_character : Model.Type -> Character.Ref -> Model.Type
handle_select_character model char_id =
{model |
selection = (Just char_id),
battlemap =
- (apply_to_all_tiles
+ (Battlemap.apply_to_all_tiles
model.battlemap
- (reset_navigation)
+ (Battlemap.Navigator.reset_navigation)
),
navigator =
- (case (Dt.get char_id model.characters) of
+ (case (Dict.get char_id model.characters) of
Nothing -> Nothing
(Just char) ->
- (Just (Nr.new_navigator char.location char.movement_points))
+ (Just
+ (Battlemap.Navigator.new_navigator
+ char.location
+ char.movement_points
+ )
+ )
)
}
-handle_end_turn : Model -> Model
+handle_end_turn : Model.Type -> Model.Type
handle_end_turn model =
case (model.navigator, model.selection) of
(_, Nothing) -> model
(Nothing, _) -> model
((Just nav), (Just char_id)) ->
- (case (Dt.get char_id model.characters) of
+ (case (Dict.get char_id model.characters) of
Nothing -> model
(Just char) ->
{model |
navigator =
(Just
- (Nr.new_navigator
+ (Battlemap.Navigator.new_navigator
nav.current_location
char.movement_points
)
),
battlemap =
- (apply_to_all_tiles
- (apply_to_tile_unsafe
- (apply_to_tile_unsafe
+ (Battlemap.apply_to_all_tiles
+ (Battlemap.apply_to_tile_unsafe
+ (Battlemap.apply_to_tile_unsafe
model.battlemap
char.location
(\t -> {t | char_level = Nothing})
@@ -83,10 +90,10 @@ handle_end_turn model =
nav.current_location
(\t -> {t | char_level = (Just char_id)})
)
- (reset_navigation)
+ (Battlemap.Navigator.reset_navigation)
),
characters =
- (Dt.update
+ (Dict.update
char_id
(\mc ->
case mc of
@@ -99,7 +106,7 @@ handle_end_turn model =
}
)
-update : Msg -> Model -> Model
+update : Type -> Model.Type -> Model.Type
update msg model =
case msg of
(DirectionRequest d) ->
diff --git a/client/elm/battlemap/src/View.elm b/client/elm/battlemap/src/View.elm
index 50fa563..2ea5972 100644
--- a/client/elm/battlemap/src/View.elm
+++ b/client/elm/battlemap/src/View.elm
@@ -1,55 +1,73 @@
module View exposing (view)
-import Html exposing (Html, button, div, text)
-import Html.Events exposing (onClick)
+import Dict
-import Update exposing (Msg(..))
-import Model exposing (Model)
+import Html
+import Html.Events
+
+import Battlemap.Direction
+import Battlemap.Html
+
+import Update
+import Model
-import Battlemap.Html as Batmap exposing (view)
-import Battlemap.Direction exposing (Direction(..))
-import Dict as Dt exposing (get)
-- VIEW
-view : Model -> (Html Msg)
+view : Model.Type -> (Html.Html Update.Type)
view model =
- (div
+ (Html.div
[]
[
- (button
- [ (onClick (DirectionRequest Left)) ]
- [ (text "Left") ]
+ (Html.button
+ [
+ (Html.Events.onClick
+ (Update.DirectionRequest Battlemap.Direction.Left)
+ )
+ ]
+ [ (Html.text "Left") ]
),
- (button
- [ (onClick (DirectionRequest Down)) ]
- [ (text "Down") ]
+ (Html.button
+ [
+ (Html.Events.onClick
+ (Update.DirectionRequest Battlemap.Direction.Down)
+ )
+ ]
+ [ (Html.text "Down") ]
),
- (button
- [ (onClick (DirectionRequest Up)) ]
- [ (text "Up") ]
+ (Html.button
+ [
+ (Html.Events.onClick
+ (Update.DirectionRequest Battlemap.Direction.Up)
+ )
+ ]
+ [ (Html.text "Up") ]
),
- (button
- [ (onClick (DirectionRequest Right)) ]
- [ (text "Right") ]
+ (Html.button
+ [
+ (Html.Events.onClick
+ (Update.DirectionRequest Battlemap.Direction.Right)
+ )
+ ]
+ [ (Html.text "Right") ]
),
- (button
- [ (onClick EndTurn) ]
- [ (text "Apply") ]
+ (Html.button
+ [ (Html.Events.onClick Update.EndTurn) ]
+ [ (Html.text "Apply") ]
),
- (div
+ (Html.div
[]
- [(Batmap.view model)]
+ [(Battlemap.Html.view model)]
),
- (div
+ (Html.div
[]
[
- (text
+ (Html.text
(case (model.selection, model.navigator) of
(Nothing, _) -> ""
(_, Nothing) -> ""
((Just char_id), (Just nav)) ->
- case (Dt.get char_id model.characters) of
+ case (Dict.get char_id model.characters) of
Nothing -> ""
(Just char) ->
(