diff --git a/apps/champions/lib/champions/config.ex b/apps/champions/lib/champions/config.ex index 10505d95d..e22acf581 100644 --- a/apps/champions/lib/champions/config.ex +++ b/apps/champions/lib/champions/config.ex @@ -22,12 +22,13 @@ defmodule Champions.Config do @doc """ Imports the skills configuration from 'skills.json' in the app's priv folder. """ - def import_skill_config() do + def import_skill_config(game_id) do {:ok, skills_json} = Application.app_dir(:champions, "priv/skills.json") |> File.read() Jason.decode!(skills_json, [{:keys, :atoms}]) + |> Enum.map(fn skill -> Map.put(skill, :game_id, game_id) end) |> Skills.upsert_skills() end diff --git a/apps/configurator/assets/css/app.css b/apps/configurator/assets/css/app.css index 378c8f905..4ad267ab4 100644 --- a/apps/configurator/assets/css/app.css +++ b/apps/configurator/assets/css/app.css @@ -2,4 +2,41 @@ @import "tailwindcss/components"; @import "tailwindcss/utilities"; + +.form-container { + display: flex; /* Make the container a flex container */ + flex-wrap: wrap; /* Allow items to wrap to the next line if needed */ + align-items: center; + justify-content: center; +} + +.form-container > div { + padding: 10px; +} + +.input-item { + border-bottom: 1px solid #ccc; + margin-bottom: 10px; + align-items: center; + flex-wrap: wrap; +} + +.input-item > div { + padding: 10px; + flex: 0 0 150px; +} + +.left{ + position: absolute; + top: 0px; + left: 10px; + text-align: left; + } + +.right{ + position: absolute; + top: 0px; + right: 10px; + } + /* This file is for your main application CSS */ diff --git a/apps/configurator/lib/configurator_web/components/core_components.ex b/apps/configurator/lib/configurator_web/components/core_components.ex index c7d4718e1..690b4c7d0 100644 --- a/apps/configurator/lib/configurator_web/components/core_components.ex +++ b/apps/configurator/lib/configurator_web/components/core_components.ex @@ -209,6 +209,42 @@ defmodule ConfiguratorWeb.CoreComponents do """ end + @doc """ + Renders a css flex container styled simple form. + + ## Examples + + <.flex_form for={@form} phx-change="validate" phx-submit="save"> + <.input field={@form[:email]} label="Email"/> + <.input field={@form[:username]} label="Username" /> + <:actions> + <.button>Save + + + """ + attr :for, :any, required: true, doc: "the datastructure for the form" + attr :as, :any, default: nil, doc: "the server side parameter to collect all input under" + + attr :rest, :global, + include: ~w(autocomplete name rel action enctype method novalidate target multipart), + doc: "the arbitrary HTML attributes to apply to the form tag" + + slot :inner_block, required: true + slot :actions, doc: "the slot for form actions, such as a submit button" + + def flex_form(assigns) do + ~H""" + <.form :let={f} for={@for} as={@as} {@rest}> +
+ <%= render_slot(@inner_block, f) %> +
+ <%= render_slot(action, f) %> +
+
+ + """ + end + @doc """ Renders a button. diff --git a/apps/configurator/lib/configurator_web/components/custom_components.ex b/apps/configurator/lib/configurator_web/components/custom_components.ex index d2c2062a5..b5da29aa5 100644 --- a/apps/configurator/lib/configurator_web/components/custom_components.ex +++ b/apps/configurator/lib/configurator_web/components/custom_components.ex @@ -50,6 +50,12 @@ defmodule ConfiguratorWeb.CustomComponents do attr :form, :map, required: true attr :field, :atom, required: true + def effect_form(%{form: %{params: %{"effect" => nil}}} = assigns) do + ~H""" +

No Effect

+ """ + end + def effect_form(assigns) do ~H""" <.button type="button" phx-click={show_modal("effect-form")}>Edit effect @@ -74,7 +80,11 @@ defmodule ConfiguratorWeb.CustomComponents do /> <.input field={mechanics_form[:modifier]} type="number" label="Modifier" step="any" /> <.input field={mechanics_form[:force]} type="number" label="Force" step="any" /> - <.input field={effect_f[:execute_multiple_times]} type="checkbox" label="Execute mechanic multiple times" /> + <.input + field={mechanics_form[:execute_multiple_times]} + type="checkbox" + label="Execute mechanic multiple times" + /> <.input field={mechanics_form[:damage]} type="number" label="Damage amount" /> <.input field={mechanics_form[:effect_delay_ms]} type="number" label="Mechanic delay" /> <.input field={mechanics_form[:additive_duration_add_ms]} type="number" label="Additive duration to add ms" /> diff --git a/apps/configurator/lib/configurator_web/components/layouts/app.html.heex b/apps/configurator/lib/configurator_web/components/layouts/app.html.heex index 6cadb8c8f..9d51ce2e7 100644 --- a/apps/configurator/lib/configurator_web/components/layouts/app.html.heex +++ b/apps/configurator/lib/configurator_web/components/layouts/app.html.heex @@ -1,5 +1,5 @@
-
+
<.flash_group flash={@flash} /> <%= @inner_content %> diff --git a/apps/configurator/lib/configurator_web/components/layouts/root.html.heex b/apps/configurator/lib/configurator_web/components/layouts/root.html.heex index 847fb75a5..6803eb222 100644 --- a/apps/configurator/lib/configurator_web/components/layouts/root.html.heex +++ b/apps/configurator/lib/configurator_web/components/layouts/root.html.heex @@ -1,4 +1,32 @@ + + @@ -12,22 +40,39 @@ -
    - <%= if @current_user do %> -
  • - <%= @current_user.email %> -
  • -
  • - <.link - href={~p"/users/log_out"} - method="delete" - class="text-[0.8125rem] leading-6 text-zinc-900 font-semibold hover:text-zinc-700" - > - Log out - -
  • - <% end %> -
+ <%= @inner_content %> diff --git a/apps/configurator/lib/configurator_web/controllers/character_controller.ex b/apps/configurator/lib/configurator_web/controllers/character_controller.ex index b576a781e..9dcd6bee1 100644 --- a/apps/configurator/lib/configurator_web/controllers/character_controller.ex +++ b/apps/configurator/lib/configurator_web/controllers/character_controller.ex @@ -4,16 +4,18 @@ defmodule ConfiguratorWeb.CharacterController do alias GameBackend.Units.Characters alias GameBackend.Units.Characters.Character alias GameBackend.Configuration + alias GameBackend.Utils - def index(conn, _params) do - characters = Characters.get_curse_characters() - render(conn, :index, characters: characters) + def index(conn, %{"version_id" => version_id}) do + characters = Characters.get_curse_characters_by_version(version_id) + render(conn, :index, characters: characters, version_id: version_id) end - def new(conn, _params) do + def new(conn, %{"version_id" => version_id}) do changeset = Ecto.Changeset.change(%Character{}) - skills = get_curse_skills_by_type() - render(conn, :new, changeset: changeset, skills: skills) + version = Configuration.get_version!(version_id) + skills = Utils.list_curse_skills_by_version_grouped_by_type(version.id) + render(conn, :new, changeset: changeset, skills: skills, version: version) end def create(conn, %{"character" => character_params}) do @@ -26,11 +28,12 @@ defmodule ConfiguratorWeb.CharacterController do {:ok, character} -> conn |> put_flash(:success, "Character created successfully.") - |> redirect(to: ~p"/characters/#{character}") + |> redirect(to: ~p"/versions/#{character.version_id}/characters/#{character}") {:error, %Ecto.Changeset{} = changeset} -> - skills = get_curse_skills_by_type() - render(conn, :new, changeset: changeset, skills: skills) + version = Configuration.get_version!(character_params["version_id"]) + skills = Utils.list_curse_skills_by_version_grouped_by_type(version.id) + render(conn, :new, changeset: changeset, skills: skills, version: version) end end @@ -43,8 +46,9 @@ defmodule ConfiguratorWeb.CharacterController do def edit(conn, %{"id" => id}) do character = Characters.get_character(id) changeset = Ecto.Changeset.change(character) - skills = get_curse_skills_by_type() - render(conn, :edit, character: character, changeset: changeset, skills: skills) + version = Configuration.get_version!(character.version_id) + skills = Utils.list_curse_skills_by_version_grouped_by_type(version.id) + render(conn, :edit, character: character, changeset: changeset, skills: skills, version: version) end def update(conn, %{"id" => id, "character" => character_params}) do @@ -54,25 +58,22 @@ defmodule ConfiguratorWeb.CharacterController do {:ok, character} -> conn |> put_flash(:success, "Character updated successfully.") - |> redirect(to: ~p"/characters/#{character}") + |> redirect(to: ~p"/versions/#{character.version_id}/characters/#{character}") {:error, %Ecto.Changeset{} = changeset} -> - skills = get_curse_skills_by_type() - render(conn, :edit, character: character, changeset: changeset, skills: skills) + version = Configuration.get_version!(character.version_id) + skills = Utils.list_curse_skills_by_version_grouped_by_type(version.id) + render(conn, :edit, character: character, changeset: changeset, skills: skills, version: version) end end def delete(conn, %{"id" => id}) do character = Characters.get_character(id) + version_id = character.version_id {:ok, _character} = Characters.delete_character(character) conn |> put_flash(:success, "Character deleted successfully.") - |> redirect(to: ~p"/characters") - end - - defp get_curse_skills_by_type() do - GameBackend.Units.Skills.list_curse_skills() - |> Enum.group_by(& &1.type) + |> redirect(to: ~p"/versions/#{version_id}/characters") end end diff --git a/apps/configurator/lib/configurator_web/controllers/character_html.ex b/apps/configurator/lib/configurator_web/controllers/character_html.ex index 541722299..6b93b9350 100644 --- a/apps/configurator/lib/configurator_web/controllers/character_html.ex +++ b/apps/configurator/lib/configurator_web/controllers/character_html.ex @@ -9,6 +9,7 @@ defmodule ConfiguratorWeb.CharacterHTML do attr :changeset, Ecto.Changeset, required: true attr :action, :string, required: true attr :skills, :list, required: true + attr :version, GameBackend.Configuration.Version, required: true def character_form(assigns) diff --git a/apps/configurator/lib/configurator_web/controllers/character_html/character_form.html.heex b/apps/configurator/lib/configurator_web/controllers/character_html/character_form.html.heex index a9a356b2e..c8f61d9ab 100644 --- a/apps/configurator/lib/configurator_web/controllers/character_html/character_form.html.heex +++ b/apps/configurator/lib/configurator_web/controllers/character_html/character_form.html.heex @@ -2,12 +2,8 @@ <.error :if={@changeset.action}> Oops, something went wrong! Please check the errors below. - <.input - field={f[:version_id]} - type="select" - options={Enum.map(GameBackend.Configuration.list_versions(), fn version -> {version.name, version.id} end)} - label="Version" - /> +

<%= "Version: #{@version.name}" %>

+ <.input type="hidden" field={f[:version_id]} value={@version.id} /> <.input field={f[:name]} type="text" label="Name" /> <.input field={f[:active]} type="checkbox" label="Active" /> <.input field={f[:base_speed]} type="number" label="Base speed" step="any" /> diff --git a/apps/configurator/lib/configurator_web/controllers/character_html/edit.html.heex b/apps/configurator/lib/configurator_web/controllers/character_html/edit.html.heex index e6c65b2fb..a77823e15 100644 --- a/apps/configurator/lib/configurator_web/controllers/character_html/edit.html.heex +++ b/apps/configurator/lib/configurator_web/controllers/character_html/edit.html.heex @@ -3,6 +3,11 @@ <:subtitle>Use this form to manage character records in your database. -<.character_form changeset={@changeset} action={~p"/characters/#{@character}"} skills={@skills} /> +<.character_form + changeset={@changeset} + action={~p"/versions/#{@version}/characters/#{@character}"} + skills={@skills} + version={@version} +/> -<.back navigate={~p"/characters"}>Back to characters +<.back navigate={~p"/versions/#{@version}/characters"}>Back to characters diff --git a/apps/configurator/lib/configurator_web/controllers/character_html/index.html.heex b/apps/configurator/lib/configurator_web/controllers/character_html/index.html.heex index f1e490c92..b409f5106 100644 --- a/apps/configurator/lib/configurator_web/controllers/character_html/index.html.heex +++ b/apps/configurator/lib/configurator_web/controllers/character_html/index.html.heex @@ -1,13 +1,13 @@ <.header> Characters <:actions> - <.link href={~p"/characters/new"}> + <.link href={~p"/versions/#{@version_id}/characters/new"}> <.button>New Character -<.table id="characters" rows={@characters} row_click={&JS.navigate(~p"/characters/#{&1}")}> +<.table id="characters" rows={@characters} row_click={&JS.navigate(~p"/versions/#{@version_id}/characters/#{&1}")}> <:col :let={character} label="Name"><%= character.name %> <:col :let={character} label="Active"><%= character.active %> <:col :let={character} label="Base speed"><%= character.base_speed %> @@ -32,12 +32,12 @@ <:action :let={character}>
- <.link navigate={~p"/characters/#{character}"}>Show + <.link navigate={~p"/versions/#{@version_id}/characters/#{character}"}>Show
- <.link navigate={~p"/characters/#{character}/edit"}>Edit + <.link navigate={~p"/versions/#{@version_id}/characters/#{character}/edit"}>Edit <:action :let={character}> - <.link href={~p"/characters/#{character}"} method="delete" data-confirm="Are you sure?"> + <.link href={~p"/versions/#{@version_id}/characters/#{character}"} method="delete" data-confirm="Are you sure?"> Delete diff --git a/apps/configurator/lib/configurator_web/controllers/character_html/new.html.heex b/apps/configurator/lib/configurator_web/controllers/character_html/new.html.heex index ff3d56330..9b7633e70 100644 --- a/apps/configurator/lib/configurator_web/controllers/character_html/new.html.heex +++ b/apps/configurator/lib/configurator_web/controllers/character_html/new.html.heex @@ -3,6 +3,11 @@ <:subtitle>Use this form to manage character records in your database. -<.character_form changeset={@changeset} action={~p"/characters"} skills={@skills} /> +<.character_form + changeset={@changeset} + action={~p"/versions/#{@version}/characters"} + skills={@skills} + version={@version} +/> -<.back navigate={~p"/characters"}>Back to characters +<.back navigate={~p"/versions/#{@version}/characters"}>Back to characters diff --git a/apps/configurator/lib/configurator_web/controllers/character_html/show.html.heex b/apps/configurator/lib/configurator_web/controllers/character_html/show.html.heex index bedbfff9e..58d7faee2 100644 --- a/apps/configurator/lib/configurator_web/controllers/character_html/show.html.heex +++ b/apps/configurator/lib/configurator_web/controllers/character_html/show.html.heex @@ -2,7 +2,7 @@ Character <%= @character.name %> <:subtitle>Version: <%= @version.name %> <:actions> - <.link href={~p"/characters/#{@character}/edit"}> + <.link href={~p"/versions/#{@version}/characters/#{@character}/edit"}> <.button>Edit character @@ -30,4 +30,4 @@ <:item title="Ultimate skill"><%= if @character.ultimate_skill, do: @character.ultimate_skill.name %> -<.back navigate={~p"/characters"}>Back to characters +<.back navigate={~p"/versions/#{@version}/characters"}>Back to characters diff --git a/apps/configurator/lib/configurator_web/controllers/consumable_item_controller.ex b/apps/configurator/lib/configurator_web/controllers/consumable_item_controller.ex index 645d18337..398d54ce9 100644 --- a/apps/configurator/lib/configurator_web/controllers/consumable_item_controller.ex +++ b/apps/configurator/lib/configurator_web/controllers/consumable_item_controller.ex @@ -5,14 +5,15 @@ defmodule ConfiguratorWeb.ConsumableItemController do alias GameBackend.Items.ConsumableItem alias GameBackend.Configuration - def index(conn, _params) do - consumable_items = Items.list_consumable_items() - render(conn, :index, consumable_items: consumable_items) + def index(conn, %{"version_id" => version_id}) do + consumable_items = Items.list_consumable_items_by_version(version_id) + render(conn, :index, consumable_items: consumable_items, version_id: version_id) end - def new(conn, _params) do + def new(conn, %{"version_id" => version_id}) do changeset = Items.change_consumable_item(%ConsumableItem{}) - render(conn, :new, changeset: changeset) + version = Configuration.get_version!(version_id) + render(conn, :new, changeset: changeset, version: version) end def create(conn, %{"consumable_item" => consumable_item_params}) do @@ -20,10 +21,11 @@ defmodule ConfiguratorWeb.ConsumableItemController do {:ok, consumable_item} -> conn |> put_flash(:info, "Consumable item created successfully.") - |> redirect(to: ~p"/consumable_items/#{consumable_item}") + |> redirect(to: ~p"/versions/#{consumable_item_params.version_id}/consumable_items/#{consumable_item}") {:error, %Ecto.Changeset{} = changeset} -> - render(conn, :new, changeset: changeset) + version = Configuration.get_version!(consumable_item_params["version_id"]) + render(conn, :new, changeset: changeset, version: version) end end @@ -36,7 +38,8 @@ defmodule ConfiguratorWeb.ConsumableItemController do def edit(conn, %{"id" => id}) do consumable_item = Items.get_consumable_item!(id) changeset = Items.change_consumable_item(consumable_item) - render(conn, :edit, consumable_item: consumable_item, changeset: changeset) + version = Configuration.get_version!(consumable_item.version_id) + render(conn, :edit, consumable_item: consumable_item, changeset: changeset, version: version) end def update(conn, %{"id" => id, "consumable_item" => consumable_item_params}) do @@ -46,19 +49,21 @@ defmodule ConfiguratorWeb.ConsumableItemController do {:ok, consumable_item} -> conn |> put_flash(:info, "Consumable item updated successfully.") - |> redirect(to: ~p"/consumable_items/#{consumable_item}") + |> redirect(to: ~p"/versions/#{consumable_item_params.version_id}/consumable_items/#{consumable_item}") {:error, %Ecto.Changeset{} = changeset} -> - render(conn, :edit, consumable_item: consumable_item, changeset: changeset) + version = Configuration.get_version!(consumable_item.version_id) + render(conn, :edit, consumable_item: consumable_item, changeset: changeset, version: version) end end def delete(conn, %{"id" => id}) do consumable_item = Items.get_consumable_item!(id) + version_id = consumable_item.version_id {:ok, _consumable_item} = Items.delete_consumable_item(consumable_item) conn |> put_flash(:info, "Consumable item deleted successfully.") - |> redirect(to: ~p"/consumable_items") + |> redirect(to: ~p"/versions/#{version_id}/consumable_items") end end diff --git a/apps/configurator/lib/configurator_web/controllers/consumable_item_html/edit.html.heex b/apps/configurator/lib/configurator_web/controllers/consumable_item_html/edit.html.heex index 3bda2bba2..f33f8d4b6 100644 --- a/apps/configurator/lib/configurator_web/controllers/consumable_item_html/edit.html.heex +++ b/apps/configurator/lib/configurator_web/controllers/consumable_item_html/edit.html.heex @@ -3,4 +3,6 @@ <:subtitle>Use this form to manage Consumable Item records in your database. -<%= live_render(@conn, ConfiguratorWeb.ConsumableItemsLive.Form, session: %{"consumable_item" => @consumable_item}) %> +<%= live_render(@conn, ConfiguratorWeb.ConsumableItemsLive.Form, + session: %{"consumable_item" => @consumable_item, "version" => @version} +) %> diff --git a/apps/configurator/lib/configurator_web/controllers/consumable_item_html/index.html.heex b/apps/configurator/lib/configurator_web/controllers/consumable_item_html/index.html.heex index 863264dc3..1d45bb911 100644 --- a/apps/configurator/lib/configurator_web/controllers/consumable_item_html/index.html.heex +++ b/apps/configurator/lib/configurator_web/controllers/consumable_item_html/index.html.heex @@ -1,20 +1,28 @@ <.header> Listing Consumable items <:actions> - <.link href={~p"/consumable_items/new"}> + <.link href={~p"/versions/#{@version_id}/consumable_items/new"}> <.button>New Consumable item -<.table id="consumable_items" rows={@consumable_items} row_click={&JS.navigate(~p"/consumable_items/#{&1}")}> +<.table + id="consumable_items" + rows={@consumable_items} + row_click={&JS.navigate(~p"/versions/#{@version_id}/consumable_items/#{&1}")} +> <:col :let={consumable_item} label="Name"><%= consumable_item.name %> <:col :let={consumable_item} label="Radius"><%= consumable_item.radius %> <:action :let={consumable_item}> - <.link navigate={~p"/consumable_items/#{consumable_item}/edit"}>Edit + <.link navigate={~p"/versions/#{@version_id}/consumable_items/#{consumable_item}/edit"}>Edit <:action :let={consumable_item}> - <.link href={~p"/consumable_items/#{consumable_item}"} method="delete" data-confirm="Are you sure?"> + <.link + href={~p"/versions/#{@version_id}/consumable_items/#{consumable_item}"} + method="delete" + data-confirm="Are you sure?" + > Delete diff --git a/apps/configurator/lib/configurator_web/controllers/consumable_item_html/new.html.heex b/apps/configurator/lib/configurator_web/controllers/consumable_item_html/new.html.heex index 3ce8899f4..de2bd2bea 100644 --- a/apps/configurator/lib/configurator_web/controllers/consumable_item_html/new.html.heex +++ b/apps/configurator/lib/configurator_web/controllers/consumable_item_html/new.html.heex @@ -3,4 +3,4 @@ <:subtitle>Use this form to manage Consumable Item records in your database. -<%= live_render(@conn, ConfiguratorWeb.ConsumableItemsLive.Form, session: %{}) %> +<%= live_render(@conn, ConfiguratorWeb.ConsumableItemsLive.Form, session: %{"version" => @version}) %> diff --git a/apps/configurator/lib/configurator_web/controllers/consumable_item_html/show.html.heex b/apps/configurator/lib/configurator_web/controllers/consumable_item_html/show.html.heex index 5e171f89a..7ba903551 100644 --- a/apps/configurator/lib/configurator_web/controllers/consumable_item_html/show.html.heex +++ b/apps/configurator/lib/configurator_web/controllers/consumable_item_html/show.html.heex @@ -2,7 +2,7 @@ Consumable item <%= @consumable_item.name %> <:subtitle>Version: <%= @version.name %> <:actions> - <.link href={~p"/consumable_items/#{@consumable_item}/edit"}> + <.link href={~p"/versions/#{@version}/consumable_items/#{@consumable_item}/edit"}> <.button>Edit Consumable item <.effect_show effect={@consumable_item.effect} /> @@ -24,4 +24,4 @@
-<.back navigate={~p"/consumable_items"}>Back to Consumable Items +<.back navigate={~p"/versions/#{@version}/consumable_items"}>Back to Consumable Items diff --git a/apps/configurator/lib/configurator_web/controllers/game_configuration_controller.ex b/apps/configurator/lib/configurator_web/controllers/game_configuration_controller.ex index ecd5d7a46..180adcc33 100644 --- a/apps/configurator/lib/configurator_web/controllers/game_configuration_controller.ex +++ b/apps/configurator/lib/configurator_web/controllers/game_configuration_controller.ex @@ -4,14 +4,15 @@ defmodule ConfiguratorWeb.GameConfigurationController do alias GameBackend.Configuration alias GameBackend.CurseOfMirra.GameConfiguration - def index(conn, _params) do - game_configurations = Configuration.list_game_configurations() - render(conn, :index, game_configurations: game_configurations) + def index(conn, %{"version_id" => version_id}) do + game_configurations = Configuration.list_game_configurations_by_version(version_id) + render(conn, :index, game_configurations: game_configurations, version_id: version_id) end - def new(conn, _params) do + def new(conn, %{"version_id" => version_id}) do changeset = Configuration.change_game_configuration(%GameConfiguration{}) - render(conn, :new, changeset: changeset) + version = Configuration.get_version!(version_id) + render(conn, :new, changeset: changeset, version: version) end def create(conn, %{"game_configuration" => game_configuration_params}) do @@ -19,10 +20,11 @@ defmodule ConfiguratorWeb.GameConfigurationController do {:ok, game_configuration} -> conn |> put_flash(:info, "Game configuration created successfully.") - |> redirect(to: ~p"/game_configurations/#{game_configuration}") + |> redirect(to: ~p"/versions/#{game_configuration.version_id}/game_configurations/#{game_configuration}") {:error, %Ecto.Changeset{} = changeset} -> - render(conn, :new, changeset: changeset) + version = Configuration.get_version!(game_configuration_params["version_id"]) + render(conn, :new, changeset: changeset, version: version) end end @@ -35,7 +37,8 @@ defmodule ConfiguratorWeb.GameConfigurationController do def edit(conn, %{"id" => id}) do game_configuration = Configuration.get_game_configuration!(id) changeset = Configuration.change_game_configuration(game_configuration) - render(conn, :edit, game_configuration: game_configuration, changeset: changeset) + version = Configuration.get_version!(game_configuration.version_id) + render(conn, :edit, game_configuration: game_configuration, changeset: changeset, version: version) end def update(conn, %{"id" => id, "game_configuration" => game_configuration_params}) do @@ -45,19 +48,21 @@ defmodule ConfiguratorWeb.GameConfigurationController do {:ok, game_configuration} -> conn |> put_flash(:info, "Game configuration updated successfully.") - |> redirect(to: ~p"/game_configurations/#{game_configuration}") + |> redirect(to: ~p"/versions/#{game_configuration.version_id}/game_configurations/#{game_configuration}") {:error, %Ecto.Changeset{} = changeset} -> - render(conn, :edit, game_configuration: game_configuration, changeset: changeset) + version = Configuration.get_version!(game_configuration.version_id) + render(conn, :edit, game_configuration: game_configuration, changeset: changeset, version: version) end end def delete(conn, %{"id" => id}) do game_configuration = Configuration.get_game_configuration!(id) + version_id = game_configuration.version_id {:ok, _game_configuration} = Configuration.delete_game_configuration(game_configuration) conn |> put_flash(:info, "Game configuration deleted successfully.") - |> redirect(to: ~p"/game_configurations") + |> redirect(to: ~p"/versions/#{version_id}/game_configurations") end end diff --git a/apps/configurator/lib/configurator_web/controllers/game_configuration_html.ex b/apps/configurator/lib/configurator_web/controllers/game_configuration_html.ex index 78971c205..bf26031f5 100644 --- a/apps/configurator/lib/configurator_web/controllers/game_configuration_html.ex +++ b/apps/configurator/lib/configurator_web/controllers/game_configuration_html.ex @@ -8,6 +8,7 @@ defmodule ConfiguratorWeb.GameConfigurationHTML do """ attr :changeset, Ecto.Changeset, required: true attr :action, :string, required: true + attr :version, GameBackend.Configuration.Version, required: true def game_configuration_form(assigns) end diff --git a/apps/configurator/lib/configurator_web/controllers/game_configuration_html/edit.html.heex b/apps/configurator/lib/configurator_web/controllers/game_configuration_html/edit.html.heex index f866c3d94..f6d4250ca 100644 --- a/apps/configurator/lib/configurator_web/controllers/game_configuration_html/edit.html.heex +++ b/apps/configurator/lib/configurator_web/controllers/game_configuration_html/edit.html.heex @@ -3,6 +3,10 @@ <:subtitle>Use this form to manage game_configuration records in your database. -<.game_configuration_form changeset={@changeset} action={~p"/game_configurations/#{@game_configuration}"} /> +<.game_configuration_form + changeset={@changeset} + action={~p"/versions/#{@version}/game_configurations/#{@game_configuration}"} + version={@version} +/> -<.back navigate={~p"/game_configurations"}>Back to game_configurations +<.back navigate={~p"/versions/#{@version}/game_configurations"}>Back to game_configurations diff --git a/apps/configurator/lib/configurator_web/controllers/game_configuration_html/game_configuration_form.html.heex b/apps/configurator/lib/configurator_web/controllers/game_configuration_html/game_configuration_form.html.heex index 4734ecbed..589b7677f 100644 --- a/apps/configurator/lib/configurator_web/controllers/game_configuration_html/game_configuration_form.html.heex +++ b/apps/configurator/lib/configurator_web/controllers/game_configuration_html/game_configuration_form.html.heex @@ -2,12 +2,8 @@ <.error :if={@changeset.action}> Oops, something went wrong! Please check the errors below. - <.input - field={f[:version_id]} - type="select" - options={Enum.map(GameBackend.Configuration.list_versions(), fn version -> {version.name, version.id} end)} - label="Version" - /> +

<%= "Version: #{@version.name}" %>

+ <.input type="hidden" field={f[:version_id]} value={@version.id} /> <.input field={f[:tick_rate_ms]} type="number" label="Tick rate ms" /> <.input field={f[:bounty_pick_time_ms]} type="number" label="Bounty pick time ms" /> <.input field={f[:start_game_time_ms]} type="number" label="Start game time ms" /> diff --git a/apps/configurator/lib/configurator_web/controllers/game_configuration_html/index.html.heex b/apps/configurator/lib/configurator_web/controllers/game_configuration_html/index.html.heex index 31838e554..4d440e8b7 100644 --- a/apps/configurator/lib/configurator_web/controllers/game_configuration_html/index.html.heex +++ b/apps/configurator/lib/configurator_web/controllers/game_configuration_html/index.html.heex @@ -1,13 +1,17 @@ <.header> Listing Game configurations <:actions> - <.link href={~p"/game_configurations/new"}> + <.link href={~p"/versions/#{@version_id}/game_configurations/new"}> <.button>New Game configuration -<.table id="game_configurations" rows={@game_configurations} row_click={&JS.navigate(~p"/game_configurations/#{&1}")}> +<.table + id="game_configurations" + rows={@game_configurations} + row_click={&JS.navigate(~p"/versions/#{@version_id}/game_configurations/#{&1}")} +> <:col :let={game_configuration} label="Tick rate ms"><%= game_configuration.tick_rate_ms %> <:col :let={game_configuration} label="Bounty pick time ms"><%= game_configuration.bounty_pick_time_ms %> <:col :let={game_configuration} label="Start game time ms"><%= game_configuration.start_game_time_ms %> @@ -41,12 +45,16 @@ <:action :let={game_configuration}>
- <.link navigate={~p"/game_configurations/#{game_configuration}"}>Show + <.link navigate={~p"/versions/#{@version_id}/game_configurations/#{game_configuration}"}>Show
- <.link navigate={~p"/game_configurations/#{game_configuration}/edit"}>Edit + <.link navigate={~p"/versions/#{@version_id}/game_configurations/#{game_configuration}/edit"}>Edit <:action :let={game_configuration}> - <.link href={~p"/game_configurations/#{game_configuration}"} method="delete" data-confirm="Are you sure?"> + <.link + href={~p"/versions/#{@version_id}/game_configurations/#{game_configuration}"} + method="delete" + data-confirm="Are you sure?" + > Delete diff --git a/apps/configurator/lib/configurator_web/controllers/game_configuration_html/new.html.heex b/apps/configurator/lib/configurator_web/controllers/game_configuration_html/new.html.heex index fe5048b57..6e7bdfc0b 100644 --- a/apps/configurator/lib/configurator_web/controllers/game_configuration_html/new.html.heex +++ b/apps/configurator/lib/configurator_web/controllers/game_configuration_html/new.html.heex @@ -3,6 +3,10 @@ <:subtitle>Use this form to manage game_configuration records in your database. -<.game_configuration_form changeset={@changeset} action={~p"/game_configurations"} /> +<.game_configuration_form + changeset={@changeset} + action={~p"/versions/#{@version}/game_configurations"} + version={@version} +/> -<.back navigate={~p"/game_configurations"}>Back to game_configurations +<.back navigate={~p"/versions/#{@version}/game_configurations"}>Back to game_configurations diff --git a/apps/configurator/lib/configurator_web/controllers/game_configuration_html/show.html.heex b/apps/configurator/lib/configurator_web/controllers/game_configuration_html/show.html.heex index ad503d808..6b674168a 100644 --- a/apps/configurator/lib/configurator_web/controllers/game_configuration_html/show.html.heex +++ b/apps/configurator/lib/configurator_web/controllers/game_configuration_html/show.html.heex @@ -2,7 +2,7 @@ Game configuration <%= @game_configuration.id %> <:subtitle>Version: <%= @version.name %> <:actions> - <.link href={~p"/game_configurations/#{@game_configuration}/edit"}> + <.link href={~p"/versions/#{@version}/game_configurations/#{@game_configuration}/edit"}> <.button>Edit game_configuration @@ -51,4 +51,4 @@ <% end %> -<.back navigate={~p"/game_configurations"}>Back to game_configurations +<.back navigate={~p"/versions/#{@version}/game_configurations"}>Back to game_configurations diff --git a/apps/configurator/lib/configurator_web/controllers/home_html/home.html.heex b/apps/configurator/lib/configurator_web/controllers/home_html/home.html.heex index 02c255148..46bd8683c 100644 --- a/apps/configurator/lib/configurator_web/controllers/home_html/home.html.heex +++ b/apps/configurator/lib/configurator_web/controllers/home_html/home.html.heex @@ -3,13 +3,15 @@ Welcome to Champions of Mirra Configurator + <.link href={~p"/versions/new"}> + <.button>New Version + + <.link href={~p"/versions/show_current_version"}> + <.button>See Current Version + + <.list> <:item title="Versions"><.link href={~p"/versions"}>Link - <:item title="Character settings"><.link href={~p"/characters"}>Link - <:item title="Game settings"><.link href={~p"/game_configurations"}>Link - <:item title="Map settings"><.link href={~p"/map_configurations"}>Link - <:item title="Skill settings"><.link href={~p"/skills"}>Link - <:item title="Consumable Items"><.link href={~p"/consumable_items"}>Link <:item title="Arena servers"><.link href={~p"/arena_servers"}>Link <% else %> diff --git a/apps/configurator/lib/configurator_web/controllers/map_configuration_controller.ex b/apps/configurator/lib/configurator_web/controllers/map_configuration_controller.ex index 130820a08..c24ddcfdb 100644 --- a/apps/configurator/lib/configurator_web/controllers/map_configuration_controller.ex +++ b/apps/configurator/lib/configurator_web/controllers/map_configuration_controller.ex @@ -5,14 +5,15 @@ defmodule ConfiguratorWeb.MapConfigurationController do alias GameBackend.CurseOfMirra.MapConfiguration alias GameBackend.Configuration - def index(conn, _params) do - map_configurations = Configuration.list_map_configurations() - render(conn, :index, map_configurations: map_configurations) + def index(conn, %{"version_id" => version_id}) do + map_configurations = Configuration.list_map_configurations_by_version(version_id) + render(conn, :index, map_configurations: map_configurations, version_id: version_id) end - def new(conn, _params) do + def new(conn, %{"version_id" => version_id}) do changeset = Configuration.change_map_configuration(%MapConfiguration{}) - render(conn, :new, changeset: changeset) + version = Configuration.get_version!(version_id) + render(conn, :new, changeset: changeset, version: version) end def create(conn, %{"map_configuration" => map_configuration_params}) do @@ -22,10 +23,11 @@ defmodule ConfiguratorWeb.MapConfigurationController do {:ok, map_configuration} -> conn |> put_flash(:info, "Map configuration created successfully.") - |> redirect(to: ~p"/map_configurations/#{map_configuration}") + |> redirect(to: ~p"/versions/#{map_configuration.version_id}/map_configurations/#{map_configuration}") {:error, %Ecto.Changeset{} = changeset} -> - render(conn, :new, changeset: changeset) + version = Configuration.get_version!(map_configuration_params["version_id"]) + render(conn, :new, changeset: changeset, version: version) end end @@ -37,9 +39,9 @@ defmodule ConfiguratorWeb.MapConfigurationController do def edit(conn, %{"id" => id}) do map_configuration = Configuration.get_map_configuration!(id) - + version = Configuration.get_version!(map_configuration.version_id) changeset = Configuration.change_map_configuration(map_configuration) - render(conn, :edit, map_configuration: map_configuration, changeset: changeset) + render(conn, :edit, map_configuration: map_configuration, changeset: changeset, version: version) end def update(conn, %{"id" => id, "map_configuration" => map_configuration_params}) do @@ -50,31 +52,32 @@ defmodule ConfiguratorWeb.MapConfigurationController do {:ok, map_configuration} -> conn |> put_flash(:info, "Map configuration updated successfully.") - |> redirect(to: ~p"/map_configurations/#{map_configuration}") + |> redirect(to: ~p"/versions/#{map_configuration.version_id}/map_configurations/#{map_configuration}") {:error, %Ecto.Changeset{} = changeset} -> - render(conn, :edit, map_configuration: map_configuration, changeset: changeset) + version = Configuration.get_version!(map_configuration.version_id) + render(conn, :edit, map_configuration: map_configuration, changeset: changeset, version: version) end end def delete(conn, %{"id" => id}) do map_configuration = Configuration.get_map_configuration!(id) + version_id = map_configuration.version_id {:ok, _map_configuration} = Configuration.delete_map_configuration(map_configuration) conn |> put_flash(:info, "Map configuration deleted successfully.") - |> redirect(to: ~p"/map_configurations") + |> redirect(to: ~p"/versions/#{version_id}/map_configurations") end def edit_obstacles(conn, %{"id" => id}) do map_configuration = Configuration.get_map_configuration!(id) - changeset = Configuration.change_map_configuration(map_configuration) render(conn, :edit_obstacles, map_configuration: map_configuration, changeset: changeset, - action: ~p"/map_configurations/#{map_configuration}/update_obstacles" + action: ~p"/versions/#{map_configuration.version_id}/map_configurations/#{map_configuration}/update_obstacles" ) end @@ -85,26 +88,25 @@ defmodule ConfiguratorWeb.MapConfigurationController do {:ok, map_configuration} -> conn |> put_flash(:info, "Map configuration updated successfully.") - |> redirect(to: ~p"/map_configurations/#{map_configuration}") + |> redirect(to: ~p"/versions/#{map_configuration.version_id}/map_configurations/#{map_configuration}") {:error, %Ecto.Changeset{} = changeset} -> render(conn, :edit_obstacles, map_configuration: map_configuration, changeset: changeset, - action: ~p"/map_configurations/#{map_configuration}/update_obstacles" + action: ~p"/versions/#{map_configuration.version_id}/map_configurations/#{map_configuration}/update_obstacles" ) end end def edit_pools(conn, %{"id" => id}) do map_configuration = Configuration.get_map_configuration!(id) - changeset = Configuration.change_map_configuration(map_configuration) render(conn, :edit_pools, map_configuration: map_configuration, changeset: changeset, - action: ~p"/map_configurations/#{map_configuration}/update_pools" + action: ~p"/versions/#{map_configuration.version_id}/map_configurations/#{map_configuration}/update_pools" ) end @@ -115,26 +117,25 @@ defmodule ConfiguratorWeb.MapConfigurationController do {:ok, map_configuration} -> conn |> put_flash(:info, "Map configuration updated successfully.") - |> redirect(to: ~p"/map_configurations/#{map_configuration}") + |> redirect(to: ~p"/versions/#{map_configuration.version_id}/map_configurations/#{map_configuration}") {:error, %Ecto.Changeset{} = changeset} -> render(conn, :edit_pools, map_configuration: map_configuration, changeset: changeset, - action: ~p"/map_configurations/#{map_configuration}/update_obstacles" + action: ~p"/versions/#{map_configuration.version_id}/map_configurations/#{map_configuration}/update_obstacles" ) end end def edit_crates(conn, %{"id" => id}) do map_configuration = Configuration.get_map_configuration!(id) - changeset = Configuration.change_map_configuration(map_configuration) render(conn, :edit_crates, map_configuration: map_configuration, changeset: changeset, - action: ~p"/map_configurations/#{map_configuration}/update_crates" + action: ~p"/versions/#{map_configuration.version_id}/map_configurations/#{map_configuration}/update_crates" ) end @@ -145,18 +146,18 @@ defmodule ConfiguratorWeb.MapConfigurationController do {:ok, map_configuration} -> conn |> put_flash(:info, "Map configuration updated successfully.") - |> redirect(to: ~p"/map_configurations/#{map_configuration}") + |> redirect(to: ~p"/versions/#{map_configuration.version_id}/map_configurations/#{map_configuration}") {:error, %Ecto.Changeset{} = changeset} -> render(conn, :edit_crates, map_configuration: map_configuration, changeset: changeset, - action: ~p"/map_configurations/#{map_configuration}/update_obstacles" + action: ~p"/versions/#{map_configuration.version_id}/map_configurations/#{map_configuration}/update_obstacles" ) end end - defp parse_json_params(map_configuration_params) do + def parse_json_params(map_configuration_params) do map_configuration_params |> Map.update("initial_positions", "", &parse_json/1) |> Map.update("obstacles", "", &parse_json/1) 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 99fab600e..96b5076e7 100644 --- a/apps/configurator/lib/configurator_web/controllers/map_configuration_html.ex +++ b/apps/configurator/lib/configurator_web/controllers/map_configuration_html.ex @@ -8,6 +8,7 @@ defmodule ConfiguratorWeb.MapConfigurationHTML do """ attr :changeset, Ecto.Changeset, required: true attr :action, :string, required: true + attr :version, GameBackend.Configuration.Version, required: true def map_configuration_form(assigns) @@ -28,7 +29,7 @@ defmodule ConfiguratorWeb.MapConfigurationHTML do end def embed_to_string(%Ecto.Changeset{} = changeset) do - changeset.params + changeset.params |> Map.delete("id") end def embed_to_string(struct) when is_map(struct) do diff --git a/apps/configurator/lib/configurator_web/controllers/map_configuration_html/edit.html.heex b/apps/configurator/lib/configurator_web/controllers/map_configuration_html/edit.html.heex index f750391af..e989e143e 100644 --- a/apps/configurator/lib/configurator_web/controllers/map_configuration_html/edit.html.heex +++ b/apps/configurator/lib/configurator_web/controllers/map_configuration_html/edit.html.heex @@ -3,23 +3,27 @@ <:subtitle>Use this form to manage Map Configuration records in your database. <:actions> <%= unless Enum.empty?(@map_configuration.obstacles) do %> - <.link href={~p"/map_configurations/#{@map_configuration}/edit_obstacles"}> + <.link href={~p"/versions/#{@version}/map_configurations/#{@map_configuration}/edit_obstacles"}> <.button>Edit Map Obstacles <% end %> <%= unless Enum.empty?(@map_configuration.pools) do %> - <.link href={~p"/map_configurations/#{@map_configuration}/edit_pools"}> + <.link href={~p"/versions/#{@version}/map_configurations/#{@map_configuration}/edit_pools"}> <.button>Edit Map Pools <% end %> <%= unless Enum.empty?(@map_configuration.crates) do %> - <.link href={~p"/map_configurations/#{@map_configuration}/edit_crates"}> + <.link href={~p"/versions/#{@version}/map_configurations/#{@map_configuration}/edit_crates"}> <.button>Edit Map Crates <% end %> -<.map_configuration_form changeset={@changeset} action={~p"/map_configurations/#{@map_configuration}"} /> +<.map_configuration_form + changeset={@changeset} + action={~p"/versions/#{@version}/map_configurations/#{@map_configuration}"} + version={@version} +/> -<.back navigate={~p"/map_configurations"}>Back to Map Configuration +<.back navigate={~p"/versions/#{@version}/map_configurations"}>Back to Map Configuration 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 9b1f79f82..56f3a4a49 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 @@ -1,7 +1,7 @@ <.header> Listing Map configurations <:actions> - <.link href={~p"/map_configurations/new"}> + <.link href={~p"/versions/#{@version_id}/map_configurations/new"}> <.button>New Map configuration @@ -73,13 +73,17 @@ <% end %> <:action :let={map_configuration}> - <.link navigate={~p"/map_configurations/#{map_configuration}"}>View + <.link navigate={~p"/versions/#{@version_id}/map_configurations/#{map_configuration}"}>View <:action :let={map_configuration}> - <.link navigate={~p"/map_configurations/#{map_configuration}/edit"}>Edit + <.link navigate={~p"/versions/#{@version_id}/map_configurations/#{map_configuration}/edit"}>Edit <:action :let={map_configuration}> - <.link href={~p"/map_configurations/#{map_configuration}"} method="delete" data-confirm="Are you sure?"> + <.link + href={~p"/versions/#{@version_id}/map_configurations/#{map_configuration}"} + method="delete" + data-confirm="Are you sure?" + > Delete 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 5fa9b6a8c..b9ae3cd2a 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 @@ -3,16 +3,8 @@ Oops, something went wrong! Please check the errors below. <.input field={f[:active]} type="checkbox" label="Active" /> - <.input - field={f[:version_id]} - type="select" - options={ - Enum.map(GameBackend.Configuration.list_versions(), fn version -> - {version.name, version.id} - end) - } - label="Version" - /> +

<%= "Version: #{@version.name}" %>

+ <.input type="hidden" field={f[:version_id]} value={@version.id} /> <.input field={f[:name]} type="text" label="Name" /> <.input field={f[:radius]} type="number" label="Radius" step="any" /> <.input diff --git a/apps/configurator/lib/configurator_web/controllers/map_configuration_html/new.html.heex b/apps/configurator/lib/configurator_web/controllers/map_configuration_html/new.html.heex index f4cde19b4..a4ef020ed 100644 --- a/apps/configurator/lib/configurator_web/controllers/map_configuration_html/new.html.heex +++ b/apps/configurator/lib/configurator_web/controllers/map_configuration_html/new.html.heex @@ -3,6 +3,6 @@ <:subtitle>Use this form to manage Map Configuration records in your database. -<.map_configuration_form changeset={@changeset} action={~p"/map_configurations"} /> +<.map_configuration_form changeset={@changeset} action={~p"/versions/#{@version}/map_configurations"} /> -<.back navigate={~p"/map_configurations"}>Back to Map Configuration +<.back navigate={~p"/versions/#{@version}/map_configurations"}>Back to Map Configuration 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 1a6121a38..3f8ab1ad4 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 @@ -2,21 +2,21 @@ Map configuration <%= @map_configuration.name %> <:subtitle>Version: <%= @version.name %> <:actions> - <.link href={~p"/map_configurations/#{@map_configuration}/edit"}> + <.link href={~p"/versions/#{@version}/map_configurations/#{@map_configuration}/edit"}> <.button>Edit Map Configuration <%= unless Enum.empty?(@map_configuration.obstacles) do %> - <.link href={~p"/map_configurations/#{@map_configuration}/edit_obstacles"}> + <.link href={~p"/versions/#{@version}/map_configurations/#{@map_configuration}/edit_obstacles"}> <.button>Edit Map Obstacles <% end %> <%= unless Enum.empty?(@map_configuration.pools) do %> - <.link href={~p"/map_configurations/#{@map_configuration}/edit_pools"}> + <.link href={~p"/versions/#{@version}/map_configurations/#{@map_configuration}/edit_pools"}> <.button>Edit Map Pools <% end %> <%= unless Enum.empty?(@map_configuration.crates) do %> - <.link href={~p"/map_configurations/#{@map_configuration}/edit_crates"}> + <.link href={~p"/versions/#{@version}/map_configurations/#{@map_configuration}/edit_crates"}> <.button>Edit Map Crates <% end %> @@ -114,4 +114,4 @@ -<.back navigate={~p"/map_configurations"}>Back to Map Configurations +<.back navigate={~p"/versions/#{@version}/map_configurations"}>Back to Map Configurations diff --git a/apps/configurator/lib/configurator_web/controllers/skill_controller.ex b/apps/configurator/lib/configurator_web/controllers/skill_controller.ex index eb7d21a2b..acce01aab 100644 --- a/apps/configurator/lib/configurator_web/controllers/skill_controller.ex +++ b/apps/configurator/lib/configurator_web/controllers/skill_controller.ex @@ -5,15 +5,17 @@ defmodule ConfiguratorWeb.SkillController do alias GameBackend.Units.Skills.Mechanic alias GameBackend.Units.Skills.Skill alias GameBackend.Utils + alias GameBackend.Configuration - def index(conn, _params) do - skills = Skills.list_curse_skills() - render(conn, :index, skills: skills) + def index(conn, %{"version_id" => version_id}) do + skills = Skills.list_curse_skills_by_version(version_id) + render(conn, :index, skills: skills, version_id: version_id) end - def new(conn, _params) do + def new(conn, %{"version_id" => version_id}) do changeset = Skills.change_skill(%Skill{mechanics: [%Mechanic{}]}) - render(conn, :new, changeset: changeset) + version = Configuration.get_version!(version_id) + render(conn, :new, changeset: changeset, version: version) end def create(conn, %{"skill" => skill_params}) do @@ -23,22 +25,25 @@ defmodule ConfiguratorWeb.SkillController do {:ok, skill} -> conn |> put_flash(:info, "Skill created successfully.") - |> redirect(to: ~p"/skills/#{skill}") + |> redirect(to: ~p"/versions/#{skill.version_id}/skills/#{skill}") {:error, %Ecto.Changeset{} = changeset} -> - render(conn, :new, changeset: changeset) + version = Configuration.get_version!(skill_params["version_id"]) + render(conn, :new, changeset: changeset, version: version) end end def show(conn, %{"id" => id}) do skill = Skills.get_skill!(id) - render(conn, :show, skill: skill) + version = Configuration.get_version!(skill.version_id) + render(conn, :show, skill: skill, version: version) end def edit(conn, %{"id" => id}) do skill = Skills.get_skill!(id) changeset = Skills.change_skill(skill) - render(conn, :edit, skill: skill, changeset: changeset) + version = Configuration.get_version!(skill.version_id) + render(conn, :edit, skill: skill, changeset: changeset, version: version) end def update(conn, %{"id" => id, "skill" => skill_params}) do @@ -51,31 +56,33 @@ defmodule ConfiguratorWeb.SkillController do {:ok, skill} -> conn |> put_flash(:info, "Skill updated successfully.") - |> redirect(to: ~p"/skills/#{skill}") + |> redirect(to: ~p"/versions/#{skill.version_id}/skills/#{skill}") {:error, %Ecto.Changeset{} = changeset} -> - render(conn, :edit, skill: skill, changeset: changeset) + version = Configuration.get_version!(skill.version_id) + render(conn, :edit, skill: skill, changeset: changeset, version: version) end end def delete(conn, %{"id" => id}) do skill = Skills.get_skill!(id) + version_id = skill.version_id case Skills.delete_skill(skill) do {:error, %{errors: [characters: {_, [constraint: :foreign, constraint_name: "characters_basic_skill_id_fkey"]}]}} -> conn |> put_flash(:error, "Skill being used by a Character.") - |> redirect(to: ~p"/skills/#{skill}") + |> redirect(to: ~p"/versions/#{version_id}/skills/#{skill}") {:error, _changeset} -> conn |> put_flash(:info, "Something went wrong.") - |> redirect(to: ~p"/skills/#{skill}") + |> redirect(to: ~p"/versions/#{version_id}/skills/#{skill}") {:ok, _skill} -> conn |> put_flash(:success, "Skill deleted successfully.") - |> redirect(to: ~p"/skills") + |> redirect(to: ~p"/versions/#{version_id}/skills") end end end diff --git a/apps/configurator/lib/configurator_web/controllers/skill_html.ex b/apps/configurator/lib/configurator_web/controllers/skill_html.ex index b998b3603..4df243286 100644 --- a/apps/configurator/lib/configurator_web/controllers/skill_html.ex +++ b/apps/configurator/lib/configurator_web/controllers/skill_html.ex @@ -9,6 +9,7 @@ defmodule ConfiguratorWeb.SkillHTML do """ attr :changeset, Ecto.Changeset, required: true attr :action, :string, required: true + attr :version, GameBackend.Configuration.Version, required: true def skill_form(assigns) diff --git a/apps/configurator/lib/configurator_web/controllers/skill_html/edit.html.heex b/apps/configurator/lib/configurator_web/controllers/skill_html/edit.html.heex index dce7511bf..2777817e3 100644 --- a/apps/configurator/lib/configurator_web/controllers/skill_html/edit.html.heex +++ b/apps/configurator/lib/configurator_web/controllers/skill_html/edit.html.heex @@ -3,6 +3,6 @@ <:subtitle>Use this form to manage skill records in your database. -<.skill_form changeset={@changeset} action={~p"/skills/#{@skill}"} /> +<.skill_form changeset={@changeset} action={~p"/versions/#{@version}/skills/#{@skill}"} version={@version} /> -<.back navigate={~p"/skills"}>Back to skills +<.back navigate={~p"/versions/#{@version}/skills"}>Back to skills diff --git a/apps/configurator/lib/configurator_web/controllers/skill_html/index.html.heex b/apps/configurator/lib/configurator_web/controllers/skill_html/index.html.heex index 8277231e4..ac49d2eed 100644 --- a/apps/configurator/lib/configurator_web/controllers/skill_html/index.html.heex +++ b/apps/configurator/lib/configurator_web/controllers/skill_html/index.html.heex @@ -1,13 +1,13 @@ <.header> Listing Config skills <:actions> - <.link href={~p"/skills/new"}> + <.link href={~p"/versions/#{@version_id}/skills/new"}> <.button>New Skill -<.table id="skills" rows={@skills} row_click={&JS.navigate(~p"/skills/#{&1}")}> +<.table id="skills" rows={@skills} row_click={&JS.navigate(~p"/versions/#{@version_id}/skills/#{&1}")}> <:col :let={skill} label="Name"><%= skill.name %> <:col :let={skill} label="Activation delay (ms)"><%= skill.activation_delay_ms %> <:col :let={skill} label="Autoaim"><%= skill.autoaim %> @@ -55,12 +55,12 @@ <:action :let={skill}>
- <.link navigate={~p"/skills/#{skill}"}>Show + <.link navigate={~p"/versions/#{@version_id}/skills/#{skill}"}>Show
- <.link navigate={~p"/skills/#{skill}/edit"}>Edit + <.link navigate={~p"/versions/#{@version_id}/skills/#{skill}/edit"}>Edit <:action :let={skill}> - <.link href={~p"/skills/#{skill}"} method="delete" data-confirm="Are you sure?"> + <.link href={~p"/versions/#{@version_id}/skills/#{skill}"} method="delete" data-confirm="Are you sure?"> Delete diff --git a/apps/configurator/lib/configurator_web/controllers/skill_html/new.html.heex b/apps/configurator/lib/configurator_web/controllers/skill_html/new.html.heex index 5dd46d2f8..658c14ef8 100644 --- a/apps/configurator/lib/configurator_web/controllers/skill_html/new.html.heex +++ b/apps/configurator/lib/configurator_web/controllers/skill_html/new.html.heex @@ -3,6 +3,6 @@ <:subtitle>Use this form to manage skill records in your database. -<.skill_form changeset={@changeset} action={~p"/skills"} /> +<.skill_form changeset={@changeset} action={~p"/versions/#{@version}/skills"} version={@version} /> -<.back navigate={~p"/skills"}>Back to skills +<.back navigate={~p"/versions/#{@version}/skills"}>Back to skills diff --git a/apps/configurator/lib/configurator_web/controllers/skill_html/show.html.heex b/apps/configurator/lib/configurator_web/controllers/skill_html/show.html.heex index b67dfacb6..308b1ade7 100644 --- a/apps/configurator/lib/configurator_web/controllers/skill_html/show.html.heex +++ b/apps/configurator/lib/configurator_web/controllers/skill_html/show.html.heex @@ -9,7 +9,7 @@ <% end %> <:actions> - <.link href={~p"/skills/#{@skill}/edit"}> + <.link href={~p"/versions/#{@version}/skills/#{@skill}/edit"}> <.button>Edit skill <.effect_show effect={@skill.effect_to_apply} /> @@ -60,4 +60,4 @@ <% end %> -<.back navigate={~p"/skills"}>Back to skills +<.back navigate={~p"/versions/#{@version}/skills"}>Back to skills diff --git a/apps/configurator/lib/configurator_web/controllers/skill_html/skill_form.html.heex b/apps/configurator/lib/configurator_web/controllers/skill_html/skill_form.html.heex index 9b4c1f498..61573fba6 100644 --- a/apps/configurator/lib/configurator_web/controllers/skill_html/skill_form.html.heex +++ b/apps/configurator/lib/configurator_web/controllers/skill_html/skill_form.html.heex @@ -2,12 +2,8 @@ <.error :if={@changeset.action}> Oops, something went wrong! Please check the errors below. - <.input - field={f[:version_id]} - type="select" - options={Enum.map(GameBackend.Configuration.list_versions(), fn version -> {version.name, version.id} end)} - label="Version" - /> +

<%= "Version: #{@version.name}" %>

+ <.input type="hidden" field={f[:version_id]} value={@version.id} /> <.input field={f[:name]} type="text" label="Name" required /> <.input field={f[:type]} diff --git a/apps/configurator/lib/configurator_web/controllers/skill_html/skill_mechanic_inputs.html.heex b/apps/configurator/lib/configurator_web/controllers/skill_html/skill_mechanic_inputs.html.heex index 373609007..bb4c8b57b 100644 --- a/apps/configurator/lib/configurator_web/controllers/skill_html/skill_mechanic_inputs.html.heex +++ b/apps/configurator/lib/configurator_web/controllers/skill_html/skill_mechanic_inputs.html.heex @@ -30,7 +30,10 @@ <% end %> <.input field={fp[:shape]} type="select" label="Shape of entity to spawn" options={["circle", "polygon"]} /> - <.input field={fp[:vertices]} type="text" label="Vertices" value={Jason.encode!(fp.data.vertices)} /> + <%!-- TODO: Fix this because it breaks if its null --%> + <%!-- https://github.com/lambdaclass/mirra_backend/issues/1028 --%> + <.input field={fp[:vertices]} type="text" label="Vertices" value={[]} /> + <%!-- END TODO --%> <.button type="button" phx-click={show_modal("on-arrival-mechanic-modal")}>Edit on arrival mechanic <.modal id="on-arrival-mechanic-modal"> diff --git a/apps/configurator/lib/configurator_web/controllers/version_controller.ex b/apps/configurator/lib/configurator_web/controllers/version_controller.ex index 3c2ae207a..7d187e8e2 100644 --- a/apps/configurator/lib/configurator_web/controllers/version_controller.ex +++ b/apps/configurator/lib/configurator_web/controllers/version_controller.ex @@ -1,8 +1,10 @@ defmodule ConfiguratorWeb.VersionController do use ConfiguratorWeb, :controller + alias ConfiguratorWeb.MapConfigurationController alias GameBackend.Configuration alias GameBackend.Configuration.Version + alias GameBackend.Utils def index(conn, _params) do versions = Configuration.list_versions() @@ -10,11 +12,64 @@ defmodule ConfiguratorWeb.VersionController do end def new(conn, _params) do - changeset = Configuration.change_version(%Version{}) - render(conn, :new, changeset: changeset) + last_version = GameBackend.Configuration.get_current_version() + skills = Utils.list_curse_skills_by_version_grouped_by_type(last_version.id) + + params = + Map.from_struct(last_version) + |> Map.put(:characters, schema_to_map(last_version.characters)) + |> Map.put(:consumable_items, schema_to_map(last_version.consumable_items)) + |> Map.put(:game_configuration, schema_to_map(last_version.game_configuration)) + |> Map.put(:map_configurations, schema_to_map(last_version.map_configurations)) + |> Map.put(:skills, schema_to_map(last_version.skills)) + + changeset = Configuration.change_version(%Version{}, params) + render(conn, :new, changeset: changeset, last_version: last_version, skills: skills) + end + + # TODO: We have a cycle in our Skill.Mechanic assocs so this is to end that loop. + # This replaces the unloaded mechanics assoc by an empty list. + # The key is that we preload the necessary steps of the mechanics loop associations. + # https://github.com/lambdaclass/mirra_backend/issues/1028 + def schema_to_map(%{ + __cardinality__: :many, + __field__: _, + __owner__: _ + }) do + [] + end + + def schema_to_map(%Decimal{} = decimal), do: decimal + + def schema_to_map(%_struct{} = schema) do + schema + |> Map.from_struct() + |> Enum.map(fn {key, value} -> {key, schema_to_map(value)} end) + |> Enum.into(%{}) + end + + def schema_to_map(map) when is_map(map) do + map + |> Enum.map(fn {key, value} -> {key, schema_to_map(value)} end) + |> Enum.into(%{}) end + def schema_to_map(list) when is_list(list) do + Enum.map(list, &schema_to_map/1) + end + + def schema_to_map(value), do: value + def create(conn, %{"version" => version_params}) do + version_params = + Map.put( + version_params, + "map_configurations", + Map.new(version_params["map_configurations"], fn {key, map_params} -> + {key, MapConfigurationController.parse_json_params(map_params)} + end) + ) + case Configuration.create_version(version_params) do {:ok, version} -> conn @@ -22,7 +77,10 @@ defmodule ConfiguratorWeb.VersionController do |> redirect(to: ~p"/versions/#{version}") {:error, %Ecto.Changeset{} = changeset} -> - render(conn, :new, changeset: changeset) + last_version = GameBackend.Configuration.get_current_version() + skills = Utils.list_curse_skills_by_version_grouped_by_type(last_version.id) + + render(conn, :new, changeset: changeset, last_version: last_version, skills: skills) end end @@ -31,6 +89,11 @@ defmodule ConfiguratorWeb.VersionController do render(conn, :show, version: version) end + def show_current_version(conn, _params) do + version = GameBackend.Configuration.get_current_version() + render(conn, :show, version: version) + end + def edit(conn, %{"id" => id}) do version = Configuration.get_version!(id) changeset = Configuration.change_version(version) diff --git a/apps/configurator/lib/configurator_web/controllers/version_html.ex b/apps/configurator/lib/configurator_web/controllers/version_html.ex index ea45fc38a..5c07be18d 100644 --- a/apps/configurator/lib/configurator_web/controllers/version_html.ex +++ b/apps/configurator/lib/configurator_web/controllers/version_html.ex @@ -1,5 +1,8 @@ defmodule ConfiguratorWeb.VersionHTML do use ConfiguratorWeb, :html + import ConfiguratorWeb.SkillHTML + import ConfiguratorWeb.MapConfigurationHTML + import ConfiguratorWeb.CharacterHTML embed_templates "version_html/*" @@ -8,6 +11,8 @@ defmodule ConfiguratorWeb.VersionHTML do """ attr :changeset, Ecto.Changeset, required: true attr :action, :string, required: true + attr :last_version, GameBackend.Configuration.Version + attr :skills, :list def version_form(assigns) end diff --git a/apps/configurator/lib/configurator_web/controllers/version_html/edit.html.heex b/apps/configurator/lib/configurator_web/controllers/version_html/edit.html.heex index cce2cd1f1..ae0ea25d6 100644 --- a/apps/configurator/lib/configurator_web/controllers/version_html/edit.html.heex +++ b/apps/configurator/lib/configurator_web/controllers/version_html/edit.html.heex @@ -3,6 +3,12 @@ <:subtitle>Use this form to manage version records in your database. -<.version_form changeset={@changeset} action={~p"/versions/#{@version}"} /> +<.list> + <:item title="Character settings"><.link href={~p"/versions/#{@version}/characters"}>Link + <:item title="Game settings"><.link href={~p"/versions/#{@version}/game_configurations"}>Link + <:item title="Map settings"><.link href={~p"/versions/#{@version}/map_configurations"}>Link + <:item title="Skill settings"><.link href={~p"/versions/#{@version}/skills"}>Link + <:item title="Consumable Items"><.link href={~p"/versions/#{@version}/consumable_items"}>Link + <.back navigate={~p"/versions"}>Back to versions diff --git a/apps/configurator/lib/configurator_web/controllers/version_html/index.html.heex b/apps/configurator/lib/configurator_web/controllers/version_html/index.html.heex index 70fd58061..e9311ffc7 100644 --- a/apps/configurator/lib/configurator_web/controllers/version_html/index.html.heex +++ b/apps/configurator/lib/configurator_web/controllers/version_html/index.html.heex @@ -22,7 +22,7 @@ <:action :let={version}> <%= if version.current do %> - Current version + Current version <% else %> <.link href={~p"/versions/#{version}/current"} method="put" data-confirm="Are you sure?"> Mark as current diff --git a/apps/configurator/lib/configurator_web/controllers/version_html/new.html.heex b/apps/configurator/lib/configurator_web/controllers/version_html/new.html.heex index 9073c5cae..40ff4c47b 100644 --- a/apps/configurator/lib/configurator_web/controllers/version_html/new.html.heex +++ b/apps/configurator/lib/configurator_web/controllers/version_html/new.html.heex @@ -3,6 +3,6 @@ <:subtitle>Use this form to manage version records in your database. -<.version_form changeset={@changeset} action={~p"/versions"} /> +<.version_form changeset={@changeset} last_version={@last_version} action={~p"/versions"} skills={@skills} /> <.back navigate={~p"/versions"}>Back to versions diff --git a/apps/configurator/lib/configurator_web/controllers/version_html/show.html.heex b/apps/configurator/lib/configurator_web/controllers/version_html/show.html.heex index eabac1495..6604c937a 100644 --- a/apps/configurator/lib/configurator_web/controllers/version_html/show.html.heex +++ b/apps/configurator/lib/configurator_web/controllers/version_html/show.html.heex @@ -8,8 +8,22 @@ +<%= if @version.current do %> +

+ This is the current version +

+<% end %> + <.list> <:item title="Name"><%= @version.name %> +<.list> + <:item title="Character settings"><.link href={~p"/versions/#{@version}/characters"}>Link + <:item title="Game settings"><.link href={~p"/versions/#{@version}/game_configurations"}>Link + <:item title="Map settings"><.link href={~p"/versions/#{@version}/map_configurations"}>Link + <:item title="Skill settings"><.link href={~p"/versions/#{@version}/skills"}>Link + <:item title="Consumable Items"><.link href={~p"/versions/#{@version}/consumable_items"}>Link + + <.back navigate={~p"/versions"}>Back to versions diff --git a/apps/configurator/lib/configurator_web/controllers/version_html/version_form.html.heex b/apps/configurator/lib/configurator_web/controllers/version_html/version_form.html.heex index af62124c9..b60ee0156 100644 --- a/apps/configurator/lib/configurator_web/controllers/version_html/version_form.html.heex +++ b/apps/configurator/lib/configurator_web/controllers/version_html/version_form.html.heex @@ -1,9 +1,197 @@ -<.simple_form :let={f} for={@changeset} action={@action}> +<.flex_form :let={f} for={@changeset} action={@action}> <.error :if={@changeset.action}> Oops, something went wrong! Please check the errors below. - <.input field={f[:name]} type="text" label="Name" /> + <.input field={f[:name]} type="text" label="Version Name" /> +
+ Characters +
+ <.inputs_for :let={fc} field={f[:characters]}> +
+ <.input field={fc[:name]} type="text" label="Character Name" class="input-item" /> + <.input field={fc[:base_speed]} type="number" label="Base speed" step="any" /> + <.input field={fc[:base_size]} type="number" label="Base size" step="any" lang="en" /> + <.input field={fc[:base_health]} type="number" label="Base health" /> + <.input field={fc[:base_stamina]} type="number" label="Base stamina" /> + <.input field={fc[:stamina_interval]} type="number" label="Stamina Interval" /> + <.input field={fc[:base_mana]} type="number" label="Base mana" /> + <.input field={fc[:initial_mana]} type="number" label="Initial mana when spawning" /> + <.input + field={fc[:mana_recovery_strategy]} + type="select" + label="Mana recovery strategy" + prompt="Select strategy" + options={Ecto.Enum.values(GameBackend.Units.Characters.Character, :mana_recovery_strategy)} + /> + <.input field={fc[:mana_recovery_time_interval_ms]} type="number" label="Time based mana recovery interval" /> + <.input field={fc[:mana_recovery_time_amount]} type="number" label="Time based mana recovery amount" /> + <.input + field={fc[:mana_recovery_damage_multiplier]} + type="number" + label="Damage based mana recovery multiplier amount" + step="any" + /> + <.input field={fc[:max_inventory_size]} type="number" label="Max inventory size" step="any" /> + <.input field={fc[:natural_healing_interval]} type="number" label="Natural healing interval" /> + <.input field={fc[:natural_healing_damage_interval]} type="number" label="Natural healing damage interval" /> + <.skill_select field={fc[:basic_skill_id]} label="Basic skill" skills={@skills[:basic]} /> + <.skill_select field={fc[:dash_skill_id]} label="Dash skill" skills={@skills[:dash]} /> + <.skill_select field={fc[:ultimate_skill_id]} label="Ultimate skill" skills={@skills[:ultimate]} /> + <.input field={fc[:active]} type="checkbox" label="Active" /> + <.input type="hidden" field={fc[:game_id]} /> + <.input type="hidden" field={fc[:faction]} /> +
+ +
+
+
+ Consumable Items +
+ <.inputs_for :let={fci} field={f[:consumable_items]}> +
+ <.input field={fci[:name]} type="text" label="Name" /> + <.input field={fci[:radius]} type="number" label="Radius" step="any" /> + <.input field={fci[:active]} type="checkbox" label="Active" /> + <.effect_form form={fci} field={:effect} /> +
+ +
+
+ +
+ Skills +
+ <.inputs_for :let={fs} field={f[:skills]}> +
+ <.input field={fs[:name]} type="text" label="Name" required /> + <.input + field={fs[:type]} + type="select" + label="Type" + prompt="Choose a value" + options={Ecto.Enum.values(GameBackend.Units.Skills.Skill, :type)} + /> + <.input field={fs[:activation_delay_ms]} type="number" label="Activation delay (ms)" /> + <.input field={fs[:autoaim]} type="checkbox" label="Autoaim" /> + <.input field={fs[:block_movement]} type="checkbox" label="Block movement" /> + <.input field={fs[:can_pick_destination]} type="checkbox" label="Can pick destination" /> + <.input + field={fs[:cooldown_mechanism]} + type="select" + label="Cooldown mechanism" + prompt="Choose a value" + options={Ecto.Enum.values(GameBackend.Units.Skills.Skill, :cooldown_mechanism)} + /> + <.input field={fs[:cooldown_ms]} type="number" label="Cooldown (ms)" /> + <.input field={fs[:execution_duration_ms]} type="number" label="Execution duration (ms)" /> + <.input field={fs[:inmune_while_executing]} type="checkbox" label="Inmune while executing" /> + <.input field={fs[:is_passive]} type="checkbox" label="Is passive" /> + <.input field={fs[:max_autoaim_range]} type="number" label="Max autoaim range" /> + <.input field={fs[:stamina_cost]} type="number" label="Stamina cost" /> + <.input field={fs[:mana_cost]} type="number" label="Mana cost" /> + <.input type="hidden" field={fs[:game_id]} /> + + <.skill_mechanic_inputs skill_form={fs} /> + <%= if fs.data.effect_to_apply do %> + <.effect_form form={fs} field={:effect_to_apply} /> + <% end %> +
+ +
+
+ +
+ Game Configuration +
+ <.inputs_for :let={fg} field={f[:game_configuration]}> +
+ <.input field={fg[:tick_rate_ms]} type="number" label="Tick rate ms" /> + <.input field={fg[:bounty_pick_time_ms]} type="number" label="Bounty pick time ms" /> + <.input field={fg[:start_game_time_ms]} type="number" label="Start game time ms" /> + <.input field={fg[:end_game_interval_ms]} type="number" label="End game interval ms" /> + <.input field={fg[:shutdown_game_wait_ms]} type="number" label="Shutdown game wait ms" /> + <.input field={fg[:natural_healing_interval_ms]} type="number" label="Natural healing interval ms" /> + <.input field={fg[:zone_shrink_start_ms]} type="number" label="Zone shrink start ms" /> + <.input field={fg[:zone_shrink_radius_by]} type="number" label="Zone shrink radius by" /> + <.input field={fg[:zone_shrink_interval]} type="number" label="Zone shrink interval" /> + <.input field={fg[:zone_stop_interval_ms]} type="number" label="Zone stop interval ms" /> + <.input field={fg[:zone_start_interval_ms]} type="number" label="Zone start interval ms" /> + <.input field={fg[:zone_damage_interval_ms]} type="number" label="Zone damage interval ms" /> + <.input field={fg[:zone_damage]} type="number" label="Zone damage" /> + <.input field={fg[:item_spawn_interval_ms]} type="number" label="Item spawn interval ms" /> + <.input field={fg[:bounties_options_amount]} type="number" label="Bounties options amount" /> + <.input field={fg[:match_timeout_ms]} type="number" label="Match Timeout ms" /> + <.input field={fg[:bots_enabled]} type="checkbox" label="Bots enabled" /> + <.input field={fg[:zone_enabled]} type="checkbox" label="Zone enabled" /> + <.input field={fg[:field_of_view_inside_bush]} type="number" label="Field of view inside bush" /> + <.input field={fg[:time_visible_in_bush_after_skill]} type="number" label="Field of view inside bush" /> + +

Power Ups

+ <.input field={fg[:distance_to_power_up]} type="number" label="Power Up spawn range" step="any" /> + <.input field={fg[:power_up_damage_modifier]} type="number" label="Power Up damage modifier" step="any" /> + <.input field={fg[:power_up_health_modifier]} type="number" label="Power Up health modifier" step="any" /> + <.input field={fg[:power_up_radius]} type="number" label="Power Up radius" step="any" /> + <.input field={fg[:power_up_activation_delay_ms]} type="number" label="Power Up activation delay" step="any" /> + <.inputs_for :let={power_ups_per_kill_f} field={fg[:power_ups_per_kill]}> +
+
+ <.input + field={power_ups_per_kill_f[:minimum_amount_of_power_ups]} + type="number" + label="Minimum amount of power ups" + step="any" + /> +
+
+ <.input + field={power_ups_per_kill_f[:amount_of_power_ups_to_drop]} + type="number" + label="Amount of power ups to drop" + step="any" + /> +
+
+ +
+ +
+
+ +
+ Map Configurations +
+ <.inputs_for :let={fm} field={f[:map_configurations]}> +
+ <.input field={fm[:active]} type="checkbox" label="Active" /> + <.input field={fm[:name]} type="text" label="Name" /> + <.input field={fm[:radius]} type="number" label="Radius" step="any" /> + <.input + field={fm[:initial_positions]} + type="textarea" + label="Initial positions" + value={embed_to_string(fm[:initial_positions].value)} + /> + <.input + field={fm[:square_wall]} + type="textarea" + label="Square Wall" + value={embed_to_string(fm[:square_wall].value) |> Jason.encode!() |> Jason.Formatter.pretty_print()} + /> + <.input + field={fm[:obstacles]} + type="textarea" + label="Obstacles" + value={embed_to_string(fm[:obstacles].value)} + /> + <.input field={fm[:bushes]} type="textarea" label="Bushes" value={embed_to_string(fm[:bushes].value)} /> + <.input field={fm[:pools]} type="textarea" label="Pools" value={embed_to_string(fm[:pools].value)} /> + <.input field={fm[:crates]} type="textarea" label="Crates" value={embed_to_string(fm[:crates].value)} /> +
+ +
+
+ <:actions> <.button>Save Version - + diff --git a/apps/configurator/lib/configurator_web/live/consumable_items/form.ex b/apps/configurator/lib/configurator_web/live/consumable_items/form.ex index 2a5b2449a..c2670f2da 100644 --- a/apps/configurator/lib/configurator_web/live/consumable_items/form.ex +++ b/apps/configurator/lib/configurator_web/live/consumable_items/form.ex @@ -3,27 +3,28 @@ defmodule ConfiguratorWeb.ConsumableItemsLive.Form do alias GameBackend.Items alias GameBackend.Items.ConsumableItem + alias GameBackend.Configuration def mount( _params, - %{"consumable_item" => consumable_item}, + %{"consumable_item" => consumable_item, "version" => version}, socket ) do changeset = Items.change_consumable_item(consumable_item) socket = - socket |> assign(:changeset, changeset) |> assign(:action, "update") |> assign(:consumable_item, consumable_item) + assign(socket, changeset: changeset, action: "update", consumable_item: consumable_item, version: version) {:ok, socket} end def mount( _params, - _session, + %{"version" => version}, socket ) do changeset = Items.change_consumable_item(%ConsumableItem{}) - socket = socket |> assign(:changeset, changeset) |> assign(:action, "save") + socket = assign(socket, changeset: changeset, action: "save", version: version, consumable_item: %{}) {:ok, socket} end @@ -40,12 +41,14 @@ defmodule ConfiguratorWeb.ConsumableItemsLive.Form do {:ok, consumable_item} -> socket |> put_flash(:info, "Consumable item created successfully.") - |> redirect(to: ~p"/consumable_items/#{consumable_item.id}") + |> redirect(to: ~p"/versions/#{consumable_item.version_id}/consumable_items/#{consumable_item.id}") {:error, %Ecto.Changeset{} = changeset} -> + version = Configuration.get_version!(consumable_item_params["version_id"]) + socket |> put_flash(:error, "Please correct the errors below.") - |> assign(:changeset, changeset) + |> assign(changeset: changeset, version: version) end {:noreply, socket} @@ -59,12 +62,14 @@ defmodule ConfiguratorWeb.ConsumableItemsLive.Form do {:ok, consumable_item} -> socket |> put_flash(:info, "Consumable item updated successfully.") - |> redirect(to: ~p"/consumable_items/#{consumable_item.id}") + |> redirect(to: ~p"/versions/#{consumable_item.version_id}/consumable_items/#{consumable_item.id}") {:error, %Ecto.Changeset{} = changeset} -> + version = Configuration.get_version!(consumable_item.version_id) + socket |> put_flash(:error, "Please correct the errors below.") - |> assign(:changeset, changeset) + |> assign(changeset: changeset, version: version) end {:noreply, socket} diff --git a/apps/configurator/lib/configurator_web/live/consumable_items/form.html.heex b/apps/configurator/lib/configurator_web/live/consumable_items/form.html.heex index 481476238..a6dc6c0f4 100644 --- a/apps/configurator/lib/configurator_web/live/consumable_items/form.html.heex +++ b/apps/configurator/lib/configurator_web/live/consumable_items/form.html.heex @@ -3,26 +3,24 @@ Oops, something went wrong! Please check the errors below. - <.input - field={f[:version_id]} - type="select" - options={Enum.map(GameBackend.Configuration.list_versions(), fn version -> {version.name, version.id} end)} - label="Version" - /> +

<%= "Version: #{@version.name}" %>

+ <.input type="hidden" field={f[:version_id]} value={@version.id} /> <.input field={f[:name]} type="text" label="Name" /> <.input field={f[:radius]} type="number" label="Radius" step="any" /> <.input field={f[:active]} type="checkbox" label="Active" /> - <%= if @consumable_item.effect do %> - <.effect_form form={f} field={:effect} /> - <% end %> + <.effect_form form={f} field={:effect} /> + <:actions> <.button>Save Consumable item
- <.link href="/consumable_items" class="text-sm font-semibold leading-6 text-zinc-900 hover:text-zinc-700"> + <.link + href={"/versions/#{@version.id}/consumable_items"} + class="text-sm font-semibold leading-6 text-zinc-900 hover:text-zinc-700" + > <.icon name="hero-arrow-left-solid" class="h-3 w-3" /> Back to consumable_items
diff --git a/apps/configurator/lib/configurator_web/router.ex b/apps/configurator/lib/configurator_web/router.ex index 1fc815eb7..923b3d8a4 100644 --- a/apps/configurator/lib/configurator_web/router.ex +++ b/apps/configurator/lib/configurator_web/router.ex @@ -53,23 +53,26 @@ defmodule ConfiguratorWeb.Router do scope "/", ConfiguratorWeb do pipe_through [:browser, :require_authenticated_user] - - resources "/characters", CharacterController - resources "/skills", SkillController - resources "/game_configurations", GameConfigurationController - resources "/map_configurations", MapConfigurationController - get "/map_configurations/:id/edit_obstacles", MapConfigurationController, :edit_obstacles - put "/map_configurations/:id/update_obstacles", MapConfigurationController, :update_obstacles - get "/map_configurations/:id/edit_pools", MapConfigurationController, :edit_pools - put "/map_configurations/:id/update_pools", MapConfigurationController, :update_pools - get "/map_configurations/:id/edit_crates", MapConfigurationController, :edit_crates - put "/map_configurations/:id/update_crates", MapConfigurationController, :update_crates - resources "/consumable_items", ConsumableItemController resources "/arena_servers", ArenaServerController scope "/versions" do + get "/show_current_version", VersionController, :show_current_version resources "/", VersionController put "/:id/current", VersionController, :mark_as_current + + scope "/:version_id" do + resources "/characters", CharacterController + resources "/skills", SkillController + resources "/game_configurations", GameConfigurationController + resources "/map_configurations", MapConfigurationController + get "/map_configurations/:id/edit_obstacles", MapConfigurationController, :edit_obstacles + put "/map_configurations/:id/update_obstacles", MapConfigurationController, :update_obstacles + get "/map_configurations/:id/edit_pools", MapConfigurationController, :edit_pools + put "/map_configurations/:id/update_pools", MapConfigurationController, :update_pools + get "/map_configurations/:id/edit_crates", MapConfigurationController, :edit_crates + put "/map_configurations/:id/update_crates", MapConfigurationController, :update_crates + resources "/consumable_items", ConsumableItemController + end end end diff --git a/apps/game_backend/lib/game_backend/configuration.ex b/apps/game_backend/lib/game_backend/configuration.ex index 8ad3a0c6b..22b4d1ae4 100644 --- a/apps/game_backend/lib/game_backend/configuration.ex +++ b/apps/game_backend/lib/game_backend/configuration.ex @@ -5,7 +5,6 @@ defmodule GameBackend.Configuration do import Ecto.Query alias Ecto.Multi alias GameBackend.CurseOfMirra.GameConfiguration - alias GameBackend.Items.ConsumableItem alias GameBackend.Units.Characters.Character alias GameBackend.CurseOfMirra.MapConfiguration alias GameBackend.ArenaServers.ArenaServer @@ -21,8 +20,8 @@ defmodule GameBackend.Configuration do [%GameConfiguration{}, ...] """ - def list_game_configurations do - Repo.all(GameConfiguration) + def list_game_configurations_by_version(version_id) do + Repo.all(from(gc in GameConfiguration, where: gc.version_id == ^version_id)) end @doc """ @@ -115,8 +114,8 @@ defmodule GameBackend.Configuration do [%MapConfiguration{}, ...] """ - def list_map_configurations do - Repo.all(from(m in MapConfiguration, order_by: [desc: m.inserted_at])) + def list_map_configurations_by_version(version_id) do + Repo.all(from(m in MapConfiguration, where: m.version_id == ^version_id, order_by: [desc: m.inserted_at])) end @doc """ @@ -418,7 +417,6 @@ defmodule GameBackend.Configuration do def get_current_version do consumable_items_preload = from(ci in GameBackend.Items.ConsumableItem, - where: ci.active, preload: [ mechanics: [:on_arrival_mechanic, :on_explode_mechanics, :parent_mechanic] ] @@ -429,7 +427,7 @@ defmodule GameBackend.Configuration do where: v.current, preload: [ [consumable_items: ^consumable_items_preload], - :skills, + [skills: [mechanics: [:on_arrival_mechanic, :on_explode_mechanics]]], :map_configurations, :game_configuration, characters: [ @@ -466,42 +464,6 @@ defmodule GameBackend.Configuration do Repo.all(q) end - @doc """ - Get game configuration by version - - ## Examples - iex> get_game_configuration_by_version(version) - %GameConfiguration{} - """ - def get_game_configuration_by_version(version) do - q = - from(g in GameConfiguration, - where: g.version_id == ^version.id - ) - - Repo.one(q) - end - - @doc """ - List all consumable items by version - - ## Examples - iex> list_consumable_items_by_version(version) - [%ConsumableItem{}, ...] - """ - def list_consumable_items_by_version(version) do - q = from(ci in ConsumableItem, where: ci.version_id == ^version.id and ci.active) - Repo.all(q) - end - - @doc """ - - """ - def list_map_configurations_by_version(version) do - q = from(m in MapConfiguration, where: m.version_id == ^version.id) - Repo.all(q) - end - @doc """ Marks a version as current and the former one as not current diff --git a/apps/game_backend/lib/game_backend/configuration/version.ex b/apps/game_backend/lib/game_backend/configuration/version.ex index 5a69d6252..4d95c96ec 100644 --- a/apps/game_backend/lib/game_backend/configuration/version.ex +++ b/apps/game_backend/lib/game_backend/configuration/version.ex @@ -28,6 +28,11 @@ defmodule GameBackend.Configuration.Version do def changeset(version, attrs) do version |> cast(attrs, [:name, :current]) - |> validate_required([:name]) + |> cast_assoc(:characters) + |> cast_assoc(:consumable_items) + |> cast_assoc(:skills, with: &Skill.assoc_changeset/2) + |> cast_assoc(:map_configurations, with: &MapConfiguration.assoc_changeset/2) + |> cast_assoc(:game_configuration, with: &GameConfiguration.assoc_changeset/2) + |> validate_required([:name, :current]) end end diff --git a/apps/game_backend/lib/game_backend/curse_of_mirra/game_configuration.ex b/apps/game_backend/lib/game_backend/curse_of_mirra/game_configuration.ex index c3566154c..114c900be 100644 --- a/apps/game_backend/lib/game_backend/curse_of_mirra/game_configuration.ex +++ b/apps/game_backend/lib/game_backend/curse_of_mirra/game_configuration.ex @@ -79,6 +79,14 @@ defmodule GameBackend.CurseOfMirra.GameConfiguration do |> cast_embed(:power_ups_per_kill) end + @doc false + def assoc_changeset(game_configuration, attrs) do + game_configuration + |> cast(attrs, @required) + |> validate_required(@required -- [:version_id]) + |> cast_embed(:power_ups_per_kill) + end + defmodule PowerUpPerKillAmount do @moduledoc """ Position embedded schema to be used by MapConfiguration 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 b8546528a..78a2eff81 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 @@ -40,6 +40,20 @@ defmodule GameBackend.CurseOfMirra.MapConfiguration do |> unique_constraint(:name) end + @doc false + def assoc_changeset(map_configuration, attrs) do + map_configuration + |> cast(attrs, [:radius, :name, :active]) + |> validate_required([:radius, :active]) + |> cast_embed(:initial_positions) + |> cast_embed(:obstacles) + |> cast_embed(:bushes) + |> cast_embed(:pools) + |> cast_embed(:crates) + |> cast_embed(:square_wall) + |> unique_constraint(:name) + end + defmodule SquareWall do @moduledoc """ SquareWall embedded schema to be used by MapConfiguration diff --git a/apps/game_backend/lib/game_backend/items.ex b/apps/game_backend/lib/game_backend/items.ex index 3324fc6cc..5f8299925 100644 --- a/apps/game_backend/lib/game_backend/items.ex +++ b/apps/game_backend/lib/game_backend/items.ex @@ -285,8 +285,8 @@ defmodule GameBackend.Items do [%ConsumableItem{}, ...] """ - def list_consumable_items do - Repo.all(ConsumableItem) + def list_consumable_items_by_version(version_id) do + Repo.all(from(ci in ConsumableItem, where: ci.version_id == ^version_id)) end @doc """ diff --git a/apps/game_backend/lib/game_backend/units/characters.ex b/apps/game_backend/lib/game_backend/units/characters.ex index 36172756e..0fe1ac237 100644 --- a/apps/game_backend/lib/game_backend/units/characters.ex +++ b/apps/game_backend/lib/game_backend/units/characters.ex @@ -4,6 +4,7 @@ defmodule GameBackend.Units.Characters do """ import Ecto.Query + alias GameBackend.Configuration.Version alias Ecto.Multi alias GameBackend.Repo alias GameBackend.Units.Characters.Character @@ -55,7 +56,7 @@ defmodule GameBackend.Units.Characters do on_conflict: [ set: Enum.into(attrs, []) ], - conflict_target: [:name, :game_id] + conflict_target: [:name, :game_id, :version_id] ) end) |> Repo.transaction() @@ -124,8 +125,20 @@ defmodule GameBackend.Units.Characters do iex> get_character(wrong_character_name, game_id) nil """ - def get_character_id_by_name_and_game_id(name, game_id), - do: Repo.one(from(c in Character, where: c.name == ^name and c.game_id == ^game_id, select: c.id)) + def get_character_id_by_name_and_game_id(name, game_id) do + if game_id == GameBackend.Utils.get_game_id(:champions_of_mirra) do + Repo.one(from(c in Character, where: c.name == ^name and c.game_id == ^game_id, select: c.id)) + else + current_version_id = Repo.one(from(v in Version, where: v.current, select: v.id)) + + Repo.one( + from(c in Character, + where: c.name == ^name and c.game_id == ^game_id and c.version_id == ^current_version_id, + select: c.id + ) + ) + end + end @doc """ Delete all Characters from the database. @@ -171,12 +184,12 @@ defmodule GameBackend.Units.Characters do iex> get_curse_characters() [%Character%{game_id: 1, name: "Muflus"}, ...] """ - def get_curse_characters() do + def get_curse_characters_by_version(version_id) do curse_id = GameBackend.Utils.get_game_id(:curse_of_mirra) q = from(c in Character, - where: ^curse_id == c.game_id, + where: ^curse_id == c.game_id and ^version_id == c.version_id, preload: [ basic_skill: [mechanics: [:on_arrival_mechanic, :on_explode_mechanics, :parent_mechanic]], ultimate_skill: [mechanics: [:on_arrival_mechanic, :on_explode_mechanics, :parent_mechanic]], diff --git a/apps/game_backend/lib/game_backend/units/characters/character.ex b/apps/game_backend/lib/game_backend/units/characters/character.ex index 47d62f722..90d7ae070 100644 --- a/apps/game_backend/lib/game_backend/units/characters/character.ex +++ b/apps/game_backend/lib/game_backend/units/characters/character.ex @@ -106,6 +106,7 @@ defmodule GameBackend.Units.Characters.Character do ]) |> cast_assoc(:basic_skill) |> cast_assoc(:ultimate_skill) + |> unique_constraint([:game_id, :name, :version_id]) |> validate_required([:game_id, :name, :active, :faction]) |> mana_recovery_strategy_validation() end diff --git a/apps/game_backend/lib/game_backend/units/skills.ex b/apps/game_backend/lib/game_backend/units/skills.ex index 265219abb..38cf5e473 100644 --- a/apps/game_backend/lib/game_backend/units/skills.ex +++ b/apps/game_backend/lib/game_backend/units/skills.ex @@ -21,6 +21,21 @@ defmodule GameBackend.Units.Skills do |> Repo.update() end + # TODO: These two functions are placeholders to fix the validations the normal changeset do in the future. + # e.g. the version_id constraint. + # https://github.com/lambdaclass/mirra_backend/issues/1028 + def autobattler_insert_skill(attrs) do + %Skill{} + |> Skill.assoc_changeset(attrs) + |> Repo.insert() + end + + def autobattler_update_skill(skill, attrs \\ %{}) do + skill + |> Skill.assoc_changeset(attrs) + |> Repo.update() + end + @doc """ Inserts all skills into the database. If another one already exists with the same name, it updates it instead. @@ -43,8 +58,8 @@ defmodule GameBackend.Units.Skills do def upsert_skill(attrs) do case get_skill_by_name(attrs.name) do - nil -> insert_skill(attrs) - skill -> update_skill(skill, attrs) + nil -> autobattler_insert_skill(attrs) + skill -> autobattler_update_skill(skill, attrs) end end @@ -54,12 +69,12 @@ defmodule GameBackend.Units.Skills do end) end - def list_curse_skills() do + def list_curse_skills_by_version(version_id) do curse_id = GameBackend.Utils.get_game_id(:curse_of_mirra) q = from(s in Skill, - where: ^curse_id == s.game_id, + where: ^curse_id == s.game_id and ^version_id == s.version_id, preload: [mechanics: [:on_arrival_mechanic, :on_explode_mechanics]] ) diff --git a/apps/game_backend/lib/game_backend/units/skills/skill.ex b/apps/game_backend/lib/game_backend/units/skills/skill.ex index e0f2d4067..29a0dab2e 100644 --- a/apps/game_backend/lib/game_backend/units/skills/skill.ex +++ b/apps/game_backend/lib/game_backend/units/skills/skill.ex @@ -39,36 +39,52 @@ defmodule GameBackend.Units.Skills.Skill do timestamps() end + @permitted [ + :name, + :game_id, + :cooldown, + :energy_regen, + :animation_duration, + :buff_id, + :next_skill_id, + :activation_delay_ms, + :autoaim, + :block_movement, + :can_pick_destination, + :cooldown_mechanism, + :cooldown_ms, + :reset_combo_ms, + :execution_duration_ms, + :inmune_while_executing, + :is_passive, + :is_combo?, + :max_autoaim_range, + :stamina_cost, + :mana_cost, + :type, + :version_id + ] + @doc false def changeset(skill, attrs \\ %{}) do skill - |> cast(attrs, [ - :name, - :game_id, - :cooldown, - :energy_regen, - :animation_duration, - :buff_id, - :next_skill_id, - :activation_delay_ms, - :autoaim, - :block_movement, - :can_pick_destination, - :cooldown_mechanism, - :cooldown_ms, - :reset_combo_ms, - :execution_duration_ms, - :inmune_while_executing, - :is_passive, - :is_combo?, - :max_autoaim_range, - :stamina_cost, - :mana_cost, - :type, - :version_id - ]) + |> cast(attrs, @permitted) + |> cast_assoc(:mechanics) + |> unique_constraint([:game_id, :name, :version_id]) + |> validate_required([:game_id, :name, :version_id]) + |> foreign_key_constraint(:characters, name: "characters_basic_skill_id_fkey") + |> cooldown_mechanism_validation() + |> validate_combo_fields() + |> cast_embed(:effect_to_apply) + end + + @doc false + def assoc_changeset(skill, attrs \\ %{}) do + skill + |> cast(attrs, @permitted) |> cast_assoc(:mechanics) - |> unique_constraint([:game_id, :name]) + |> unique_constraint([:game_id, :name, :version_id]) + |> validate_required([:game_id, :name]) |> foreign_key_constraint(:characters, name: "characters_basic_skill_id_fkey") |> cooldown_mechanism_validation() |> validate_combo_fields() diff --git a/apps/game_backend/lib/game_backend/utils.ex b/apps/game_backend/lib/game_backend/utils.ex index 5747f55e0..707c608b4 100644 --- a/apps/game_backend/lib/game_backend/utils.ex +++ b/apps/game_backend/lib/game_backend/utils.ex @@ -8,4 +8,9 @@ defmodule GameBackend.Utils do def get_daily_rewards_config(), do: Application.get_env(:game_backend, :daily_rewards_config) |> Map.get("reward_per_day") + + def list_curse_skills_by_version_grouped_by_type(version_id) do + GameBackend.Units.Skills.list_curse_skills_by_version(version_id) + |> Enum.group_by(& &1.type) + end end diff --git a/apps/game_backend/priv/repo/migrations/20241216174052_update_skills_unique_index.exs b/apps/game_backend/priv/repo/migrations/20241216174052_update_skills_unique_index.exs new file mode 100644 index 000000000..ab1e91af8 --- /dev/null +++ b/apps/game_backend/priv/repo/migrations/20241216174052_update_skills_unique_index.exs @@ -0,0 +1,12 @@ +defmodule GameBackend.Repo.Migrations.UpdateSkillsUniqueIndex do + use Ecto.Migration + + def change do + drop unique_index(:skills, [:name]) + drop unique_index(:skills, [:game_id, :name]) + drop unique_index(:characters, [:game_id, :name]) + create unique_index(:characters, [:game_id, :name, :version_id]) + + create unique_index(:skills, [:game_id, :name, :version_id]) + end +end diff --git a/apps/gateway/lib/gateway/controllers/curse_of_mirra/configuration_controller.ex b/apps/gateway/lib/gateway/controllers/curse_of_mirra/configuration_controller.ex index ad532ac9a..25047bd52 100644 --- a/apps/gateway/lib/gateway/controllers/curse_of_mirra/configuration_controller.ex +++ b/apps/gateway/lib/gateway/controllers/curse_of_mirra/configuration_controller.ex @@ -16,7 +16,7 @@ defmodule Gateway.Controllers.CurseOfMirra.ConfigurationController do Jason.encode!(%{ characters: encode_characters(version.characters), game: version.game_configuration, - items: encode_items(version.consumable_items), + items: encode_items(version.consumable_items |> Enum.filter(fn ci -> ci.active end)), map: version.map_configurations }) @@ -24,7 +24,9 @@ defmodule Gateway.Controllers.CurseOfMirra.ConfigurationController do end def get_characters_configuration(conn, _params) do - case Characters.get_curse_characters() do + version = Configuration.get_current_version() + + case Characters.get_curse_characters_by_version(version.id) do [] -> {:error, :not_found} @@ -44,12 +46,14 @@ defmodule Gateway.Controllers.CurseOfMirra.ConfigurationController do end def get_map_configurations(conn, _params) do - map_configuration = Configuration.list_map_configurations() + version = Configuration.get_current_version() + map_configuration = Configuration.list_map_configurations_by_version(version.id) send_resp(conn, 200, Jason.encode!(map_configuration)) end def get_consumable_items_configuration(conn, _params) do - consumable_items = Items.list_consumable_items() |> Enum.filter(& &1.active) + version = Configuration.get_current_version() + consumable_items = Items.list_consumable_items_by_version(version.id) |> Enum.filter(& &1.active) send_resp(conn, 200, Jason.encode!(consumable_items)) end diff --git a/priv/repo/seeds.exs b/priv/repo/seeds.exs index 3aff70dbd..581cb5ef8 100644 --- a/priv/repo/seeds.exs +++ b/priv/repo/seeds.exs @@ -10,7 +10,7 @@ champions_of_mirra_id = Utils.get_game_id(:champions_of_mirra) ### Champions Currencies -{:ok, _skills} = Champions.Config.import_skill_config() +{:ok, _skills} = Champions.Config.import_skill_config(champions_of_mirra_id) {:ok, _characters} = Champions.Config.import_character_config() @@ -629,7 +629,8 @@ skills = [ "offset" => 0 } } - ] + ], + "version_id" => version.id }, %{ "name" => "muflus_dash", @@ -649,7 +650,8 @@ skills = [ "speed" => 3.3, "duration_ms" => 330 } - ] + ], + "version_id" => version.id }, %{ "name" => "h4ck_slingshot", @@ -684,7 +686,8 @@ skills = [ "speed" => 4.0, "duration_ms" => 250 } - ] + ], + "version_id" => version.id }, %{ "name" => "h4ck_denial_of_service", @@ -757,7 +760,8 @@ skills = [ "offset" => 0 } ], - "effect_to_apply" => invisible_effect + "effect_to_apply" => invisible_effect, + "version_id" => version.id }, %{ "name" => "uma_sneak", @@ -946,7 +950,8 @@ skills = [ "block_movement" => true, "mechanics" => [ otix_carbonthrow_mechanic - ] + ], + "version_id" => version.id }, %{ "name" => "otix_magma_rush", @@ -962,7 +967,8 @@ skills = [ "block_movement" => true, "mechanics" => [ otix_magma_rush_mechanic - ] + ], + "version_id" => version.id }, %{ "name" => "otix_inferno", @@ -978,7 +984,8 @@ skills = [ "block_movement" => true, "mechanics" => [ inferno - ] + ], + "version_id" => version.id }, %{ "name" => "shinko_toxic_onion", @@ -994,7 +1001,8 @@ skills = [ "block_movement" => true, "mechanics" => [ toxic_onion - ] + ], + "version_id" => version.id }, %{ "name" => "shinko_spore_dash", @@ -1010,7 +1018,8 @@ skills = [ "block_movement" => true, "mechanics" => [ spore_dash - ] + ], + "version_id" => version.id }, %{ "name" => "shinko_PEB", @@ -1026,7 +1035,8 @@ skills = [ "block_movement" => true, "mechanics" => [ putrid_elixir_bomb - ] + ], + "version_id" => version.id }, %{ "name" => "uren_basic", @@ -1055,7 +1065,8 @@ skills = [ "max_autoaim_range" => 1200, "can_pick_destination" => false, "block_movement" => true, - "mechanics" => [multi_piercing_shoot] + "mechanics" => [multi_piercing_shoot], + "version_id" => version.id }, %{ "name" => "uren_dash", @@ -1075,7 +1086,8 @@ skills = [ "speed" => 4, "duration_ms" => 250 } - ] + ], + "version_id" => version.id } ] @@ -1524,8 +1536,7 @@ fake_item_params = %{ active: false, name: "fake_item", radius: 200.0, - mechanics: [spawn_bomb_mechanic], - effects: [], + effect_mechanics: [spawn_bomb_mechanic], version_id: version.id }