summaryrefslogtreecommitdiff
path: root/elm
diff options
context:
space:
mode:
Diffstat (limited to 'elm')
-rw-r--r--elm/battlemap/src/Battlemap.elm12
-rw-r--r--elm/battlemap/src/Battlemap/Html.elm112
-rw-r--r--elm/battlemap/src/Battlemap/Navigator.elm31
-rw-r--r--elm/battlemap/src/Battlemap/Navigator/Path.elm3
-rw-r--r--elm/battlemap/src/Battlemap/Tile.elm14
-rw-r--r--elm/battlemap/src/Character.elm7
-rw-r--r--elm/battlemap/src/Shim/Battlemap.elm7
-rw-r--r--elm/battlemap/src/Shim/Battlemap/Tile.elm15
-rw-r--r--elm/battlemap/src/Shim/Model.elm2
-rw-r--r--elm/battlemap/src/View.elm11
-rw-r--r--elm/battlemap/src/View/Battlemap.elm88
-rw-r--r--elm/battlemap/src/View/Battlemap/Navigator.elm17
-rw-r--r--elm/battlemap/src/View/Battlemap/Tile.elm39
13 files changed, 203 insertions, 155 deletions
diff --git a/elm/battlemap/src/Battlemap.elm b/elm/battlemap/src/Battlemap.elm
index c4aaf06..d2e4523 100644
--- a/elm/battlemap/src/Battlemap.elm
+++ b/elm/battlemap/src/Battlemap.elm
@@ -3,9 +3,11 @@ module Battlemap exposing
Type,
reset,
get_navigator_remaining_points,
+ get_tiles,
set_navigator,
try_getting_navigator_location,
try_getting_navigator_path_to,
+ try_getting_navigator_summary,
try_adding_step_to_navigator
)
@@ -46,6 +48,9 @@ has_location bmap loc =
--------------------------------------------------------------------------------
-- EXPORTED --------------------------------------------------------------------
--------------------------------------------------------------------------------
+get_tiles : Type -> (Array.Array Battlemap.Tile.Type)
+get_tiles bmap = bmap.content
+
reset : Type -> Type
reset bmap =
{bmap |
@@ -117,6 +122,12 @@ try_adding_step_to_navigator bmap can_cross dir =
_ -> Nothing
+try_getting_navigator_summary : Type -> (Maybe Battlemap.Navigator.Summary)
+try_getting_navigator_summary bmap =
+ case bmap.navigator of
+ (Just navigator) -> (Just (Battlemap.Navigator.get_summary navigator))
+ Nothing -> Nothing
+
try_getting_navigator_path_to : (
Type ->
Battlemap.Location.Ref ->
@@ -128,3 +139,4 @@ try_getting_navigator_path_to bmap loc_ref =
(Battlemap.Navigator.try_getting_path_to navigator loc_ref)
Nothing -> Nothing
+
diff --git a/elm/battlemap/src/Battlemap/Html.elm b/elm/battlemap/src/Battlemap/Html.elm
deleted file mode 100644
index 2fa6472..0000000
--- a/elm/battlemap/src/Battlemap/Html.elm
+++ /dev/null
@@ -1,112 +0,0 @@
-module Battlemap.Html exposing (view)
-
-import Array
-
-import Html
-import Html.Events
-
-import Battlemap
-import Battlemap.Tile
-import Battlemap.Direction
-
-import Event
-
-type alias GridBuilder =
- {
- row : (List (Html.Html Event.Type)),
- columns : (List (Html.Html Event.Type)),
- row_size : Int,
- bmap : Battlemap.Type
- }
-
-view_battlemap_cell : Battlemap.Tile.Type -> (Html.Html Event.Type)
-view_battlemap_cell t =
- (Html.td
- [
- (Html.Events.onClick
- (Battlemap.Tile.get_location t)
- ),
- (Html.Attribute.class (Battlemap.Tile.get_css_class t))
- ]
- [
- case (Battlemap.Tile.get_character t) of
- (Just char_id) ->
- (Character.Html.get_icon
- (Character.get model char_id)
- )
-
- Nothing -> (Html.text "") -- Meaning no element.
- ]
- )
-
-
-foldr_to_html : Battlemap.Tile.Type -> GridBuilder -> GridBuilder
-foldr_to_html t gb =
- if (gb.row_size == gb.bmap.width)
- then
- {gb |
- row = [(view_battlemap_cell t)],
- row_size = 1,
- columns =
- (
- (Html.tr [] gb.row) :: gb.columns
- )
- }
- else
- {gb |
- row = ((view_battlemap_cell t) :: gb.row),
- row_size = (gb.row_size + 1)
- }
-
-grid_builder_to_html : GridBuilder -> (List (Html.Html Event.Type))
-grid_builder_to_html gb =
- if (gb.row_size == 0)
- then
- gb.columns
- else
- ((Html.tr [] gb.row) :: gb.columns)
-
-tiles_grid battlemap =
- (Html.table
- [
- (Html.Attribute.class "battlemap-tiles-grid")
- ]
- (grid_builder_to_html
- (Array.foldr
- (foldr_to_html)
- {
- row = [],
- columns = [],
- row_size = 0,
- bmap = battlemap
- }
- battlemap.content
- )
- )
- )
-
-view : Battlemap.Type -> (Html.Html Event.Type)
-view battlemap =
- (Html.div
- [
- (Html.Attribute.class "battlemap-container")
- ]
- [
- (Html.div
- [
- (Html.Attribute.class "battlemap-tiles-container")
- ]
- [ (tiles_grid battlemap) ]
- ),
- case battlemap.navigator of
- (Just navigator) ->
- (Html.div
- [
- (Html.Attribute.class "battlemap-navigator-container")
- ]
- [ (Battlemap.Navigator.Html.view battlemap.navigator) ]
- )
-
- Nothing -> (Html.text "") -- Meaning no element.
- ]
- )
diff --git a/elm/battlemap/src/Battlemap/Navigator.elm b/elm/battlemap/src/Battlemap/Navigator.elm
index ac394b5..6687b18 100644
--- a/elm/battlemap/src/Battlemap/Navigator.elm
+++ b/elm/battlemap/src/Battlemap/Navigator.elm
@@ -1,10 +1,12 @@
module Battlemap.Navigator exposing
(
Type,
+ Summary,
new,
get_current_location,
get_remaining_points,
get_range_markers,
+ get_summary,
try_adding_step,
try_getting_path_to
)
@@ -13,6 +15,7 @@ import Dict
import Battlemap.Location
import Battlemap.Direction
+import Battlemap.Marker
import Battlemap.Navigator.Path
import Battlemap.Navigator.RangeIndicator
@@ -33,6 +36,12 @@ type alias Type =
)
}
+type alias Summary =
+ {
+ starting_location: Battlemap.Location.Type,
+ path: (List Battlemap.Direction.Type),
+ markers: (List (Battlemap.Location.Ref, Battlemap.Marker.Type))
+ }
--------------------------------------------------------------------------------
-- LOCAL -----------------------------------------------------------------------
--------------------------------------------------------------------------------
@@ -79,6 +88,27 @@ get_range_markers : (
)
get_range_markers navigator = (Dict.toList navigator.range_indicators)
+get_summary : Type -> Summary
+get_summary navigator =
+ {
+ starting_location = navigator.starting_location,
+ path = (Battlemap.Navigator.Path.get_summary navigator.path),
+ markers =
+ (List.map
+ (\(loc, range_indicator) ->
+ (
+ loc,
+ (Battlemap.Navigator.RangeIndicator.get_marker
+ range_indicator
+ )
+ )
+ )
+ (Dict.toList
+ navigator.range_indicators
+ )
+ )
+ }
+
try_adding_step : (
Type ->
Battlemap.Direction.Type ->
@@ -108,3 +138,4 @@ try_getting_path_to navigator loc_ref =
(Just target) ->
(Just (Battlemap.Navigator.RangeIndicator.get_path target))
Nothing -> Nothing
+
diff --git a/elm/battlemap/src/Battlemap/Navigator/Path.elm b/elm/battlemap/src/Battlemap/Navigator/Path.elm
index a20c0b7..53e12c0 100644
--- a/elm/battlemap/src/Battlemap/Navigator/Path.elm
+++ b/elm/battlemap/src/Battlemap/Navigator/Path.elm
@@ -4,6 +4,7 @@ module Battlemap.Navigator.Path exposing
new,
get_current_location,
get_remaining_points,
+ get_summary,
try_following_direction
)
@@ -131,6 +132,8 @@ get_current_location path = path.current_location
get_remaining_points : Type -> Int
get_remaining_points path = path.remaining_points
+get_summary : Type -> (List Battlemap.Direction.Type)
+get_summary path = path.previous_directions
try_following_direction : (
(Battlemap.Location.Type -> Bool) ->
(Battlemap.Location.Type -> Int) ->
diff --git a/elm/battlemap/src/Battlemap/Tile.elm b/elm/battlemap/src/Battlemap/Tile.elm
index 828fb67..255310a 100644
--- a/elm/battlemap/src/Battlemap/Tile.elm
+++ b/elm/battlemap/src/Battlemap/Tile.elm
@@ -1,7 +1,8 @@
module Battlemap.Tile exposing
(
Type,
- get_class,
+ get_location,
+ get_icon_id,
get_cost
)
@@ -9,13 +10,16 @@ import Battlemap.Location
type alias Type =
{
- location : Battlemap.Location.Ref,
- class : Int,
+ location : Battlemap.Location.Type,
+ icon_id : String,
crossing_cost : Int
}
-get_class : Type -> Int
-get_class tile = tile.class
+get_location : Type -> Battlemap.Location.Type
+get_location tile = tile.location
+
+get_icon_id : Type -> String
+get_icon_id tile = tile.icon_id
get_cost : Type -> Int
get_cost tile = tile.crossing_cost
diff --git a/elm/battlemap/src/Character.elm b/elm/battlemap/src/Character.elm
index b0be220..1b4d1a1 100644
--- a/elm/battlemap/src/Character.elm
+++ b/elm/battlemap/src/Character.elm
@@ -3,6 +3,7 @@ module Character exposing
Type,
Ref,
get_ref,
+ get_icon_id,
get_location,
set_location,
get_movement_points,
@@ -25,8 +26,10 @@ type alias Type =
type alias Ref = String
get_ref : Type -> Ref
-get_ref c =
- c.id
+get_ref c = c.id
+
+get_icon_id : Type -> String
+get_icon_id c = c.icon
get_location : Type -> Battlemap.Location.Type
get_location t = t.location
diff --git a/elm/battlemap/src/Shim/Battlemap.elm b/elm/battlemap/src/Shim/Battlemap.elm
index f35cb67..5a2e29b 100644
--- a/elm/battlemap/src/Shim/Battlemap.elm
+++ b/elm/battlemap/src/Shim/Battlemap.elm
@@ -5,7 +5,8 @@ import Shim.Battlemap.Tile
--generate : Battlemap.Type
generate =
{
- width = 32,
- height = 32,
- content = (Shim.Battlemap.Tile.generate 32)
+ width = 16,
+ height = 16,
+ content = (Shim.Battlemap.Tile.generate 16),
+ navigator = Nothing
}
diff --git a/elm/battlemap/src/Shim/Battlemap/Tile.elm b/elm/battlemap/src/Shim/Battlemap/Tile.elm
index c243f0a..1e11cb5 100644
--- a/elm/battlemap/src/Shim/Battlemap/Tile.elm
+++ b/elm/battlemap/src/Shim/Battlemap/Tile.elm
@@ -3,20 +3,17 @@ module Shim.Battlemap.Tile exposing (generate)
import Array
import List
-import Battlemap.Location
import Battlemap.Tile
from_int : Int -> Int -> (Int, Int) -> Battlemap.Tile.Type
-from_int map_width index (class, cost) =
+from_int map_width index (icon_id, cost) =
{
location =
- (Battlemap.Location.get_ref
- {
- x = (index % map_width),
- y = (index // map_width)
- }
- ),
- class = class,
+ {
+ x = (index % map_width),
+ y = (index // map_width)
+ },
+ icon_id = (toString icon_id),
crossing_cost = cost
}
diff --git a/elm/battlemap/src/Shim/Model.elm b/elm/battlemap/src/Shim/Model.elm
index 1ebe723..f82a0d3 100644
--- a/elm/battlemap/src/Shim/Model.elm
+++ b/elm/battlemap/src/Shim/Model.elm
@@ -10,7 +10,7 @@ import Shim.Battlemap
generate =
{
state = Model.Default,
- selection = Nothing,
+ selection = Model.None,
error = Nothing,
battlemap = (Shim.Battlemap.generate),
characters =
diff --git a/elm/battlemap/src/View.elm b/elm/battlemap/src/View.elm
index 3450f9c..8a956d1 100644
--- a/elm/battlemap/src/View.elm
+++ b/elm/battlemap/src/View.elm
@@ -1,14 +1,14 @@
module View exposing (view)
+import Dict
import Html
-import Battlemap.Html
+import View.Battlemap
import View.Controls
import View.Status
import Event
-import Update
import Model
view : Model.Type -> (Html.Html Event.Type)
@@ -20,9 +20,10 @@ view model =
[]
(View.Controls.view)
),
- (Html.div
- []
- [ (Battlemap.Html.view model.battlemap) ]
+ (View.Battlemap.get_html
+ model.battlemap
+ 32
+ (Dict.values model.characters)
),
(Html.div
[]
diff --git a/elm/battlemap/src/View/Battlemap.elm b/elm/battlemap/src/View/Battlemap.elm
index 1e10a2a..efe4d1e 100644
--- a/elm/battlemap/src/View/Battlemap.elm
+++ b/elm/battlemap/src/View/Battlemap.elm
@@ -1,26 +1,78 @@
-module View.Battlemap exposing (view)
+module View.Battlemap exposing (get_html)
+
+import Array
+
+import List
+
+import Html
+import Html.Attributes
+import Html.Events
+
+import Battlemap
+
+import Character
import View.Battlemap.Tile
import View.Battlemap.Navigator
-view : Battlemap.Type -> (Html.Html Event.Type)
-view battlemap =
+import Event
+--------------------------------------------------------------------------------
+-- LOCAL -----------------------------------------------------------------------
+--------------------------------------------------------------------------------
+char_on_map : Int -> Character.Type -> (Html.Html Event.Type)
+char_on_map tile_size char =
+ let
+ char_loc = (Character.get_location char)
+ in
+ (Html.div
+ [
+ (Html.Attributes.class "battlemap-character-icon"),
+ (Html.Attributes.class
+ ("asset-character-icon-" ++ (Character.get_icon_id char))
+ ),
+ (Html.Events.onClick
+ (Event.CharacterSelected (Character.get_ref char))
+ ),
+ (Html.Attributes.style
+ [
+ ("top", ((toString (char_loc.y * tile_size)) ++ "px")),
+ ("left", ((toString (char_loc.x * tile_size)) ++ "px"))
+ ]
+ )
+ ]
+ [
+ ]
+ )
+
+--------------------------------------------------------------------------------
+-- EXPORTED --------------------------------------------------------------------
+--------------------------------------------------------------------------------
+get_html : (
+ Battlemap.Type ->
+ Int ->
+ (List Character.Type) ->
+ (Html.Html Event.Type)
+ )
+get_html battlemap tile_size characters =
(Html.div
[
- (Html.Attribute.class "battlemap-container")
- ]
- [
- (
- ,
- case battlemap.navigator of
- (Just navigator) ->
- (Html.div
- [
- (Html.Attribute.class "battlemap-navigator-container")
- ]
- [ (Battlemap.Navigator.Html.view battlemap.navigator) ]
- )
-
- Nothing -> (Html.text "") -- Meaning no element.
+ (Html.Attributes.class "battlemap-container")
]
+ (
+ (List.map
+ (View.Battlemap.Tile.get_html tile_size)
+ (Array.toList (Battlemap.get_tiles battlemap))
+ )
+ ++
+ (List.map
+ (char_on_map tile_size)
+ characters
+ )
+ ++
+ case (Battlemap.try_getting_navigator_summary battlemap) of
+ (Just nav_summary) ->
+ (View.Battlemap.Navigator.get_html tile_size nav_summary)
+
+ Nothing -> [(Html.text "")]
+ )
)
diff --git a/elm/battlemap/src/View/Battlemap/Navigator.elm b/elm/battlemap/src/View/Battlemap/Navigator.elm
new file mode 100644
index 0000000..4180e6d
--- /dev/null
+++ b/elm/battlemap/src/View/Battlemap/Navigator.elm
@@ -0,0 +1,17 @@
+module View.Battlemap.Navigator exposing (get_html)
+
+import Html
+--import Html.Attributes
+--import Html.Events
+
+--import Battlemap.Location
+import Battlemap.Navigator
+
+import Event
+
+get_html : (
+ Int ->
+ Battlemap.Navigator.Summary ->
+ (List (Html.Html Event.Type))
+ )
+get_html tile_size nav_summary = []
diff --git a/elm/battlemap/src/View/Battlemap/Tile.elm b/elm/battlemap/src/View/Battlemap/Tile.elm
new file mode 100644
index 0000000..d38d84e
--- /dev/null
+++ b/elm/battlemap/src/View/Battlemap/Tile.elm
@@ -0,0 +1,39 @@
+module View.Battlemap.Tile exposing (get_html)
+
+import Html
+import Html.Attributes
+import Html.Events
+
+import Battlemap.Tile
+import Battlemap.Location
+
+import Event
+
+get_html : (
+ Int ->
+ Battlemap.Tile.Type ->
+ (Html.Html Event.Type)
+ )
+get_html tile_size tile =
+ let
+ tile_loc = (Battlemap.Tile.get_location tile)
+ in
+ (Html.div
+ [
+ (Html.Attributes.class "battlemap-tile-icon"),
+ (Html.Attributes.class
+ ("asset-tile-" ++ (toString (Battlemap.Tile.get_icon_id tile)))
+ ),
+ (Html.Events.onClick
+ (Event.TileSelected (Battlemap.Location.get_ref tile_loc))
+ ),
+ (Html.Attributes.style
+ [
+ ("top", ((toString (tile_loc.y * tile_size)) ++ "px")),
+ ("left", ((toString (tile_loc.x * tile_size)) ++ "px"))
+ ]
+ )
+ ]
+ [
+ ]
+ )