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
|
||||
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]
|
||||
|
|
|
@ -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
|
||||
body_ids = swf_assets.select([:body_id]).map(&:body_id)
|
||||
return Species.all if body_ids.include?(0)
|
||||
|
||||
def support_species?(species)
|
||||
species_support_ids.blank? || species_support_ids.include?(species.id)
|
||||
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)
|
||||
|
@ -231,6 +232,12 @@ class Item < ActiveRecord::Base
|
|||
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
|
||||
self.species_support_ids = info[:species_support].map(&:to_i)
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue