diff --git a/lib/galaxies/planet_building.ex b/lib/galaxies/planet_building.ex index 56e7217..3635eec 100644 --- a/lib/galaxies/planet_building.ex +++ b/lib/galaxies/planet_building.ex @@ -8,7 +8,7 @@ defmodule Galaxies.PlanetBuilding do field :current_level, :integer belongs_to :planet, Galaxies.Planet, primary_key: true - belongs_to :building, Galaxies.Building, primary_key: true + belongs_to :building, Galaxies.Building, primary_key: true, type: :integer timestamps(type: :utc_datetime_usec) end diff --git a/lib/galaxies/planet_unit.ex b/lib/galaxies/planet_unit.ex index 18ab46c..66b21ed 100644 --- a/lib/galaxies/planet_unit.ex +++ b/lib/galaxies/planet_unit.ex @@ -6,7 +6,7 @@ defmodule Galaxies.PlanetUnit do field :amount, :integer belongs_to :planet, Galaxies.Planet, primary_key: true - belongs_to :unit, Galaxies.Unit, primary_key: true + belongs_to :unit, Galaxies.Unit, primary_key: true, type: :integer timestamps(type: :utc_datetime_usec) end diff --git a/lib/galaxies/planets.ex b/lib/galaxies/planets.ex index 8aaf1f0..34d5b0c 100644 --- a/lib/galaxies/planets.ex +++ b/lib/galaxies/planets.ex @@ -40,6 +40,7 @@ defmodule Galaxies.Planets do ) planet_building = Enum.find(planet_buildings, fn pb -> pb.building_id == building_id end) + dbg(planet_building) {cost_metal, cost_crystal, cost_deuterium, _energy} = Galaxies.calc_upgrade_cost(planet_building.building.upgrade_cost_formula, level) diff --git a/lib/galaxies/planets/enqueued_building.ex b/lib/galaxies/planets/enqueued_building.ex index dcfe98d..602bb5b 100644 --- a/lib/galaxies/planets/enqueued_building.ex +++ b/lib/galaxies/planets/enqueued_building.ex @@ -17,7 +17,7 @@ defmodule Galaxies.Planets.EnqueuedBuilding do field :started_at, :utc_datetime field :completed_at, :utc_datetime - belongs_to :building, Galaxies.Building + belongs_to :building, Galaxies.Building, type: :integer belongs_to :planet, Galaxies.Planet timestamps(type: :utc_datetime_usec) diff --git a/lib/galaxies/unit.ex b/lib/galaxies/unit.ex index 9e000a4..48bb72a 100644 --- a/lib/galaxies/unit.ex +++ b/lib/galaxies/unit.ex @@ -1,9 +1,10 @@ defmodule Galaxies.Unit do @moduledoc """ Defines the schema for the unit of the game. + Uses integer IDs for simplicity. """ - use Galaxies.Schema + use Ecto.Schema schema "units" do field :name, :string diff --git a/lib/galaxies_web/live/facilities_live.ex b/lib/galaxies_web/live/facilities_live.ex index f5511b6..7894e5a 100644 --- a/lib/galaxies_web/live/facilities_live.ex +++ b/lib/galaxies_web/live/facilities_live.ex @@ -208,7 +208,11 @@ defmodule GalaxiesWeb.FacilitiesLive do level = building.current_level + 1 - case Accounts.upgrade_planet_building(socket.assigns.current_planet, building_id, level) do + case Accounts.upgrade_planet_building( + socket.assigns.current_planet, + String.to_integer(building_id), + level + ) do :ok -> # TODO: doing the same as mount seems a bit too much, try to optimize current_planet = Accounts.get_active_planet(socket.assigns.current_player) diff --git a/lib/galaxies_web/live/resources_live.ex b/lib/galaxies_web/live/resources_live.ex index 0c77dc2..7c433a8 100644 --- a/lib/galaxies_web/live/resources_live.ex +++ b/lib/galaxies_web/live/resources_live.ex @@ -208,7 +208,11 @@ defmodule GalaxiesWeb.ResourcesLive do level = building.current_level + 1 - case Accounts.upgrade_planet_building(socket.assigns.current_planet, building_id, level) do + case Accounts.upgrade_planet_building( + socket.assigns.current_planet, + String.to_integer(building_id), + level + ) do :ok -> # TODO: doing the same as mount seems a bit too much, try to optimize current_planet = Accounts.get_active_planet(socket.assigns.current_player) diff --git a/priv/repo/migrations/20240126093746_create_buildings_table.exs b/priv/repo/migrations/20240126093746_create_buildings_table.exs index a148486..ebed51c 100644 --- a/priv/repo/migrations/20240126093746_create_buildings_table.exs +++ b/priv/repo/migrations/20240126093746_create_buildings_table.exs @@ -3,7 +3,6 @@ defmodule Galaxies.Repo.Migrations.CreateBuildingsTable do def change do create table(:buildings) do - # add :id, :binary_id, primary_key: true add :name, :string, null: false add :short_description, :text, null: false diff --git a/priv/repo/migrations/20240129163345_create_units_table.exs b/priv/repo/migrations/20240129163345_create_units_table.exs index 349e2ef..9488866 100644 --- a/priv/repo/migrations/20240129163345_create_units_table.exs +++ b/priv/repo/migrations/20240129163345_create_units_table.exs @@ -2,8 +2,7 @@ defmodule Galaxies.Repo.Migrations.CreateUnitsTable do use Ecto.Migration def change do - create table(:units, primary_key: false) do - add :id, :binary_id, primary_key: true + create table(:units) do add :name, :string, null: false add :short_description, :text, null: false @@ -37,7 +36,7 @@ defmodule Galaxies.Repo.Migrations.CreateUnitsTable do null: false, primary_key: true - add :unit_id, references(:units, type: :binary_id, on_delete: :delete_all), + add :unit_id, references(:units, on_delete: :delete_all), null: false, primary_key: true diff --git a/priv/repo/migrations/20240129223345_insert_units.exs b/priv/repo/migrations/20240129223345_insert_units.exs index e9f4351..9ad25ba 100644 --- a/priv/repo/migrations/20240129223345_insert_units.exs +++ b/priv/repo/migrations/20240129223345_insert_units.exs @@ -8,6 +8,7 @@ defmodule Galaxies.Repo.Migrations.InsertUnits do Repo.insert_all(Galaxies.Unit, [ %{ + id: 101, name: "Light Fighter", list_order: 10, image_src: "/images/units/light-fighter.webp", @@ -23,6 +24,7 @@ defmodule Galaxies.Repo.Migrations.InsertUnits do updated_at: now }, %{ + id: 102, name: "Heavy Fighter", list_order: 20, image_src: "/images/units/heavy-fighter.webp", @@ -38,6 +40,7 @@ defmodule Galaxies.Repo.Migrations.InsertUnits do updated_at: now }, %{ + id: 103, name: "Cruiser", list_order: 10, image_src: "/images/units/cruiser.webp", @@ -53,6 +56,7 @@ defmodule Galaxies.Repo.Migrations.InsertUnits do updated_at: now }, %{ + id: 104, name: "Battleship", list_order: 10, image_src: "/images/units/battleship.webp", @@ -68,6 +72,7 @@ defmodule Galaxies.Repo.Migrations.InsertUnits do updated_at: now }, %{ + id: 105, name: "Interceptor", list_order: 10, image_src: "/images/units/interceptor.webp", @@ -83,6 +88,7 @@ defmodule Galaxies.Repo.Migrations.InsertUnits do updated_at: now }, %{ + id: 106, name: "Bomber", list_order: 10, image_src: "/images/units/bombardier.webp", @@ -98,6 +104,7 @@ defmodule Galaxies.Repo.Migrations.InsertUnits do updated_at: now }, %{ + id: 107, name: "Destroyer", list_order: 10, image_src: "/images/units/dreadnaught.webp", @@ -113,6 +120,7 @@ defmodule Galaxies.Repo.Migrations.InsertUnits do updated_at: now }, %{ + id: 108, name: "Reaper", list_order: 10, image_src: "/images/units/battleship-v3.webp", @@ -128,6 +136,7 @@ defmodule Galaxies.Repo.Migrations.InsertUnits do updated_at: now }, %{ + id: 109, name: "Deathstar", list_order: 10, image_src: "/images/units/juggernaut.webp", @@ -143,6 +152,7 @@ defmodule Galaxies.Repo.Migrations.InsertUnits do updated_at: now }, %{ + id: 201, name: "Solar Satellite", list_order: 10, image_src: "/images/units/solar-satellite.webp", @@ -158,6 +168,7 @@ defmodule Galaxies.Repo.Migrations.InsertUnits do updated_at: now }, %{ + id: 202, name: "Crawler", list_order: 10, image_src: "/images/units/crawler.webp", @@ -173,6 +184,7 @@ defmodule Galaxies.Repo.Migrations.InsertUnits do updated_at: now }, %{ + id: 301, name: "Spy Probe", list_order: 10, image_src: "/images/units/espionage-probe.webp", @@ -188,6 +200,7 @@ defmodule Galaxies.Repo.Migrations.InsertUnits do updated_at: now }, %{ + id: 401, name: "Small Cargo Ship", list_order: 10, image_src: "/images/units/small-cargo.webp", @@ -203,6 +216,7 @@ defmodule Galaxies.Repo.Migrations.InsertUnits do updated_at: now }, %{ + id: 402, name: "Large Cargo Ship", list_order: 10, image_src: "/images/units/large-cargo.webp", @@ -218,6 +232,7 @@ defmodule Galaxies.Repo.Migrations.InsertUnits do updated_at: now }, %{ + id: 403, name: "Recycler", list_order: 10, image_src: "/images/units/large-cargo-v2.webp", @@ -233,6 +248,7 @@ defmodule Galaxies.Repo.Migrations.InsertUnits do updated_at: now }, %{ + id: 404, name: "Colonizer", list_order: 10, image_src: "/images/units/colony.webp", @@ -247,6 +263,7 @@ defmodule Galaxies.Repo.Migrations.InsertUnits do updated_at: now }, %{ + id: 405, name: "Asteroid Miner", list_order: 10, image_src: "/images/units/asteroid-miner.webp", @@ -262,6 +279,7 @@ defmodule Galaxies.Repo.Migrations.InsertUnits do updated_at: now }, %{ + id: 501, name: "Missile Launcher", list_order: 10, image_src: "/images/units/missile-launcher.webp", @@ -277,6 +295,7 @@ defmodule Galaxies.Repo.Migrations.InsertUnits do updated_at: now }, %{ + id: 502, name: "Light Laser Turret", list_order: 10, image_src: "/images/units/light-laser.webp", @@ -292,6 +311,7 @@ defmodule Galaxies.Repo.Migrations.InsertUnits do updated_at: now }, %{ + id: 503, name: "Heavy Laser Turret", list_order: 10, image_src: "/images/units/heavy-laser.webp", @@ -307,6 +327,7 @@ defmodule Galaxies.Repo.Migrations.InsertUnits do updated_at: now }, %{ + id: 504, name: "Ion Cannon", list_order: 10, image_src: "/images/units/ion-cannon.webp", @@ -322,6 +343,7 @@ defmodule Galaxies.Repo.Migrations.InsertUnits do updated_at: now }, %{ + id: 505, name: "Gauss Cannon", list_order: 10, image_src: "/images/units/gauss-cannon.webp", @@ -337,6 +359,7 @@ defmodule Galaxies.Repo.Migrations.InsertUnits do updated_at: now }, %{ + id: 506, name: "Plasma Cannon", list_order: 10, image_src: "/images/units/plasma-cannon.webp", @@ -351,7 +374,40 @@ defmodule Galaxies.Repo.Migrations.InsertUnits do inserted_at: now, updated_at: now }, + %{ + id: 507, + name: "Small Shield Dome", + list_order: 10, + image_src: "/images/units/small-shield.webp", + short_description: + "The small shield dome covers the defense units and ships with a protective energy shield using a generator. This can absorb additional energy from the outside and is still permeable enough to let your own defenses fire.", + long_description: + "The small shield dome covers facilities and units with a protective energy shield using a generator. This can absorb additional energy from the outside and is still permeable enough to let own defense systems fire. Due to the high energy voltage required, only a limited number of shield domes can be built per planet. This amount can be increased by the ongoing progress of the empire.", + type: :defense, + weapon_points: 0, + shield_points: 2000, + hull_points: 4000, + inserted_at: now, + updated_at: now + }, + %{ + id: 508, + name: "Large Shield Dome", + list_order: 10, + image_src: "/images/units/large-shield.webp", + short_description: + "Further research into shield technologies has significantly improved the resilience of small shield domes. Large shield domes thus cover a much larger area of the planet, which means that its facilities and units can be protected much more efficiently.", + long_description: + "Further research into shield technologies has significantly improved the resilience of small shield domes. Large shield domes thus cover a much larger area of the planet, which means that more facilities and units can be protected more efficiently. Due to the high energy voltage required, only a limited number of shield domes can be built per planet. That number can be increased by ongoing progress of the empire.", + type: :defense, + weapon_points: 0, + shield_points: 10_000, + hull_points: 20_000, + inserted_at: now, + updated_at: now + }, # %{ + # id: 509, # name: "Fortress", # image_src: "/images/units/.webp", # short_description: @@ -364,6 +420,7 @@ defmodule Galaxies.Repo.Migrations.InsertUnits do # hull_points: 960_000 # }, # %{ + # id: 510, # name: "Doom Cannon", # image_src: "/images/units/.webp", # short_description: @@ -376,6 +433,7 @@ defmodule Galaxies.Repo.Migrations.InsertUnits do # hull_points: 3_600_000 # }, # %{ + # id: 511, # name: "Orbital Defense Platform", # image_src: "/images/units/.webp", # short_description: @@ -387,37 +445,8 @@ defmodule Galaxies.Repo.Migrations.InsertUnits do # shield_points: 1_000_000, # hull_points: 22_400_000 # }, - %{ - name: "Small Shield Dome", - list_order: 10, - image_src: "/images/units/small-shield.webp", - short_description: - "The small shield dome covers the defense units and ships with a protective energy shield using a generator. This can absorb additional energy from the outside and is still permeable enough to let your own defenses fire.", - long_description: - "The small shield dome covers facilities and units with a protective energy shield using a generator. This can absorb additional energy from the outside and is still permeable enough to let own defense systems fire. Due to the high energy voltage required, only a limited number of shield domes can be built per planet. This amount can be increased by the ongoing progress of the empire.", - type: :defense, - weapon_points: 0, - shield_points: 2000, - hull_points: 4000, - inserted_at: now, - updated_at: now - }, - %{ - name: "Large Shield Dome", - list_order: 10, - image_src: "/images/units/large-shield.webp", - short_description: - "Further research into shield technologies has significantly improved the resilience of small shield domes. Large shield domes thus cover a much larger area of the planet, which means that its facilities and units can be protected much more efficiently.", - long_description: - "Further research into shield technologies has significantly improved the resilience of small shield domes. Large shield domes thus cover a much larger area of the planet, which means that more facilities and units can be protected more efficiently. Due to the high energy voltage required, only a limited number of shield domes can be built per planet. That number can be increased by ongoing progress of the empire.", - type: :defense, - weapon_points: 0, - shield_points: 10_000, - hull_points: 20_000, - inserted_at: now, - updated_at: now - }, # %{ + # id: 512, # name: "Atmospheric Shield", # image_src: "/images/units/.webp", # short_description: @@ -430,6 +459,7 @@ defmodule Galaxies.Repo.Migrations.InsertUnits do # hull_points: 4_000_000 # }, %{ + id: 601, name: "Interceptor Missile", list_order: 10, image_src: "/images/units/interceptor-missile.webp", @@ -444,6 +474,7 @@ defmodule Galaxies.Repo.Migrations.InsertUnits do updated_at: now }, %{ + id: 602, name: "Interplanetary Missile", list_order: 10, image_src: "/images/units/interplanetary-missile.webp",