summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app/controllers/characters/hearth_controller.rb4
-rw-r--r--app/models/built_hearth_amenity.rb4
-rw-r--r--app/models/character.rb1
-rw-r--r--app/models/hearth.rb3
-rw-r--r--app/models/hearth_amenity.rb2
-rw-r--r--app/views/application/_navbar.html.erb3
-rw-r--r--app/views/characters/hearth/index.html.erb6
-rw-r--r--config/routes.rb1
-rw-r--r--data/hearth_amenities.yml23
-rw-r--r--data/items.yml3
-rw-r--r--db/migrate/20210518002820_create_hearths.rb9
-rw-r--r--db/migrate/20210518214713_create_hearth_amenities.rb13
-rw-r--r--db/migrate/20210518214817_create_built_hearth_amenities.rb11
-rw-r--r--db/schema.rb32
-rw-r--r--db/seeds.rb5
-rw-r--r--test/fixtures/built_hearth_amenities.yml11
-rw-r--r--test/fixtures/hearth_amenities.yml13
-rw-r--r--test/fixtures/hearths.yml7
-rw-r--r--test/models/built_hearth_amenity_test.rb7
-rw-r--r--test/models/hearth_amenity_test.rb7
-rw-r--r--test/models/hearth_test.rb7
21 files changed, 171 insertions, 1 deletions
diff --git a/app/controllers/characters/hearth_controller.rb b/app/controllers/characters/hearth_controller.rb
new file mode 100644
index 0000000..010404d
--- /dev/null
+++ b/app/controllers/characters/hearth_controller.rb
@@ -0,0 +1,4 @@
+class Characters::HearthController < ApplicationController
+ def index
+ end
+end
diff --git a/app/models/built_hearth_amenity.rb b/app/models/built_hearth_amenity.rb
new file mode 100644
index 0000000..c4d5a53
--- /dev/null
+++ b/app/models/built_hearth_amenity.rb
@@ -0,0 +1,4 @@
+class BuiltHearthAmenity < ApplicationRecord
+ belongs_to :hearth
+ belongs_to :hearth_amenity
+end
diff --git a/app/models/character.rb b/app/models/character.rb
index 7df48e8..661521b 100644
--- a/app/models/character.rb
+++ b/app/models/character.rb
@@ -1,6 +1,7 @@
class Character < ApplicationRecord
belongs_to :user
belongs_to :activity, optional: true
+ has_one :hearth
has_many :character_items
has_many :items, through: :character_items
has_many :character_skills
diff --git a/app/models/hearth.rb b/app/models/hearth.rb
new file mode 100644
index 0000000..8885a08
--- /dev/null
+++ b/app/models/hearth.rb
@@ -0,0 +1,3 @@
+class Hearth < ApplicationRecord
+ belongs_to :character
+end
diff --git a/app/models/hearth_amenity.rb b/app/models/hearth_amenity.rb
new file mode 100644
index 0000000..ecc136a
--- /dev/null
+++ b/app/models/hearth_amenity.rb
@@ -0,0 +1,2 @@
+class HearthAmenity < ApplicationRecord
+end
diff --git a/app/views/application/_navbar.html.erb b/app/views/application/_navbar.html.erb
index 104c349..ef81d6c 100644
--- a/app/views/application/_navbar.html.erb
+++ b/app/views/application/_navbar.html.erb
@@ -9,5 +9,8 @@
<li class="mr-6 inline">
<%= link_to "Inventory", character_items_path(current_char) %>
</li>
+ <li class="mr-6 inline">
+ <%= link_to "Hearth", character_hearth_path(current_char) %>
+ </li>
<% end %>
</ul>
diff --git a/app/views/characters/hearth/index.html.erb b/app/views/characters/hearth/index.html.erb
new file mode 100644
index 0000000..ec055d1
--- /dev/null
+++ b/app/views/characters/hearth/index.html.erb
@@ -0,0 +1,6 @@
+<h1 class="text-3xl">Hearth</h1>
+
+<% if current_char.hearth %>
+<% else %>
+ <p>You haven't built your hearth yet. First, you'll need to start with a foundation.</p>
+<% end %>
diff --git a/config/routes.rb b/config/routes.rb
index 9e6fb82..21230a8 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -18,6 +18,7 @@ Rails.application.routes.draw do
resources :characters, only: [:show, :new, :create] do
scope module: :characters do
resources :items, only: [:index]
+ get "/hearth", to: "hearth#index"
end
end
diff --git a/data/hearth_amenities.yml b/data/hearth_amenities.yml
new file mode 100644
index 0000000..d255e90
--- /dev/null
+++ b/data/hearth_amenities.yml
@@ -0,0 +1,23 @@
+foundation:
+ name: "Foundation"
+ description: "The foundation is the necessary first step to building anything of value."
+ build_data:
+ - level: 1
+ requirements:
+ cost:
+ items:
+ stone: 100
+ wood: 100
+ duration:
+ base: 60
+forge:
+ name: "Forge"
+ description: "Can be used for practicing the otherforge skill."
+ build_data:
+ - level: 1
+ requirements:
+ cost:
+ items:
+ stone: 300
+ duration:
+ base: 600
diff --git a/data/items.yml b/data/items.yml
index 949bb41..06bd627 100644
--- a/data/items.yml
+++ b/data/items.yml
@@ -64,3 +64,6 @@ mending_salve:
name: "Mending salve"
description: "A healing mixture capable of closing wounds."
usable: true
+wood:
+ name: "wood"
+ description: "A bit of wood."
diff --git a/db/migrate/20210518002820_create_hearths.rb b/db/migrate/20210518002820_create_hearths.rb
new file mode 100644
index 0000000..051a2e7
--- /dev/null
+++ b/db/migrate/20210518002820_create_hearths.rb
@@ -0,0 +1,9 @@
+class CreateHearths < ActiveRecord::Migration[6.1]
+ def change
+ create_table :hearths do |t|
+ t.references :character, null: false, foreign_key: true
+
+ t.timestamps
+ end
+ end
+end
diff --git a/db/migrate/20210518214713_create_hearth_amenities.rb b/db/migrate/20210518214713_create_hearth_amenities.rb
new file mode 100644
index 0000000..dbbea6d
--- /dev/null
+++ b/db/migrate/20210518214713_create_hearth_amenities.rb
@@ -0,0 +1,13 @@
+class CreateHearthAmenities < ActiveRecord::Migration[6.1]
+ def change
+ create_table :hearth_amenities do |t|
+ t.string :gid
+ t.string :name
+ t.text :description
+ t.jsonb :build_data
+
+ t.timestamps
+ end
+ add_index :hearth_amenities, :gid
+ end
+end
diff --git a/db/migrate/20210518214817_create_built_hearth_amenities.rb b/db/migrate/20210518214817_create_built_hearth_amenities.rb
new file mode 100644
index 0000000..d9c1c5d
--- /dev/null
+++ b/db/migrate/20210518214817_create_built_hearth_amenities.rb
@@ -0,0 +1,11 @@
+class CreateBuiltHearthAmenities < ActiveRecord::Migration[6.1]
+ def change
+ create_table :built_hearth_amenities do |t|
+ t.references :hearth, null: false, foreign_key: true
+ t.references :hearth_amenity, null: false, foreign_key: true
+ t.integer :level
+
+ t.timestamps
+ end
+ end
+end
diff --git a/db/schema.rb b/db/schema.rb
index 626ec36..7cae7d0 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
-ActiveRecord::Schema.define(version: 2021_05_03_235646) do
+ActiveRecord::Schema.define(version: 2021_05_18_214817) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@@ -27,6 +27,16 @@ ActiveRecord::Schema.define(version: 2021_05_03_235646) do
t.index ["location_id"], name: "index_activities_on_location_id"
end
+ create_table "built_hearth_amenities", force: :cascade do |t|
+ t.bigint "hearth_id", null: false
+ t.bigint "hearth_amenity_id", null: false
+ t.integer "level"
+ t.datetime "created_at", precision: 6, null: false
+ t.datetime "updated_at", precision: 6, null: false
+ t.index ["hearth_amenity_id"], name: "index_built_hearth_amenities_on_hearth_amenity_id"
+ t.index ["hearth_id"], name: "index_built_hearth_amenities_on_hearth_id"
+ end
+
create_table "character_items", force: :cascade do |t|
t.bigint "character_id", null: false
t.bigint "item_id", null: false
@@ -59,6 +69,23 @@ ActiveRecord::Schema.define(version: 2021_05_03_235646) do
t.index ["user_id"], name: "index_characters_on_user_id"
end
+ create_table "hearth_amenities", force: :cascade do |t|
+ t.string "gid"
+ t.string "name"
+ t.text "description"
+ t.jsonb "build_data"
+ t.datetime "created_at", precision: 6, null: false
+ t.datetime "updated_at", precision: 6, null: false
+ t.index ["gid"], name: "index_hearth_amenities_on_gid"
+ end
+
+ create_table "hearths", force: :cascade do |t|
+ t.bigint "character_id", null: false
+ t.datetime "created_at", precision: 6, null: false
+ t.datetime "updated_at", precision: 6, null: false
+ t.index ["character_id"], name: "index_hearths_on_character_id"
+ end
+
create_table "items", force: :cascade do |t|
t.string "gid"
t.string "name"
@@ -118,11 +145,14 @@ ActiveRecord::Schema.define(version: 2021_05_03_235646) do
t.index ["unlock_token"], name: "index_users_on_unlock_token", unique: true
end
+ add_foreign_key "built_hearth_amenities", "hearth_amenities"
+ add_foreign_key "built_hearth_amenities", "hearths"
add_foreign_key "character_items", "characters"
add_foreign_key "character_items", "items"
add_foreign_key "character_skills", "characters"
add_foreign_key "character_skills", "skills"
add_foreign_key "characters", "activities"
add_foreign_key "characters", "users"
+ add_foreign_key "hearths", "characters"
add_foreign_key "users", "characters", column: "active_character_id"
end
diff --git a/db/seeds.rb b/db/seeds.rb
index 7fcd125..cf4caa6 100644
--- a/db/seeds.rb
+++ b/db/seeds.rb
@@ -34,3 +34,8 @@ load_data_file("data/activities.yml").map do |gid, hash|
activity.location = Location.find_by_gid(hash[:location])
activity.save
end
+
+load_data_file("data/hearth_amenities.yml").map do |gid, hash|
+ hearth_amenity = HearthAmenity.find_or_create_by(gid: gid)
+ hearth_amenity.update(hash)
+end
diff --git a/test/fixtures/built_hearth_amenities.yml b/test/fixtures/built_hearth_amenities.yml
new file mode 100644
index 0000000..fa9ee9a
--- /dev/null
+++ b/test/fixtures/built_hearth_amenities.yml
@@ -0,0 +1,11 @@
+# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
+
+one:
+ hearth: one
+ hearth_amenity: one
+ level: 1
+
+two:
+ hearth: two
+ hearth_amenity: two
+ level: 1
diff --git a/test/fixtures/hearth_amenities.yml b/test/fixtures/hearth_amenities.yml
new file mode 100644
index 0000000..d6aef5c
--- /dev/null
+++ b/test/fixtures/hearth_amenities.yml
@@ -0,0 +1,13 @@
+# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
+
+one:
+ gid: MyString
+ name: MyString
+ description: MyText
+ build_data:
+
+two:
+ gid: MyString
+ name: MyString
+ description: MyText
+ build_data:
diff --git a/test/fixtures/hearths.yml b/test/fixtures/hearths.yml
new file mode 100644
index 0000000..c8cea5e
--- /dev/null
+++ b/test/fixtures/hearths.yml
@@ -0,0 +1,7 @@
+# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
+
+one:
+ character: one
+
+two:
+ character: two
diff --git a/test/models/built_hearth_amenity_test.rb b/test/models/built_hearth_amenity_test.rb
new file mode 100644
index 0000000..0aad38f
--- /dev/null
+++ b/test/models/built_hearth_amenity_test.rb
@@ -0,0 +1,7 @@
+require "test_helper"
+
+class BuiltHearthAmenityTest < ActiveSupport::TestCase
+ # test "the truth" do
+ # assert true
+ # end
+end
diff --git a/test/models/hearth_amenity_test.rb b/test/models/hearth_amenity_test.rb
new file mode 100644
index 0000000..895a1d6
--- /dev/null
+++ b/test/models/hearth_amenity_test.rb
@@ -0,0 +1,7 @@
+require "test_helper"
+
+class HearthAmenityTest < ActiveSupport::TestCase
+ # test "the truth" do
+ # assert true
+ # end
+end
diff --git a/test/models/hearth_test.rb b/test/models/hearth_test.rb
new file mode 100644
index 0000000..16dbac0
--- /dev/null
+++ b/test/models/hearth_test.rb
@@ -0,0 +1,7 @@
+require "test_helper"
+
+class HearthTest < ActiveSupport::TestCase
+ # test "the truth" do
+ # assert true
+ # end
+end