Skip to content

Commit

Permalink
[GH-982] Square Wall Parameters in the Configurator (#986)
Browse files Browse the repository at this point in the history
* feat: add square wall to map configurations form

* feat: add square wall to show

* feat: add square wall to index

* test: encode the struct in the template
  • Loading branch information
tvillegas98 authored Nov 14, 2024
1 parent 8bfe075 commit b600aba
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ defmodule ConfiguratorWeb.MapConfigurationController do
|> Map.update("bushes", "", &parse_json/1)
|> Map.update("pools", "", &parse_json/1)
|> Map.update("crates", "", &parse_json/1)
|> Map.update("square_wall", "", &parse_json/1)
end

defp parse_json(""), do: []
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,18 @@
</.modal>
<% end %>
</:col>
<:col :let={map_configuration} label="Square Wall">
<%= if is_nil(map_configuration.square_wall) do %>
<p>N/A</p>
<% else %>
<.button type="button" phx-click={show_modal("square-wall-#{map_configuration.id}")}>Show</.button>
<.modal id={"square-wall-#{map_configuration.id}"}>
<p class="whitespace-pre">
<%= embed_to_string(map_configuration.square_wall) |> Jason.encode!() |> Jason.Formatter.pretty_print() %>
</p>
</.modal>
<% end %>
</:col>
<:action :let={map_configuration}>
<.link navigate={~p"/map_configurations/#{map_configuration}"}>View</.link>
</:action>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,27 @@
<.input
field={f[:version_id]}
type="select"
options={Enum.map(GameBackend.Configuration.list_versions(), fn version -> {version.name, version.id} end)}
options={
Enum.map(GameBackend.Configuration.list_versions(), fn version ->
{version.name, version.id}
end)
}
label="Version"
/> <.input field={f[:name]} type="text" label="Name" />
/>
<.input field={f[:name]} type="text" label="Name" />
<.input field={f[:radius]} type="number" label="Radius" step="any" />
<.input
field={f[:initial_positions]}
type="textarea"
label="Initial positions"
value={embed_to_string(f[:initial_positions].value)}
/>
<.input
field={f[:square_wall]}
type="textarea"
label="Square Wall"
value={embed_to_string(f[:square_wall].value) |> Jason.encode!() |> Jason.Formatter.pretty_print()}
/>
<.input field={f[:obstacles]} type="textarea" label="Obstacles" value={embed_to_string(f[:obstacles].value)} />
<.input field={f[:bushes]} type="textarea" label="Bushes" value={embed_to_string(f[:bushes].value)} />
<.input field={f[:pools]} type="textarea" label="Pools" value={embed_to_string(f[:pools].value)} />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,21 @@
<% end %>
</dd>
</div>
<div class="flex gap-5 py-4 border-b-2 items-center">
<dt>Square Wall</dt>
<dd>
<%= if is_nil(@map_configuration.square_wall) do %>
<p>N/A</p>
<% else %>
<.button type="button" phx-click={show_modal("square-wall-#{@map_configuration.id}")}>Show</.button>
<.modal id={"square-wall-#{@map_configuration.id}"}>
<p class="whitespace-pre">
<%= embed_to_string(@map_configuration.square_wall) |> Jason.encode!() |> Jason.Formatter.pretty_print() %>
</p>
</.modal>
<% end %>
</dd>
</div>
</div>

<.back navigate={~p"/map_configurations"}>Back to Map Configurations</.back>
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ defmodule ConfiguratorWeb.MapConfigurationControllerTest do
bushes: "",
pools: "",
crates: "",
active: true
active: true,
square_wall: ""
}
@update_attrs %{
name: "another_map",
Expand All @@ -23,7 +24,8 @@ defmodule ConfiguratorWeb.MapConfigurationControllerTest do
bushes: "",
pools: "",
crates: "",
active: false
active: false,
square_wall: nil
}
@invalid_attrs %{
name: nil,
Expand All @@ -33,7 +35,8 @@ defmodule ConfiguratorWeb.MapConfigurationControllerTest do
bushes: nil,
pools: nil,
crates: nil,
active: nil
active: nil,
square_wall: ""
}

describe "index" do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ defmodule GameBackend.CurseOfMirra.MapConfiguration do
def changeset(square_wall, attrs) do
square_wall
|> cast(attrs, [:right, :left, :top, :bottom])
|> validate_required([:right, :left, :top, :bottom])
end
end

Expand Down

0 comments on commit b600aba

Please sign in to comment.