summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
Diffstat (limited to 'app')
-rw-r--r--app/controllers/characters/hearth_controller.rb21
-rw-r--r--app/models/hearth.rb6
-rw-r--r--app/views/characters/hearth/index.html.erb4
3 files changed, 28 insertions, 3 deletions
diff --git a/app/controllers/characters/hearth_controller.rb b/app/controllers/characters/hearth_controller.rb
index abe8232..02b8446 100644
--- a/app/controllers/characters/hearth_controller.rb
+++ b/app/controllers/characters/hearth_controller.rb
@@ -2,6 +2,25 @@ class Characters::HearthController < ApplicationController
def index
@all_amenities = HearthAmenity.all
@construct_activities = Activity.where("gid like ?", "construct_%")
- @forge_activities = Activity.where("gid like ?", "craft_%")
+
+ @amenity_activities = {
+ forge: [],
+ labratory: [],
+ }
+
+ Activity.where("gid like ?", "craft_%").each do |activity|
+ activity.whatnot[:requirements]&.each do |requirement_data|
+ if requirement_data[:type] == "hearth_amenity"
+ case requirement_data[:gid]
+ when "forge"
+ @amenity_activities[:forge].push(activity) && next
+ when "labratory"
+ @amenity_activities[:labratory].push(activity) && next
+ else
+ raise "Invalid amenity gid (#{requirement_data[:gid]}"
+ end
+ end
+ end
+ end
end
end
diff --git a/app/models/hearth.rb b/app/models/hearth.rb
index 5d244ec..1bd54a5 100644
--- a/app/models/hearth.rb
+++ b/app/models/hearth.rb
@@ -9,4 +9,10 @@ class Hearth < ApplicationRecord
return false unless bhi
bhi.level >= level
end
+
+ def amenity_level(hearth_amenity)
+ hearth_amenity = HearthAmenity.find_by_gid(hearth_amenity) if hearth_amenity.is_a? String
+ bhi = self.built_hearth_amenities.find_by(hearth_amenity: hearth_amenity)
+ bhi ? bhi.level : 0
+ end
end
diff --git a/app/views/characters/hearth/index.html.erb b/app/views/characters/hearth/index.html.erb
index c95977e..7baf2bf 100644
--- a/app/views/characters/hearth/index.html.erb
+++ b/app/views/characters/hearth/index.html.erb
@@ -14,9 +14,9 @@
<% if built_amenity %>
<p class="mb-2">Level <%= built_amenity.level %></p>
<p class="mb-2"><%= ha.description %></p>
- <% if ha.gid == "forge" %>
+ <% if @amenity_activities[ha.gid.to_sym] %>
<%= form_with url: start_activity_path, method: :post do |f| %>
- <%= f.select :id, @forge_activities.map { |a| [a.name, a.id] } %>
+ <%= f.select :id, @amenity_activities[ha.gid.to_sym].map { |a| [a.name, a.id] } %>
<%= f.submit "Go" %>
<% end %>
<% end %>