diff --git a/app/models/item.rb b/app/models/item.rb index 3f8dfaa6..bb5ffe2e 100644 --- a/app/models/item.rb +++ b/app/models/item.rb @@ -764,7 +764,7 @@ class Item < ActiveRecord::Base end single_search_filter :type, {:limit => true, :scope => :join_swf_assets} do |zone_set_name| - zone_set = Zone::ItemZoneSets[zone_set_name] + zone_set = Zone.find_set(zone_set_name) raise SearchError, "Type \"#{zone_set_name}\" does not exist" unless zone_set SwfAsset.arel_table[:zone_id].in(zone_set.map(&:id)) end diff --git a/app/models/zone.rb b/app/models/zone.rb index cf79690b..fef3983e 100644 --- a/app/models/zone.rb +++ b/app/models/zone.rb @@ -17,16 +17,35 @@ class Zone < StaticResource @sometimes ? "#{label} sometimes" : label end + def self.find_set(name) + ItemZoneSets[plain(name)] + end + + def self.plain(name) + name.delete('\- /').downcase + end + n = 0 @objects = YAML.load_file(Rails.root.join('config', 'zones.yml')).map do |a| a['id'] = (n += 1) obj = new(a) if obj.type_id == 2 || obj.type_id == 3 - zone_name = obj.label.delete(' -').gsub(/item$/, '').downcase - ItemZoneSets[zone_name] ||= [] - ItemZoneSets[zone_name] << obj + plain_name = plain(obj.label) + + ItemZoneSets[plain_name] ||= [] + ItemZoneSets[plain_name] << obj end obj end n = nil + + # Add aliases to keys like "lowerforegrounditem" to "lowerforeground" + # ...unless there's already such a key, like "backgrounditem" to "background", + # in which case we don't, because that'd be silly. + ItemZoneSets.keys.each do |name| + if name.end_with?('item') + stripped_name = name[0..-5] + ItemZoneSets[stripped_name] ||= ItemZoneSets[name] + end + end end