summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'src/battlemap')
-rw-r--r--src/battlemap/src/Battlemap/Direction.elm12
-rw-r--r--src/battlemap/src/Battlemap/Location.elm1
-rw-r--r--src/battlemap/src/Battlemap/Navigator/RangeIndicator.elm25
-rw-r--r--src/battlemap/src/Model/SelectCharacter.elm9
-rw-r--r--src/battlemap/src/View/Battlemap/Navigator.elm190
-rw-r--r--src/battlemap/www/index.html53
6 files changed, 239 insertions, 51 deletions
diff --git a/src/battlemap/src/Battlemap/Direction.elm b/src/battlemap/src/Battlemap/Direction.elm
index 5aad141..cebe765 100644
--- a/src/battlemap/src/Battlemap/Direction.elm
+++ b/src/battlemap/src/Battlemap/Direction.elm
@@ -1,4 +1,4 @@
-module Battlemap.Direction exposing (Type(..), opposite_of)
+module Battlemap.Direction exposing (Type(..), opposite_of, to_string)
type Type =
None
@@ -15,3 +15,13 @@ opposite_of d =
Up -> Down
Down -> Up
None -> None
+
+to_string : Type -> String
+to_string dir =
+ case dir of
+ Right -> "R"
+ Left -> "L"
+ Up -> "U"
+ Down -> "D"
+ None -> "N"
+
diff --git a/src/battlemap/src/Battlemap/Location.elm b/src/battlemap/src/Battlemap/Location.elm
index 36f0c4d..8c23e9d 100644
--- a/src/battlemap/src/Battlemap/Location.elm
+++ b/src/battlemap/src/Battlemap/Location.elm
@@ -19,6 +19,7 @@ neighbor loc dir =
Battlemap.Direction.Down -> {loc | y = (loc.y + 1)}
Battlemap.Direction.None -> loc
+
get_ref : Type -> Ref
get_ref l =
(l.x, l.y)
diff --git a/src/battlemap/src/Battlemap/Navigator/RangeIndicator.elm b/src/battlemap/src/Battlemap/Navigator/RangeIndicator.elm
index 9271a45..56fb171 100644
--- a/src/battlemap/src/Battlemap/Navigator/RangeIndicator.elm
+++ b/src/battlemap/src/Battlemap/Navigator/RangeIndicator.elm
@@ -15,6 +15,9 @@ import Battlemap.Marker
import Util.List
+--------------------------------------------------------------------------------
+-- TYPES -----------------------------------------------------------------------
+--------------------------------------------------------------------------------
type alias Type =
{
distance: Int,
@@ -23,6 +26,9 @@ type alias Type =
marker: Battlemap.Marker.Type
}
+--------------------------------------------------------------------------------
+-- LOCAL -----------------------------------------------------------------------
+--------------------------------------------------------------------------------
generate_row : (
Battlemap.Location.Type ->
Int ->
@@ -121,15 +127,7 @@ handle_neighbors loc dist atk_dist indicator remaining directions =
)
(Just neighbor) ->
let
- is_attack_range = (indicator.distance >= dist)
- new_dist =
- (
- if (is_attack_range)
- then
- (indicator.distance + 1)
- else
- (indicator.distance + neighbor.node_cost)
- )
+ new_dist = (indicator.distance + neighbor.node_cost)
in
(handle_neighbors
loc
@@ -137,11 +135,7 @@ handle_neighbors loc dist atk_dist indicator remaining directions =
atk_dist
indicator
(
- if
- (
- (new_dist < neighbor.distance)
- && (new_dist <= atk_dist)
- )
+ if (new_dist < neighbor.distance)
then
(Dict.insert
(Battlemap.Location.get_ref neighbor_loc)
@@ -267,6 +261,9 @@ grid_to_range_indicators can_cross_fun cost_fun location grid result =
result
)
+--------------------------------------------------------------------------------
+-- EXPORTED --------------------------------------------------------------------
+--------------------------------------------------------------------------------
generate : (
Battlemap.Location.Type ->
Int ->
diff --git a/src/battlemap/src/Model/SelectCharacter.elm b/src/battlemap/src/Model/SelectCharacter.elm
index 7cc2102..06fef25 100644
--- a/src/battlemap/src/Model/SelectCharacter.elm
+++ b/src/battlemap/src/Model/SelectCharacter.elm
@@ -21,7 +21,14 @@ make_it_so model char_id =
(Character.get_location char)
(Character.get_movement_points char)
(Character.get_attack_range char)
- (\e -> True) -- TODO: check for characters.
+ (\loc ->
+ (loc == (Character.get_location char))
+ ||
+ (List.all
+ (\c -> ((Character.get_location c) /= loc))
+ (Dict.values model.characters)
+ )
+ )
model.battlemap
)
}
diff --git a/src/battlemap/src/View/Battlemap/Navigator.elm b/src/battlemap/src/View/Battlemap/Navigator.elm
index a138a19..6758614 100644
--- a/src/battlemap/src/View/Battlemap/Navigator.elm
+++ b/src/battlemap/src/View/Battlemap/Navigator.elm
@@ -6,52 +6,172 @@ import Html.Attributes
import Html.Events
import Battlemap.Location
+import Battlemap.Direction
import Battlemap.Marker
import Battlemap.Navigator
import Event
-get_html : (
+--------------------------------------------------------------------------------
+-- LOCAL -----------------------------------------------------------------------
+--------------------------------------------------------------------------------
+marker_get_html : (
Int ->
- Battlemap.Navigator.Summary ->
- (List (Html.Html Event.Type))
+ (Battlemap.Location.Ref, Battlemap.Marker.Type) ->
+ (Html.Html Event.Type)
)
-get_html tile_size nav_summary =
- (List.map
- (\(loc_ref, marker) ->
- (Html.div
- [
- (Html.Attributes.class "battlemap-marker-icon"),
- (Html.Attributes.class "battlemap-tiled"),
- (Html.Attributes.class
- (
- "asset-marker-icon-"
- ++
- if (marker == Battlemap.Marker.CanGoTo)
- then
- "can-go-to"
- else
- "can-attack"
+marker_get_html tile_size (loc_ref, marker) =
+ (Html.div
+ [
+ (Html.Attributes.class "battlemap-marker-icon"),
+ (Html.Attributes.class "battlemap-tiled"),
+ (Html.Attributes.class
+ (
+ "asset-marker-icon-"
+ ++
+ if (marker == Battlemap.Marker.CanGoTo)
+ then
+ "can-go-to"
+ else
+ "can-attack"
+ )
+ ),
+ (Html.Events.onClick
+ (Event.TileSelected loc_ref)
+ ),
+ (Html.Attributes.style
+ (
+ let
+ loc = (Battlemap.Location.from_ref loc_ref)
+ in
+ [
+ ("top", ((toString (loc.y * tile_size)) ++ "px")),
+ ("left", ((toString (loc.x * tile_size)) ++ "px"))
+ ]
+ )
+ )
+ ]
+ [
+ ]
+ )
+
+path_node_get_html : (
+ Int ->
+ Battlemap.Direction.Type ->
+ (
+ Battlemap.Location.Type,
+ Battlemap.Direction.Type,
+ (List (Html.Html Event.Type))
+ ) ->
+ (
+ Battlemap.Location.Type,
+ Battlemap.Direction.Type,
+ (List (Html.Html Event.Type))
+ )
+ )
+path_node_get_html tile_size new_dir (curr_loc, prev_dir, curr_nodes) =
+ let
+ new_loc = (Battlemap.Location.neighbor curr_loc new_dir)
+ in
+ (
+ new_loc,
+ new_dir,
+ (
+ (Html.div
+ [
+ (Html.Attributes.class "battlemap-path-icon"),
+ (Html.Attributes.class "battlemap-tiled"),
+ (Html.Attributes.class
+ (
+ "asset-path-icon-"
+ ++
+ (Battlemap.Direction.to_string prev_dir)
+ ++
+ (Battlemap.Direction.to_string new_dir)
+ )
+ ),
+ (Html.Events.onClick
+ (Event.TileSelected (Battlemap.Location.get_ref new_loc))
+ ),
+ (Html.Attributes.style
+ [
+ (
+ "top",
+ ((toString (new_loc.y * tile_size)) ++ "px")
+ ),
+ (
+ "left",
+ ((toString (new_loc.x * tile_size)) ++ "px")
+ )
+ ]
)
+ ]
+ [
+ ]
+ )
+ ::
+ curr_nodes
+ )
+ )
+
+mark_the_spot : (
+ Int ->
+ Battlemap.Location.Type ->
+ Battlemap.Direction.Type ->
+ (Html.Html Event.Type)
+ )
+mark_the_spot tile_size loc origin_dir =
+ (Html.div
+ [
+ (Html.Attributes.class "battlemap-path-icon"),
+ (Html.Attributes.class "battlemap-tiled"),
+ (Html.Attributes.class
+ (
+ "asset-path-icon-mark"
+ ++
+ (Battlemap.Direction.to_string origin_dir)
+ )
+ ),
+ (Html.Events.onClick
+ (Event.TileSelected (Battlemap.Location.get_ref loc))
+ ),
+ (Html.Attributes.style
+ [
+ (
+ "top",
+ ((toString (loc.y * tile_size)) ++ "px")
),
- (Html.Events.onClick
- (Event.TileSelected loc_ref)
- ),
- (Html.Attributes.style
- (
- let
- loc = (Battlemap.Location.from_ref loc_ref)
- in
- [
- ("top", ((toString (loc.y * tile_size)) ++ "px")),
- ("left", ((toString (loc.x * tile_size)) ++ "px"))
- ]
- )
+ (
+ "left",
+ ((toString (loc.x * tile_size)) ++ "px")
)
]
- [
- ]
)
+ ]
+ [
+ ]
+ )
+--------------------------------------------------------------------------------
+-- EXPORTED --------------------------------------------------------------------
+--------------------------------------------------------------------------------
+get_html : (
+ Int ->
+ Battlemap.Navigator.Summary ->
+ (List (Html.Html Event.Type))
+ )
+get_html tile_size nav_summary =
+ (
+ (List.map (marker_get_html tile_size) nav_summary.markers)
+ ++
+ (
+ let
+ (final_loc, final_dir, path_node_htmls) =
+ (List.foldr
+ (path_node_get_html tile_size)
+ (nav_summary.starting_location, Battlemap.Direction.None, [])
+ nav_summary.path
+ )
+ in
+ ((mark_the_spot tile_size final_loc final_dir) :: path_node_htmls)
)
- nav_summary.markers
)
diff --git a/src/battlemap/www/index.html b/src/battlemap/www/index.html
index e8bff19..21c6a27 100644
--- a/src/battlemap/www/index.html
+++ b/src/battlemap/www/index.html
@@ -58,6 +58,7 @@
{
z-index: 1;
}
+
.asset-marker-icon-can-go-to
{
background-color:rgba(0,0,0,0.5);
@@ -67,6 +68,58 @@
{
background-color:rgba(0,0,0,0.7);
}
+
+ .battlemap-path-icon
+ {
+ z-index: 3;
+ color: white;
+ }
+
+ .asset-path-icon-NR:before,
+ .asset-path-icon-LR:before,
+ .asset-path-icon-RR:before,
+ .asset-path-icon-UR:before,
+ .asset-path-icon-DR:before
+ {
+ content: "}";
+ }
+
+ .asset-path-icon-NL:before,
+ .asset-path-icon-LL:before,
+ .asset-path-icon-RL:before,
+ .asset-path-icon-UL:before,
+ .asset-path-icon-DL:before
+ {
+ content: "{";
+ }
+
+ .asset-path-icon-NU:before,
+ .asset-path-icon-LU:before,
+ .asset-path-icon-RU:before,
+ .asset-path-icon-UU:before,
+ .asset-path-icon-DU:before
+ {
+ content: "^";
+ }
+
+ .asset-path-icon-ND:before,
+ .asset-path-icon-LD:before,
+ .asset-path-icon-RD:before,
+ .asset-path-icon-UD:before,
+ .asset-path-icon-DD:before
+ {
+ content: "v";
+ }
+
+ .asset-path-icon-markN:before,
+ .asset-path-icon-markL:before,
+ .asset-path-icon-markU:before,
+ .asset-path-icon-markD:before,
+ .asset-path-icon-markR:before
+ {
+ content: "x";
+ }
+
</style>
</head>
<body>