Skip to content

Commit

Permalink
make building IDs integers for simplicity
Browse files Browse the repository at this point in the history
  • Loading branch information
goncalotomas committed Apr 3, 2024
1 parent 4db2386 commit a866d5f
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 9 deletions.
3 changes: 2 additions & 1 deletion lib/galaxies/building.ex
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
defmodule Galaxies.Building do
@moduledoc """
Defines the schema for the buildings of the game.
Uses integer IDs for simplicity.
"""

use Galaxies.Schema
use Ecto.Schema

schema "buildings" do
field :name, :string
Expand Down
4 changes: 2 additions & 2 deletions lib/galaxies/buildings.ex
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ defmodule Galaxies.Buildings do
"""

# TODO: Maybe read hardcoded IDs from file or Application.compile_env?
@terraformer_id "fe80d118-99fa-4792-8d27-1053d2960a94"
@terraformer_building_id 13

@doc """
Determines the increase in used fields when upgrading a building.
Expand All @@ -21,7 +21,7 @@ defmodule Galaxies.Buildings do
"""
def total_fields_increase(_building_id, _level, true), do: 0

def total_fields_increase(@terraformer_id, level, _demolish) do
def total_fields_increase(@terraformer_building_id, level, _demolish) do
if rem(level, 2) == 0 do
6
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ defmodule Galaxies.Repo.Migrations.CreateBuildingsTable do
use Ecto.Migration

def change do
create table(:buildings, primary_key: false) do
add :id, :binary_id, primary_key: true
create table(:buildings) do
# add :id, :binary_id, primary_key: true
add :name, :string, null: false

add :short_description, :text, null: false
Expand Down Expand Up @@ -31,7 +31,7 @@ defmodule Galaxies.Repo.Migrations.CreateBuildingsTable do
null: false,
primary_key: true

add :building_id, references(:buildings, type: :binary_id, on_delete: :delete_all),
add :building_id, references(:buildings, on_delete: :delete_all),
null: false,
primary_key: true

Expand Down
18 changes: 17 additions & 1 deletion priv/repo/migrations/20240126113248_insert_buildings.exs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
defmodule Galaxies.Repo.Migrations.InsertBuildings do
@moduledoc """
Inserts the main building entities for the game.
"""
use Ecto.Migration

alias Galaxies.Repo
Expand All @@ -9,6 +12,7 @@ defmodule Galaxies.Repo.Migrations.InsertBuildings do

Repo.insert_all(Building, [
%{
id: 1,
name: "Metal Mine",
type: :resource,
list_order: 10,
Expand All @@ -23,6 +27,7 @@ defmodule Galaxies.Repo.Migrations.InsertBuildings do
updated_at: now
},
%{
id: 2,
name: "Crystal Mine",
type: :resource,
list_order: 20,
Expand All @@ -37,6 +42,7 @@ defmodule Galaxies.Repo.Migrations.InsertBuildings do
updated_at: now
},
%{
id: 3,
name: "Deuterium Synthesizer",
type: :resource,
list_order: 30,
Expand All @@ -51,6 +57,7 @@ defmodule Galaxies.Repo.Migrations.InsertBuildings do
updated_at: now
},
%{
id: 4,
name: "Solar Power Plant",
type: :resource,
list_order: 40,
Expand All @@ -65,6 +72,7 @@ defmodule Galaxies.Repo.Migrations.InsertBuildings do
updated_at: now
},
%{
id: 5,
name: "Fusion Reactor",
type: :resource,
list_order: 50,
Expand All @@ -80,6 +88,7 @@ defmodule Galaxies.Repo.Migrations.InsertBuildings do
updated_at: now
},
%{
id: 6,
name: "Metal Storage",
type: :resource,
list_order: 60,
Expand All @@ -94,6 +103,7 @@ defmodule Galaxies.Repo.Migrations.InsertBuildings do
updated_at: now
},
%{
id: 7,
name: "Crystal Storage",
type: :resource,
list_order: 70,
Expand All @@ -108,6 +118,7 @@ defmodule Galaxies.Repo.Migrations.InsertBuildings do
updated_at: now
},
%{
id: 8,
name: "Deuterium Tank",
type: :resource,
list_order: 80,
Expand All @@ -122,6 +133,7 @@ defmodule Galaxies.Repo.Migrations.InsertBuildings do
updated_at: now
},
%{
id: 9,
name: "Robot Factory",
type: :facility,
list_order: 90,
Expand All @@ -136,6 +148,7 @@ defmodule Galaxies.Repo.Migrations.InsertBuildings do
updated_at: now
},
%{
id: 10,
name: "Nanite Factory",
type: :facility,
list_order: 100,
Expand All @@ -151,6 +164,7 @@ defmodule Galaxies.Repo.Migrations.InsertBuildings do
updated_at: now
},
%{
id: 11,
name: "Shipyard",
type: :facility,
list_order: 110,
Expand All @@ -165,6 +179,7 @@ defmodule Galaxies.Repo.Migrations.InsertBuildings do
updated_at: now
},
%{
id: 12,
name: "Research Lab",
type: :facility,
list_order: 120,
Expand All @@ -179,7 +194,7 @@ defmodule Galaxies.Repo.Migrations.InsertBuildings do
updated_at: now
},
%{
id: "fe80d118-99fa-4792-8d27-1053d2960a94",
id: 13,
name: "Terraformer",
type: :facility,
list_order: 130,
Expand All @@ -194,6 +209,7 @@ defmodule Galaxies.Repo.Migrations.InsertBuildings do
updated_at: now
},
%{
id: 14,
name: "Missile Silo",
type: :facility,
list_order: 140,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ defmodule Galaxies.Repo.Migrations.CreateEventQueueTables do
add :id, :binary_id, primary_key: true
add :planet_id, references(:planets, type: :binary_id, on_delete: :delete_all), null: false

add :building_id, references(:buildings, type: :binary_id, on_delete: :delete_all),
null: false
add :building_id, references(:buildings, on_delete: :delete_all), null: false

add :level, :integer, null: false
add :list_order, :integer, null: false
Expand Down

0 comments on commit a866d5f

Please sign in to comment.