Skip to content

Commit

Permalink
Merge pull request #6862 from desertkaz/desertkaz-patch-2
Browse files Browse the repository at this point in the history
[script][inventory-manager]make nested container information an option vs default for output for search and list
  • Loading branch information
MahtraDR authored Jul 14, 2024
2 parents 9bfacfe + 6219e1e commit e4df590
Showing 1 changed file with 25 additions and 7 deletions.
32 changes: 25 additions & 7 deletions inventory-manager.lic
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,13 @@ class InventoryManager
],
[
{ name: 'search', regex: /search/i, description: 'Start a search across all characters for specified item.' },
{ name: 'item', regex: /\w+/i, optional: false, description: 'Item to find.' }
{ name: 'item', regex: /\w+/i, optional: false, description: 'Item to find.' },
{ name: 'nest', regex: /nest|-n/i, optional: true, description: 'Print the nesting container data', default: false }
],
[
{ name: 'list', regex: /list/i, description: "Print out a list of names in the database." },
{ name: 'name', regex: /\w+/i, optional: true, description: "List full inventory for specified character. (Can spam!)" }
{ name: 'name', regex: /\w+/i, optional: true, description: "List full inventory for specified character. (Can spam!)" },
{ name: 'nest', regex: /nest|-n/i, optional: true, description: 'Print the nesting container data', default: false }
],
[
{ name: 'remove', regex: /remove/i, description: "Remove character's inventory." },
Expand Down Expand Up @@ -84,9 +86,9 @@ class InventoryManager
elsif args.remove
remove_character_data(args.name)
elsif args.search
search_for_item(args.item)
search_for_item(args.item, args.nest)
elsif args.list
list_character_inv(args.name)
list_character_inv(args.name, args.nest)
else
DRC.message('Type ;inventory-manager help for a usage guide')
end
Expand Down Expand Up @@ -471,7 +473,7 @@ class InventoryManager
save_item_data('trader_shop')
end

def list_character_inv(name)
def list_character_inv(name, nested)
if name.nil?
DRC.message("There is inventory data for:")
@item_data.each do |k, v|
Expand All @@ -489,20 +491,28 @@ class InventoryManager
name_sym = name.capitalize.to_sym
if @item_data.has_key?(name_sym)
DRC.message("Inventory for #{name.capitalize}")
@item_data[name_sym].each { |item| DRC.message(" - #{item}") }
@item_data[name_sym].each { |item|
if !nested
item = strip_nesting(item)
end
DRC.message(" - #{item}")
}
else
DRC.message("No data found for the character #{name.capitalize}!")
end
end

def search_for_item(item)
def search_for_item(item, nested)
total_found = 0
@item_data.each do |k, v|
next if k == @version_string

total_found = 0
DRC.message("Checking #{k}:")
v.each { |data|
if !nested
data = strip_nesting(data)
end
if data.downcase.include?(item)
total_found += 1
DRC.message("Match #{total_found}): #{data}")
Expand All @@ -512,6 +522,14 @@ class InventoryManager
end
end

def strip_nesting(item)
if (match = /^(?<tap>[a-z "':!-]*(?<closed>\(closed\))?)\s\((?<nest1>(?<nest2>nested container[A-Za-z "':!-]*)\s\()?(?<main>in container[a-z '-]*)\)?\)\s(?<origin>\(.*\))$/i.match(item))
return "#{match["tap"]} #{match["origin"]}"
else
return item
end
end

def remove_character_data(name_to_remove)
return if name_to_remove == "version"

Expand Down

0 comments on commit e4df590

Please sign in to comment.