forked from OpenNeo/impress
wardrobe now considers item.species_support_ids when deciding compatibility
For example, the Meerca Maid Tray is a foreground item, so the SWF is marked as compatible with all body types, but the item itself is clearly marked as Meercas-only. items#show reflected this properly, but the swf_assets#index call that the wardrobe uses ignored item.species_support_ids. So, /bodies/:body_id/swf_assets.json?item_ids[]=... was deprecated in favor of /pet_types/:pet_type_id/items/swf_assets.json?item_ids=[]..., which is much like the former route but, before loading assets, also loads the pet type and items, then filters the items by compatibility, then only loads assets for the compatible items.
This commit is contained in:
parent
86b58a0a35
commit
9701221035
5 changed files with 28 additions and 6 deletions
|
@ -13,12 +13,16 @@ class SwfAssetsController < ApplicationController
|
|||
end
|
||||
json = @swf_assets.all.group_by(&:body_id)
|
||||
end
|
||||
elsif params[:body_id] && params[:item_ids]
|
||||
swf_assets = SwfAsset.arel_table
|
||||
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.
|
||||
select('swf_assets.*, parents_swf_assets.parent_id').
|
||||
fitting_body_id(params[:body_id]).
|
||||
for_item_ids(params[:item_ids])
|
||||
fitting_body_id(pet_type.body_id).
|
||||
for_item_ids(compatible_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]
|
||||
@swf_assets = PetState.find(params[:pet_state_id]).swf_assets.all
|
||||
|
@ -34,6 +38,14 @@ class SwfAssetsController < ApplicationController
|
|||
if params[:ids][:object]
|
||||
@swf_assets += SwfAsset.object_assets.where(:remote_id => params[:ids][:object]).all
|
||||
end
|
||||
elsif params[:body_id] && params[:item_ids]
|
||||
# DEPRECATED in favor of pet_type_id and item_ids
|
||||
swf_assets = SwfAsset.arel_table
|
||||
@swf_assets = SwfAsset.object_assets.
|
||||
select('swf_assets.*, parents_swf_assets.parent_id').
|
||||
fitting_body_id(params[:body_id]).
|
||||
for_item_ids(params[:item_ids])
|
||||
json = @swf_assets.map { |a| a.as_json(:parent_id => a.parent_id.to_i, :for => 'wardrobe') }
|
||||
end
|
||||
if @swf_assets
|
||||
@swf_assets = @swf_assets.all unless @swf_assets.is_a? Array
|
||||
|
|
|
@ -148,6 +148,10 @@ class Item < ActiveRecord::Base
|
|||
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)
|
||||
end
|
||||
|
||||
def self.search(query, user=nil)
|
||||
raise SearchError, "Please provide a search query" unless query
|
||||
|
|
|
@ -167,6 +167,9 @@ class SwfAsset < ActiveRecord::Base
|
|||
joins(:parent_swf_asset_relationships).
|
||||
where(ParentSwfAssetRelationship.arel_table[:parent_id].in(item_ids))
|
||||
}
|
||||
scope :with_parent_ids, lambda {
|
||||
select('swf_assets.*, parents_swf_assets.parent_id')
|
||||
}
|
||||
|
||||
def local_url
|
||||
'/' + File.join(PUBLIC_ASSET_DIR, local_path_within_outfit_swfs)
|
||||
|
|
|
@ -11,10 +11,13 @@ OpenneoImpressItems::Application.routes.draw do |map|
|
|||
|
||||
match '/item_zone_sets.json' => 'ItemZoneSets#index'
|
||||
|
||||
# DEPRECATED
|
||||
match '/bodies/:body_id/swf_assets.json' => 'swf_assets#index', :as => :body_swf_assets
|
||||
|
||||
match '/items/:item_id/swf_assets.json' => 'swf_assets#index', :as => :item_swf_assets
|
||||
match '/items/:item_id/bodies/:body_id/swf_assets.json' => 'swf_assets#index', :as => :item_swf_assets_for_body_id
|
||||
match '/pet_types/:pet_type_id/swf_assets.json' => 'swf_assets#index', :as => :pet_type_swf_assets
|
||||
match '/pet_types/:pet_type_id/items/swf_assets.json' => 'swf_assets#index', :as => :item_swf_assets_for_pet_type
|
||||
match '/pet_states/:pet_state_id/swf_assets.json' => 'swf_assets#index', :as => :pet_state_swf_assets
|
||||
match '/species/:species_id/color/:color_id/pet_type.json' => 'pet_types#show'
|
||||
|
||||
|
|
|
@ -742,7 +742,7 @@ function Wardrobe() {
|
|||
if(!item.hasAssetsFitting(pet_type)) item_ids_needed.push(id);
|
||||
}
|
||||
if(item_ids_needed.length) {
|
||||
$.getJSON('/bodies/' + pet_type.body_id + '/swf_assets.json', {
|
||||
$.getJSON('/pet_types/' + pet_type.id + '/items/swf_assets.json', {
|
||||
item_ids: item_ids_needed
|
||||
}, function (data) {
|
||||
var item;
|
||||
|
|
Loading…
Reference in a new issue