Skip to content

Commit 47893ef

Browse files
committed
Add some context and disable buttons when necesary
1 parent 74ba992 commit 47893ef

File tree

3 files changed

+22
-10
lines changed

3 files changed

+22
-10
lines changed

assets/css/tile_map.css

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -114,14 +114,12 @@ div.toolbar {
114114
justify-content: left;
115115
}
116116
div.toolbar button {
117+
cursor: pointer;
118+
}
119+
div.toolbar * {
117120
margin: 0.5rem;
118121
padding: 0.5rem;
119122
font-size: 1.4em;
120-
cursor: pointer;
121-
}
122-
div.toolbar img.morpheus {
123-
max-width: 300px;
124-
margin: auto;
125123
}
126124
ul.entities-list {
127125
background-color: black;

config/config.exs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ config :esbuild,
4545
# Configures Elixir's Logger
4646
config :logger, :console,
4747
format: "$time $metadata[$level] $message\n",
48-
metadata: [:request_id]
48+
metadata: [:request_id],
49+
level: :info
4950

5051
# Use Jason for JSON parsing in Phoenix
5152
config :phoenix, :json_library, Jason

lib/path_demo_web/live/map_live.ex

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,14 @@ defmodule PathDemoWeb.MapLive do
3434
end
3535

3636
def render(assigns) do
37-
# <img class="morpheus" src="/images/morpheus.jpg">
38-
3937
~L"""
4038
<h3>Pathfinding A* Live Demo</h3>
4139
4240
<div class="tilemap-container">
4341
<div class="toolbar">
44-
<button phx-click="update-path">Find the path</button>
45-
<button phx-click="walk-path">Walk the path</button>
42+
<button phx-click="update-path" <%= update_disable(assigns)%>>Find the path</button>
43+
<button phx-click="walk-path" <%= walk_disable(assigns) %>>Walk the path</button>
44+
<p><%= if is_nil(assigns.player_target), do: "Pick a target!", else: "" %></p>
4645
</div>
4746
4847
<ul class="entities-list">
@@ -225,4 +224,18 @@ defmodule PathDemoWeb.MapLive do
225224
def tile_in_closed_list?(%{closed_list: closed_list}, position) do
226225
closed_list |> Enum.any?(fn node -> node.position == position end)
227226
end
227+
228+
defp update_disable(%{path: %{final_path: final_path}, player_target: player_target} = _assigns) do
229+
if is_nil(player_target) or not is_nil(final_path) do
230+
"disabled"
231+
else
232+
""
233+
end
234+
end
235+
defp update_disable(%{player_target: nil}), do: "disabled"
236+
defp update_disable(_), do: ""
237+
238+
defp walk_disable(%{path: %{final_path: nil}} = _assigns), do: "disabled"
239+
defp walk_disable(%{path: nil} = _assigns), do: "disabled"
240+
defp walk_disable(_), do: ""
228241
end

0 commit comments

Comments
 (0)