From 5041f03e272e9e1f3726b5f6b21b3d45cd78dd22 Mon Sep 17 00:00:00 2001 From: David Gay Date: Tue, 25 May 2021 20:00:32 -0400 Subject: Improve hearth view and amenity construction process --- app/models/hearth_amenity.rb | 4 ++- app/views/characters/hearth/index.html.erb | 42 ++++++++++++++++-------------- data/activities.yml | 22 ++++++++++++++++ data/hearth_amenities.yml | 14 ++++++++++ 4 files changed, 61 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.

- -
- <% current_char.hearth.built_hearth_amenities.each do |bhi| %> + <% @all_amenities.each do |ha| %>
-

<%= bhi.hearth_amenity.name %>

-

Level <%= bhi.level %>

-

<%= bhi.hearth_amenity.description %>

- <% 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" %> +

<%= ha.name %>

+ <% built_amenity = current_char.hearth.built_hearth_amenities.find_by(hearth_amenity: ha) %> + <% if built_amenity %> +

Level <%= built_amenity.level %>

+

<%= ha.description %>

+ <% 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 %> +
+ <%= form_with url: start_activity_path do |f| %> + <%= f.hidden_field :id, value: construct_activity.id %> + <%= f.submit construct_activity.name %> + <% end %> +
(costs <%= construct_activity.cost_string %>)
+
+ <% end %>
<% end %>
diff --git a/data/activities.yml b/data/activities.yml index fa38999..c169c0f 100644 --- a/data/activities.yml +++ b/data/activities.yml @@ -35,6 +35,28 @@ construct_forge_level1: - type: "hearth_amenity" gid: "forge" level: 1 +construct_forge_level2: + name: "Construct Forge Level 2" + description: "Build a level 2 forge." + innate: true + whatnot: + requirements: + - type: "hearth_amenity" + gid: "foundation" + level: 1 + duration: + base: 2400 + cost: + - type: "item" + gid: "stone" + quantity: 500 + - type: "item" + gid: "iron_ingot" + quantity: 50 + results: + - type: "hearth_amenity" + gid: "forge" + level: 2 construct_labratory_level1: name: "Construct Labratory Level 1" description: "Build a level 1 labratory." diff --git a/data/hearth_amenities.yml b/data/hearth_amenities.yml index d40fae3..b93070d 100644 --- a/data/hearth_amenities.yml +++ b/data/hearth_amenities.yml @@ -1,9 +1,23 @@ foundation: name: "Foundation" description: "The foundation is the necessary first step to building anything of value." + whatnot: + construct_activities: + - level: 1 + gid: "construct_foundation_level1" forge: name: "Forge" description: "A stone furnace. Can be used for practicing the otherforge skill." + whatnot: + construct_activities: + - level: 1 + gid: "construct_forge_level1" + - level: 2 + gid: "construct_forge_level2" labratory: name: "Labratory" description: "A table and some containers, sufficient for practicing the fluxseethe skill." + whatnot: + construct_activities: + - level: 1 + gid: "construct_labratory_level1" -- cgit v1.2.3