Skip to content

Commit

Permalink
[GH-851] Add square map to seeds (#850)
Browse files Browse the repository at this point in the history
* Add merlio map config

* Add map active field to configurator

* Fix map configurations tests

* Fix configuration tests

* Replace select with checkbox
  • Loading branch information
agustinesco authored Aug 22, 2024
1 parent e580917 commit 2c08655
Show file tree
Hide file tree
Showing 8 changed files with 218 additions and 12 deletions.
6 changes: 5 additions & 1 deletion apps/arena/lib/arena/configuration.ex
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,11 @@ defmodule Arena.Configuration do

Jason.decode!(payload.body, [{:keys, :atoms}])
|> Map.update!(:map, fn maps ->
map = Enum.random(maps)
map =
maps
|> Enum.filter(fn map -> map.active end)
|> Enum.random()

parse_map_config(map)
end)
|> Map.update!(:characters, fn characters ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<.error :if={@changeset.action}>
Oops, something went wrong! Please check the errors below.
</.error>
<.input field={f[:active]} type="checkbox" label="Active" />
<.input
field={f[:version_id]}
type="select"
Expand Down
12 changes: 10 additions & 2 deletions apps/configurator/test/configurator/configuration_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ defmodule Configurator.ConfigurationTest do

import Configurator.ConfigurationFixtures

@invalid_attrs %{radius: nil, initial_positions: nil, obstacles: nil, bushes: nil}
@invalid_attrs %{radius: nil, initial_positions: nil, obstacles: nil, bushes: nil, active: nil}

test "get_map_configuration!/1 returns the map_configuration with given id" do
map_configuration = map_configuration_fixture()
Expand All @@ -17,7 +17,15 @@ defmodule Configurator.ConfigurationTest do

test "create_map_configuration/1 with valid data creates a map_configuration" do
version = version_fixture()
valid_attrs = %{radius: "120.5", initial_positions: [], obstacles: [], bushes: [], version_id: version.id}

valid_attrs = %{
radius: "120.5",
initial_positions: [],
obstacles: [],
bushes: [],
version_id: version.id,
active: true
}

assert {:ok, %MapConfiguration{} = map_configuration} = Configuration.create_map_configuration(valid_attrs)
assert map_configuration.radius == Decimal.new("120.5")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,25 @@ defmodule ConfiguratorWeb.MapConfigurationControllerTest do
import Configurator.AccountsFixtures
setup [:create_authenticated_conn]

@create_attrs %{name: "some_map", radius: "120.5", initial_positions: "", obstacles: "", bushes: "", pools: ""}
@update_attrs %{name: "another_map", radius: "456.7", initial_positions: "", obstacles: "", bushes: "", pools: ""}
@invalid_attrs %{name: nil, radius: nil, initial_positions: nil, obstacles: nil, bushes: nil, pools: nil}
@create_attrs %{
name: "some_map",
radius: "120.5",
initial_positions: "",
obstacles: "",
bushes: "",
pools: "",
active: true
}
@update_attrs %{
name: "another_map",
radius: "456.7",
initial_positions: "",
obstacles: "",
bushes: "",
pools: "",
active: false
}
@invalid_attrs %{name: nil, radius: nil, initial_positions: nil, obstacles: nil, bushes: nil, pools: nil, active: nil}

describe "index" do
test "lists all map_configurations", %{conn: conn} do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ defmodule Configurator.ConfigurationFixtures do
initial_positions: [],
obstacles: [],
radius: "120.5",
version_id: version.id
version_id: version.id,
active: true
})
|> GameBackend.Configuration.create_map_configuration()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ defmodule GameBackend.CurseOfMirra.MapConfiguration do
import Ecto.Changeset
alias GameBackend.Configuration.Version

@derive {Jason.Encoder, only: [:name, :radius, :initial_positions, :obstacles, :bushes, :pools]}
@derive {Jason.Encoder, only: [:name, :radius, :initial_positions, :obstacles, :bushes, :pools, :active]}
schema "map_configurations" do
field(:name, :string)
field(:radius, :decimal)
field(:active, :boolean)

