From bfd825d98e45d58d8fdbde8510ab65df60934436 Mon Sep 17 00:00:00 2001 From: Matchu Date: Wed, 23 Jan 2013 00:25:09 -0600 Subject: [PATCH] attempt to fix new species_support_ids format. sigh. --- app/controllers/swf_assets_controller.rb | 5 +---- app/models/item.rb | 17 ++++++++++++----- app/models/static_resource.rb | 14 ++++++++++++-- app/models/swf_asset.rb | 6 +----- 4 files changed, 26 insertions(+), 16 deletions(-) diff --git a/app/controllers/swf_assets_controller.rb b/app/controllers/swf_assets_controller.rb index c7b00657..8ce7c9f3 100644 --- a/app/controllers/swf_assets_controller.rb +++ b/app/controllers/swf_assets_controller.rb @@ -15,13 +15,10 @@ class SwfAssetsController < ApplicationController end elsif params[:pet_type_id] && params[:item_ids] pet_type = PetType.find(params[:pet_type_id], :select => [:body_id, :species_id]) - items = Item.find(params[:item_ids], :select => [:id, :species_support_ids]) - compatible_items = items.select { |i| i.support_species?(pet_type.species) } - compatible_item_ids = compatible_items.map(&:id) @swf_assets = SwfAsset.object_assets. fitting_body_id(pet_type.body_id). - for_item_ids(compatible_item_ids). + for_item_ids(params[:item_ids]). with_parent_ids json = @swf_assets.map { |a| a.as_json(:parent_id => a.parent_id.to_i, :for => 'wardrobe') } elsif params[:pet_state_id] diff --git a/app/models/item.rb b/app/models/item.rb index 11a5c314..f3c6e7ce 100644 --- a/app/models/item.rb +++ b/app/models/item.rb @@ -146,11 +146,12 @@ class Item < ActiveRecord::Base end def supported_species - @supported_species ||= species_support_ids.blank? ? Species.all : species_support_ids.sort.map { |id| Species.find(id) } - end - - def support_species?(species) - species_support_ids.blank? || species_support_ids.include?(species.id) + body_ids = swf_assets.select([:body_id]).map(&:body_id) + return Species.all if body_ids.include?(0) + + pet_types = PetType.where(:body_id => body_ids).select([:species_id]) + species_ids = pet_types.map(&:species_id).uniq + Species.find(species_ids) end def self.search(query, user=nil) @@ -230,6 +231,12 @@ class Item < ActiveRecord::Base end end end + + def body_specific? + # If there are species support IDs (it's not empty), the item is + # body-specific. If it's empty, it fits everyone the same. + !species_support_ids.empty? + end def origin_registry_info=(info) # bear in mind that numbers from registries are floats diff --git a/app/models/static_resource.rb b/app/models/static_resource.rb index 0db48d2c..8d4c7053 100644 --- a/app/models/static_resource.rb +++ b/app/models/static_resource.rb @@ -5,11 +5,21 @@ class StaticResource @objects end - def self.find(id) - @objects[id-1] + def self.find(id_or_ids) + if id_or_ids.is_a?(Array) + id_or_ids.uniq.map { |id| find_one(id) } + else + find_one(id_or_ids) + end end def self.count @objects.size end + + private + + def self.find_one(id) + @objects[id - 1] + end end diff --git a/app/models/swf_asset.rb b/app/models/swf_asset.rb index fd8f7b00..f5814a45 100644 --- a/app/models/swf_asset.rb +++ b/app/models/swf_asset.rb @@ -197,11 +197,7 @@ class SwfAsset < ActiveRecord::Base end def body_specific? - # If we already have assigned this a non-zero body id, or if the asset is - # in a body-specific zone, or if the item is explicitly labeled as - # body-specific (like Encased In Ice, which is body-specific but whose - # assets occupy Background Item), then this asset is body-specific. - (body_id? && body_id > 0) || self.zone.type_id < 3 || (@item && @item.explicitly_body_specific?) + self.zone.type_id < 3 || (@item && @item.body_specific?) end def zone