diff --git a/apps/configurator/lib/configurator_web/controllers/map_configuration_html.ex b/apps/configurator/lib/configurator_web/controllers/map_configuration_html.ex index 46f5d388f..99fab600e 100644 --- a/apps/configurator/lib/configurator_web/controllers/map_configuration_html.ex +++ b/apps/configurator/lib/configurator_web/controllers/map_configuration_html.ex @@ -15,7 +15,8 @@ defmodule ConfiguratorWeb.MapConfigurationHTML do embeds |> Enum.map(&embed_to_string/1) |> Enum.reject(&(&1 == nil)) - |> json_encode + |> Jason.encode!() + |> Jason.Formatter.pretty_print() end def embed_to_string(nil), do: nil @@ -33,10 +34,4 @@ defmodule ConfiguratorWeb.MapConfigurationHTML do def embed_to_string(struct) when is_map(struct) do struct end - - def json_encode(value) do - value - |> Jason.encode!() - |> Jason.Formatter.pretty_print() - end end diff --git a/apps/configurator/lib/configurator_web/controllers/map_configuration_html/index.html.heex b/apps/configurator/lib/configurator_web/controllers/map_configuration_html/index.html.heex index d20524696..9b1f79f82 100644 --- a/apps/configurator/lib/configurator_web/controllers/map_configuration_html/index.html.heex +++ b/apps/configurator/lib/configurator_web/controllers/map_configuration_html/index.html.heex @@ -66,7 +66,9 @@ <% else %> <.button type="button" phx-click={show_modal("square-wall-#{map_configuration.id}")}>Show <.modal id={"square-wall-#{map_configuration.id}"}> -

<%= json_encode(map_configuration.square_wall) %>

+

+ <%= embed_to_string(map_configuration.square_wall) |> Jason.encode!() |> Jason.Formatter.pretty_print() %> +

<% end %> diff --git a/apps/configurator/lib/configurator_web/controllers/map_configuration_html/map_configuration_form.html.heex b/apps/configurator/lib/configurator_web/controllers/map_configuration_html/map_configuration_form.html.heex index 00880c160..5fa9b6a8c 100644 --- a/apps/configurator/lib/configurator_web/controllers/map_configuration_html/map_configuration_form.html.heex +++ b/apps/configurator/lib/configurator_web/controllers/map_configuration_html/map_configuration_form.html.heex @@ -6,9 +6,14 @@ <.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]} @@ -16,7 +21,12 @@ label="Initial positions" value={embed_to_string(f[:initial_positions].value)} /> - <.input field={f[:square_wall]} type="textarea" label="Square Wall" value={json_encode(f[:square_wall].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)} /> diff --git a/apps/configurator/lib/configurator_web/controllers/map_configuration_html/show.html.heex b/apps/configurator/lib/configurator_web/controllers/map_configuration_html/show.html.heex index 726d2837c..1a6121a38 100644 --- a/apps/configurator/lib/configurator_web/controllers/map_configuration_html/show.html.heex +++ b/apps/configurator/lib/configurator_web/controllers/map_configuration_html/show.html.heex @@ -105,7 +105,9 @@ <% else %> <.button type="button" phx-click={show_modal("square-wall-#{@map_configuration.id}")}>Show <.modal id={"square-wall-#{@map_configuration.id}"}> -

<%= json_encode(@map_configuration.square_wall) %>

+

+ <%= embed_to_string(@map_configuration.square_wall) |> Jason.encode!() |> Jason.Formatter.pretty_print() %> +

<% end %> diff --git a/apps/configurator/test/configurator_web/controllers/map_configuration_controller_test.exs b/apps/configurator/test/configurator_web/controllers/map_configuration_controller_test.exs index d425f3b7f..64b5a3dd6 100644 --- a/apps/configurator/test/configurator_web/controllers/map_configuration_controller_test.exs +++ b/apps/configurator/test/configurator_web/controllers/map_configuration_controller_test.exs @@ -13,7 +13,8 @@ defmodule ConfiguratorWeb.MapConfigurationControllerTest do bushes: "", pools: "", crates: "", - active: true + active: true, + square_wall: "" } @update_attrs %{ name: "another_map", @@ -23,7 +24,8 @@ defmodule ConfiguratorWeb.MapConfigurationControllerTest do bushes: "", pools: "", crates: "", - active: false + active: false, + square_wall: nil } @invalid_attrs %{ name: nil, @@ -33,7 +35,8 @@ defmodule ConfiguratorWeb.MapConfigurationControllerTest do bushes: nil, pools: nil, crates: nil, - active: nil + active: nil, + square_wall: "" } describe "index" do diff --git a/apps/game_backend/lib/game_backend/curse_of_mirra/map_configuration.ex b/apps/game_backend/lib/game_backend/curse_of_mirra/map_configuration.ex index eaa8240d7..b8546528a 100644 --- a/apps/game_backend/lib/game_backend/curse_of_mirra/map_configuration.ex +++ b/apps/game_backend/lib/game_backend/curse_of_mirra/map_configuration.ex @@ -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