diff options
Diffstat (limited to 'app')
-rw-r--r-- | app/controllers/characters/hearth_controller.rb | 1 | ||||
-rw-r--r-- | app/models/hearth_amenity.rb | 12 | ||||
-rw-r--r-- | app/views/characters/hearth/index.html.erb | 2 |
3 files changed, 15 insertions, 0 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 %> <p>You haven't built your hearth yet. First, you'll need to start with a foundation.</p> + <% foundation = @all_amenities.find_by_gid("foundation") %> + <%= link_to "Build #{foundation.name}", "#" %> (requires <%= foundation.build_requirements_string(1) %>) <% end %> |