From 282c27edf741a36ec5bb659ab57bafa4e7a3eb9a Mon Sep 17 00:00:00 2001 From: David Gay Date: Sun, 6 Jun 2021 00:20:33 -0400 Subject: New inventory view, with items sorted by categories --- app/models/concerns/has_whatnot.rb | 7 ++- .../characters/items/_inventory_section.html.erb | 34 ++++++++++++++ app/views/characters/items/index.html.erb | 54 +++++++++------------- 3 files changed, 62 insertions(+), 33 deletions(-) create mode 100644 app/views/characters/items/_inventory_section.html.erb (limited to 'app') diff --git a/app/models/concerns/has_whatnot.rb b/app/models/concerns/has_whatnot.rb index a0934ef..22322c0 100644 --- a/app/models/concerns/has_whatnot.rb +++ b/app/models/concerns/has_whatnot.rb @@ -7,7 +7,12 @@ module HasWhatnot end def tags - whatnot[:tags] ? whatnot[:tags] : [] + whatnot && whatnot[:tags] ? whatnot[:tags] : [] + end + + def has_tag?(tag) + return false unless tags.any? + tags.include?(tag) end def where_has_tag(tag) diff --git a/app/views/characters/items/_inventory_section.html.erb b/app/views/characters/items/_inventory_section.html.erb new file mode 100644 index 0000000..727e3a1 --- /dev/null +++ b/app/views/characters/items/_inventory_section.html.erb @@ -0,0 +1,34 @@ +<% if character_items.any? %> +

<%= heading %>

+
+ <% character_items.each do |ci| %> +
+
+
<%= link_to ci.item.name, item_path(ci.item) %>
+
+ <%= ci.quantity %> +
+
+
+ <%= truncate(ci.item.description) %> +
+ <% if ci.item.equipment? %> +
<%= ci.item.equip_slots.map {|s| s.to_s.humanize}.join(", ") %>
+ <% end %> +
+ <% if ci.item.equipment? %> +
+ <%= button_to "Equip", character_item_equip_path(item_id: ci.item.id) %> +
+ <% end %> + <% if ci.item.usable? %> +
+ <%= button_to "Use", character_item_use_path(item_id: ci.item.id) %> +
+ <% end %> +
+
+ <% end %> +
+<% end %> diff --git a/app/views/characters/items/index.html.erb b/app/views/characters/items/index.html.erb index f40e666..140b737 100644 --- a/app/views/characters/items/index.html.erb +++ b/app/views/characters/items/index.html.erb @@ -1,6 +1,4 @@ -

Inventory

- -

Equipment

+

Equipped Items

@@ -23,34 +21,26 @@
-

Inventory

+<%= render "characters/items/inventory_section", heading: "Equipment", + character_items: @character.character_items.ordered_by_item_name.select { |ci| + ci.item.equipment? && ci.item.tags.none? } %> - - - - - - - - - - - <% @character.character_items.ordered_by_item_name.each do |ci| %> - - - - - - - <% end %> - -
AmountItemEquipUse
<%= ci.quantity %><%= link_to ci.item.name, item_path(ci.item) %> - <% if ci.item.equipment? %> - <%= button_to "Equip", character_item_equip_path(item_id: ci.item.id) %> - <% end %> - - <% if ci.item.usable? %> - <%= button_to "Use", character_item_use_path(item_id: ci.item.id) %> - <% end %> -
+<%= render "characters/items/inventory_section", heading: "Tools", + character_items: @character.character_items.ordered_by_item_name.select { |ci| + ci.item.has_tag?("tool") } %> + +<%= render "characters/items/inventory_section", heading: "Consumables", + character_items: @character.character_items.ordered_by_item_name.select { |ci| + ci.item.usable? } %> + +<%= render "characters/items/inventory_section", heading: "Seeds", + character_items: @character.character_items.ordered_by_item_name.select { |ci| + ci.item.has_tag?("seed") } %> + +<%= render "characters/items/inventory_section", heading: "Materials", + character_items: @character.character_items.ordered_by_item_name.select { |ci| + ci.item.has_tag?("material") } %> +<%= render "characters/items/inventory_section", heading: "Miscellany", + character_items: @character.character_items.ordered_by_item_name.select { |ci| + !ci.item.equipment? && !ci.item.usable? && ci.item.tags.none? } %> -- cgit v1.2.3