2010-05-16 12:01:38 -07:00
|
|
|
class SwfAssetsController < ApplicationController
|
|
|
|
def index
|
2010-05-20 16:56:08 -07:00
|
|
|
if params[:item_id]
|
2011-05-02 15:07:56 -07:00
|
|
|
item = Item.find(params[:item_id])
|
|
|
|
@swf_assets = item.swf_assets
|
2010-05-20 18:30:12 -07:00
|
|
|
if params[:body_id]
|
|
|
|
@swf_assets = @swf_assets.fitting_body_id(params[:body_id])
|
2010-06-08 15:26:42 -07:00
|
|
|
else
|
2011-05-02 15:07:56 -07:00
|
|
|
if item.special_color
|
|
|
|
@swf_assets = @swf_assets.fitting_color(item.special_color)
|
|
|
|
else
|
|
|
|
@swf_assets = @swf_assets.fitting_standard_body_ids
|
|
|
|
end
|
2010-06-09 19:56:47 -07:00
|
|
|
json = @swf_assets.all.group_by(&:body_id)
|
2010-05-20 18:30:12 -07:00
|
|
|
end
|
2010-11-15 13:04:54 -08:00
|
|
|
elsif params[:body_id] && params[:item_ids]
|
2010-10-10 19:18:42 -07:00
|
|
|
swf_assets = SwfAsset.arel_table
|
2010-11-25 18:33:34 -08:00
|
|
|
@swf_assets = SwfAsset.object_assets.
|
|
|
|
select('swf_assets.*, parents_swf_assets.parent_id').
|
2010-10-10 19:18:42 -07:00
|
|
|
fitting_body_id(params[:body_id]).
|
2010-11-25 18:33:34 -08:00
|
|
|
for_item_ids(params[:item_ids])
|
2010-10-10 19:18:42 -07:00
|
|
|
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') }
|
2010-05-20 16:56:08 -07:00
|
|
|
elsif params[:pet_type_id]
|
2011-02-22 15:11:12 -08:00
|
|
|
@swf_assets = PetType.find(params[:pet_type_id]).pet_states.emotion_order.first.swf_assets
|
2011-05-22 13:30:02 -07:00
|
|
|
elsif params[:ids]
|
|
|
|
@swf_assets = []
|
|
|
|
if params[:ids][:biology]
|
|
|
|
@swf_assets += SwfAsset.biology_assets.where(:id => params[:ids][:biology]).all
|
|
|
|
end
|
|
|
|
if params[:ids][:object]
|
|
|
|
@swf_assets += SwfAsset.object_assets.where(:id => params[:ids][:object]).all
|
|
|
|
end
|
|
|
|
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
|
2010-05-20 16:56:08 -07:00
|
|
|
end
|
2010-06-07 13:33:43 -07:00
|
|
|
render :json => json
|
2010-05-16 12:01:38 -07:00
|
|
|
end
|
2011-05-20 16:19:14 -07:00
|
|
|
|
|
|
|
def show
|
|
|
|
@swf_asset = SwfAsset.find params[:id]
|
|
|
|
render :json => @swf_asset
|
|
|
|
end
|
2010-05-16 12:01:38 -07:00
|
|
|
end
|
2011-05-02 15:07:56 -07:00
|
|
|
|