From 9ab7dfd99e7015513bfe1a092f257c1c7a7afb1b Mon Sep 17 00:00:00 2001 From: David Gay Date: Tue, 18 May 2021 18:35:49 -0400 Subject: Display hearth foundation requirements --- app/controllers/characters/hearth_controller.rb | 1 + app/models/hearth_amenity.rb | 12 ++++++++ app/views/characters/hearth/index.html.erb | 2 ++ data/hearth_amenities.yml | 32 ++++++++++++---------- .../20210518214713_create_hearth_amenities.rb | 2 +- db/schema.rb | 2 +- test/fixtures/hearth_amenities.yml | 4 +-- 7 files changed, 36 insertions(+), 19 deletions(-) diff --git a/app/controllers/characters/hearth_controller.rb b/app/controllers/characters/hearth_controller.rb index 010404d..27cd77d 100644 --- a/app/controllers/characters/hearth_controller.rb +++ b/app/controllers/characters/hearth_controller.rb @@ -1,4 +1,5 @@ class Characters::HearthController < ApplicationController def index + @all_amenities = HearthAmenity.all end end diff --git a/app/models/hearth_amenity.rb b/app/models/hearth_amenity.rb index ecc136a..16d8f97 100644 --- a/app/models/hearth_amenity.rb +++ b/app/models/hearth_amenity.rb @@ -1,2 +1,14 @@ class HearthAmenity < ApplicationRecord + include HasWhatnot + + validates :gid, :name, :description, :whatnot, presence: true + + def build_requirements_string(level) + requirements = [] + data = self.whatnot[:constructions].find { |d| d[:level] == level } + data[:cost][:items].each do |item_gid, quantity| + requirements.push "#{quantity} #{Item.find_by_gid(item_gid).name}" + end + requirements.join(", ") + end end diff --git a/app/views/characters/hearth/index.html.erb b/app/views/characters/hearth/index.html.erb index ec055d1..421d5e6 100644 --- a/app/views/characters/hearth/index.html.erb +++ b/app/views/characters/hearth/index.html.erb @@ -3,4 +3,6 @@ <% if current_char.hearth %> <% else %>

You haven't built your hearth yet. First, you'll need to start with a foundation.

+ <% foundation = @all_amenities.find_by_gid("foundation") %> + <%= link_to "Build #{foundation.name}", "#" %> (requires <%= foundation.build_requirements_string(1) %>) <% end %> diff --git a/data/hearth_amenities.yml b/data/hearth_amenities.yml index d255e90..a9c6889 100644 --- a/data/hearth_amenities.yml +++ b/data/hearth_amenities.yml @@ -1,23 +1,25 @@ 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 + whatnot: + constructions: + - 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 + whatnot: + constructions: + - level: 1 + requirements: + cost: + items: + stone: 300 + duration: + base: 600 diff --git a/db/migrate/20210518214713_create_hearth_amenities.rb b/db/migrate/20210518214713_create_hearth_amenities.rb index dbbea6d..cf95352 100644 --- a/db/migrate/20210518214713_create_hearth_amenities.rb +++ b/db/migrate/20210518214713_create_hearth_amenities.rb @@ -4,7 +4,7 @@ class CreateHearthAmenities < ActiveRecord::Migration[6.1] t.string :gid t.string :name t.text :description - t.jsonb :build_data + t.jsonb :whatnot t.timestamps end diff --git a/db/schema.rb b/db/schema.rb index 7cae7d0..0fd6922 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -73,7 +73,7 @@ ActiveRecord::Schema.define(version: 2021_05_18_214817) do t.string "gid" t.string "name" t.text "description" - t.jsonb "build_data" + t.jsonb "whatnot" 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" diff --git a/test/fixtures/hearth_amenities.yml b/test/fixtures/hearth_amenities.yml index d6aef5c..57af6db 100644 --- a/test/fixtures/hearth_amenities.yml +++ b/test/fixtures/hearth_amenities.yml @@ -4,10 +4,10 @@ one: gid: MyString name: MyString description: MyText - build_data: + whatnot: two: gid: MyString name: MyString description: MyText - build_data: + whatnot: -- cgit v1.2.3