embeds_many(:initial_positions, __MODULE__.Position, on_replace: :delete)
embeds_many(:obstacles, __MODULE__.Obstacle, on_replace: :delete)
Expand All @@ -24,8 +25,8 @@ defmodule GameBackend.CurseOfMirra.MapConfiguration do
@doc false
def changeset(map_configuration, attrs) do
map_configuration
|> cast(attrs, [:radius, :name, :version_id])
|> validate_required([:radius, :version_id])
|> cast(attrs, [:radius, :name, :version_id, :active])
|> validate_required([:radius, :version_id, :active])
|> cast_embed(:initial_positions)
|> cast_embed(:obstacles)
|> cast_embed(:bushes)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
defmodule GameBackend.Repo.Migrations.AddActiveToMapConfig do
use Ecto.Migration

def change do
alter table(:map_configurations) do
add :active, :boolean, default: :false
end
end
end
170 changes: 168 additions & 2 deletions priv/repo/seeds.exs
Original file line number Diff line number Diff line change
Expand Up @@ -926,9 +926,10 @@ polymorph_params = %{
{:ok, _polymorph} =
GameBackend.Items.create_consumable_item(polymorph_params)

map_config = %{
araban_map_config = %{
name: "Araban",
radius: 5520.0,
active: true,
initial_positions: [
%{
x: 5400,
Expand Down Expand Up @@ -2935,7 +2936,172 @@ map_config = %{
version_id: version.id
}

{:ok, _map_configuration_1} = GameBackend.Configuration.create_map_configuration(map_config)
merliot_map_config = %{
name: "Merliot",
radius: 10000.0,
active: false,
initial_positions: [
%{
x: 5360.0,
y: -540.0
},
%{
x: -5130.0,
y: -920.0
},
%{
x: 555.0,
y: 4314.0
},
%{
x: 2750.0,
y: -4200.0
},
%{
x: -3700.0,
y: 2700.0
},
%{
x: 4250.0,
y: 3000.0
},
%{
x: -1842.0,
y: -4505.0
}
],
obstacles: [
%{
name: "East wall",
position: %{
x: 0.0,
y: 0.0
},
radius: 0.0,
shape: "polygon",
type: "static",
base_status: "",
statuses_cycle: %{},
vertices: [
%{
x: 6400.0,
y: 6800.0
},
%{
x: 6800.0,
y: 6800.0
},
%{
x: 6800.0,
y: -6800.0
},
%{
x: 6400.0,
y: -6800.0
}
]
},
%{
name: "North wall",
position: %{
x: 0.0,
y: 0.0
},
radius: 0.0,
shape: "polygon",
type: "static",
base_status: "",
statuses_cycle: %{},
vertices: [
%{
x: 6400.0,
y: 6400.0
},
%{
x: 6400.0,
y: 6800.0
},
%{
x: -6400.0,
y: 6800.0
},
%{
x: -6400.0,
y: 6400.0
}
]
},
%{
name: "West wall",
position: %{
x: 0.0,
y: 0.0
},
radius: 0.0,
shape: "polygon",
type: "static",
base_status: "",
statuses_cycle: %{},
vertices: [
%{
x: -6400.0,
y: 6800.0
},
%{
x: -6800.0,
y: 6800.0
},
%{
x: -6800.0,
y: -6800.0
},
%{
x: -6400.0,
y: -6800.0
}
]
},
%{
name: "South wall",
position: %{
x: 0.0,
y: 0.0
},
radius: 0.0,
shape: "polygon",
type: "static",
base_status: "",
statuses_cycle: %{},
vertices: [
%{
x: -6400.0,
y: -6400.0
},
%{
x: 6400.0,
y: -6400.0
},
%{
x: 6400.0,
y: -6800.0
},
%{
x: -6400.0,
y: -6800.0
}
]
}
],
bushes: [],
pools: [],
version_id: version.id
}

{:ok, _araban_map_configuration} =
GameBackend.Configuration.create_map_configuration(araban_map_config)

{:ok, _merliot_map_configuration} =
GameBackend.Configuration.create_map_configuration(merliot_map_config)

GameBackend.CurseOfMirra.Config.import_quest_descriptions_config()

Expand Down

0 comments on commit 2c08655

Please sign in to comment.