impress/app/controllers/swf_assets_controller.rb
Matchu 9701221035 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.
2013-01-02 23:15:32 -05:00

65 lines
2.5 KiB
Ruby

class SwfAssetsController < ApplicationController
def index
if params[:item_id]
item = Item.find(params[:item_id])
@swf_assets = item.swf_assets
if params[:body_id]
@swf_assets = @swf_assets.fitting_body_id(params[:body_id])
else
if item.special_color
@swf_assets = @swf_assets.fitting_color(item.special_color)
else
@swf_assets = @swf_assets.fitting_standard_body_ids
end
json = @swf_assets.all.group_by(&:body_id)
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).
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
pet_state_id = params[:pet_state_id].to_i
json = @swf_assets.map { |a| a.as_json(:parent_id => pet_state_id, :for => 'wardrobe') }
elsif params[:pet_type_id]
@swf_assets = PetType.find(params[:pet_type_id]).pet_states.emotion_order.first.swf_assets
elsif params[:ids]
@swf_assets = []
if params[:ids][:biology]
@swf_assets += SwfAsset.biology_assets.where(:remote_id => params[:ids][:biology]).all
end
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
@swf_assets.each(&:request_image_conversion!)
json = @swf_assets unless json
else
json = nil
end
render :json => json
end
def show
@swf_asset = SwfAsset.find params[:id]
render :json => @swf_asset
end
end