<.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"
- />
+
- <.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"
- />
+
- <.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"
- />
+
- <.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
}