summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
Diffstat (limited to 'app')
-rw-r--r--app/models/hearth_amenity.rb4
-rw-r--r--app/views/characters/hearth/index.html.erb42
2 files changed, 25 insertions, 21 deletions
diff --git a/app/models/hearth_amenity.rb b/app/models/hearth_amenity.rb
index f8ebad5..a5dde23 100644
--- a/app/models/hearth_amenity.rb
+++ b/app/models/hearth_amenity.rb
@@ -4,6 +4,8 @@ class HearthAmenity < ApplicationRecord
validates :gid, :name, :description, presence: true
def construct_activity(level)
- Activity.find_by_gid("construct_#{self.name.underscore}_level#{level}")
+ activity_data = self.whatnot[:construct_activities].find { |a| a[:level] == level }
+ return nil unless activity_data
+ Activity.find_by_gid(activity_data[:gid])
end
end
diff --git a/app/views/characters/hearth/index.html.erb b/app/views/characters/hearth/index.html.erb
index 6f2c444..e425fee 100644
--- a/app/views/characters/hearth/index.html.erb
+++ b/app/views/characters/hearth/index.html.erb
@@ -6,30 +6,32 @@
in these realms. Amidst this great dream of planar chaos and destruction, you have built something.
</p>
- <ul class="my-4">
- <% @construct_activities.each do |activity| %>
- <li>
- <%= form_with url: start_activity_path do |f| %>
- <%= f.hidden_field :id, value: activity.id %>
- <%= f.submit activity.name %>
- <% end %>
- (costs <%= activity.cost_string %>)
- </li>
- <% end %>
- </ul>
-
<div class="grid grid-cols-2 gap-4">
- <% current_char.hearth.built_hearth_amenities.each do |bhi| %>
+ <% @all_amenities.each do |ha| %>
<div class="border-2 border-gray-800 rounded p-4">
- <h2 class="text-lg font-bold"><%= bhi.hearth_amenity.name %></h2>
- <p class="mb-2">Level <%= bhi.level %></p>
- <p class="mb-2"><%= bhi.hearth_amenity.description %></p>
- <% if bhi.hearth_amenity.gid == "forge" %>
- <%= form_with url: start_activity_path, method: :post do |f| %>
- <%= f.select :id, @forge_activities.map { |a| [a.name, a.id] } %>
- <%= f.submit "Go" %>
+ <h2 class="text-lg font-bold"><%= ha.name %></h2>
+ <% built_amenity = current_char.hearth.built_hearth_amenities.find_by(hearth_amenity: ha) %>
+ <% if built_amenity %>
+ <p class="mb-2">Level <%= built_amenity.level %></p>
+ <p class="mb-2"><%= ha.description %></p>
+ <% if ha.gid == "forge" %>
+ <%= form_with url: start_activity_path, method: :post do |f| %>
+ <%= f.select :id, @forge_activities.map { |a| [a.name, a.id] } %>
+ <%= f.submit "Go" %>
+ <% end %>
<% end %>
<% end %>
+ <% next_level = built_amenity ? built_amenity.level + 1 : 1 %>
+ <% construct_activity = ha.construct_activity(next_level) %>
+ <% if construct_activity %>
+ <div class="my-3">
+ <%= form_with url: start_activity_path do |f| %>
+ <%= f.hidden_field :id, value: construct_activity.id %>
+ <%= f.submit construct_activity.name %>
+ <% end %>
+ <div class="text-sm">(costs <%= construct_activity.cost_string %>)</div>
+ </div>
+ <% end %>
</div>
<% end %>
</div>