Skip to content

Commit

Permalink
Current version now takes all consumable items, also handle items wit…
Browse files Browse the repository at this point in the history
…hout any effect
  • Loading branch information
Nico-Sanchez committed Dec 24, 2024
1 parent 65a609f commit 25dc0c9
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 15 deletions.
3 changes: 2 additions & 1 deletion apps/champions/lib/champions/config.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"""
<h3>No Effect</h3>
"""
end

def effect_form(assigns) do
~H"""
<.button type="button" phx-click={show_modal("effect-form")}>Edit effect</.button>
Expand All @@ -74,7 +80,7 @@ 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" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
<.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} />
</div>
</.inputs_for>
</div>
Expand Down
1 change: 0 additions & 1 deletion apps/game_backend/lib/game_backend/configuration.ex
Original file line number Diff line number Diff line change
Expand Up @@ -417,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]
]
Expand Down
10 changes: 1 addition & 9 deletions apps/game_backend/lib/game_backend/configuration/version.ex
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,6 @@ defmodule GameBackend.Configuration.Version do
|> 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,
:characters,
:consumable_items,
:skills,
:map_configurations,
:game_configuration
])
|> validate_required([:name, :current])
end
end
5 changes: 2 additions & 3 deletions priv/repo/seeds.exs
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down Expand Up @@ -1536,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
}

Expand Down

0 comments on commit 25dc0c9

Please sign in to comment.