attempt to fix new species_support_ids format. sigh.
This commit is contained in:
parent
df5c7fe3d4
commit
bfd825d98e
4 changed files with 26 additions and 16 deletions
|
@ -15,13 +15,10 @@ class SwfAssetsController < ApplicationController
|
||||||
end
|
end
|
||||||
elsif params[:pet_type_id] && params[:item_ids]
|
elsif params[:pet_type_id] && params[:item_ids]
|
||||||
pet_type = PetType.find(params[:pet_type_id], :select => [:body_id, :species_id])
|
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.
|
@swf_assets = SwfAsset.object_assets.
|
||||||
fitting_body_id(pet_type.body_id).
|
fitting_body_id(pet_type.body_id).
|
||||||
for_item_ids(compatible_item_ids).
|
for_item_ids(params[:item_ids]).
|
||||||
with_parent_ids
|
with_parent_ids
|
||||||
json = @swf_assets.map { |a| a.as_json(:parent_id => a.parent_id.to_i, :for => 'wardrobe') }
|
json = @swf_assets.map { |a| a.as_json(:parent_id => a.parent_id.to_i, :for => 'wardrobe') }
|
||||||
elsif params[:pet_state_id]
|
elsif params[:pet_state_id]
|
||||||
|
|
|
@ -146,11 +146,12 @@ class Item < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
|
|
||||||
def supported_species
|
def supported_species
|
||||||
@supported_species ||= species_support_ids.blank? ? Species.all : species_support_ids.sort.map { |id| Species.find(id) }
|
body_ids = swf_assets.select([:body_id]).map(&:body_id)
|
||||||
end
|
return Species.all if body_ids.include?(0)
|
||||||
|
|
||||||
def support_species?(species)
|
pet_types = PetType.where(:body_id => body_ids).select([:species_id])
|
||||||
species_support_ids.blank? || species_support_ids.include?(species.id)
|
species_ids = pet_types.map(&:species_id).uniq
|
||||||
|
Species.find(species_ids)
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.search(query, user=nil)
|
def self.search(query, user=nil)
|
||||||
|
@ -231,6 +232,12 @@ class Item < ActiveRecord::Base
|
||||||
end
|
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)
|
def origin_registry_info=(info)
|
||||||
# bear in mind that numbers from registries are floats
|
# bear in mind that numbers from registries are floats
|
||||||
self.species_support_ids = info[:species_support].map(&:to_i)
|
self.species_support_ids = info[:species_support].map(&:to_i)
|
||||||
|
|
|
@ -5,11 +5,21 @@ class StaticResource
|
||||||
@objects
|
@objects
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.find(id)
|
def self.find(id_or_ids)
|
||||||
@objects[id-1]
|
if id_or_ids.is_a?(Array)
|
||||||
|
id_or_ids.uniq.map { |id| find_one(id) }
|
||||||
|
else
|
||||||
|
find_one(id_or_ids)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.count
|
def self.count
|
||||||
@objects.size
|
@objects.size
|
||||||
end
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def self.find_one(id)
|
||||||
|
@objects[id - 1]
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -197,11 +197,7 @@ class SwfAsset < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
|
|
||||||
def body_specific?
|
def body_specific?
|
||||||
# If we already have assigned this a non-zero body id, or if the asset is
|
self.zone.type_id < 3 || (@item && @item.body_specific?)
|
||||||
# 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?)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def zone
|
def zone
|
||||||
|
|
Loading…
Reference in a new issue