show biology assets on item preview from pet state

This commit is contained in:
Emi Matchu 2010-05-20 21:16:35 -04:00
parent 7fc59745e5
commit 4604a412fd
2 changed files with 60 additions and 14 deletions

View file

@ -3,7 +3,7 @@ class SwfAssetsController < ApplicationController
if params[:item_id] if params[:item_id]
@swf_assets = Item.find(params[:item_id]).swf_assets.for_json.all @swf_assets = Item.find(params[:item_id]).swf_assets.for_json.all
elsif params[:pet_type_id] elsif params[:pet_type_id]
@swf_assets = PetType.find(params[:pet_type_id]).swf_assets.for_json.all @swf_assets = PetType.find(params[:pet_type_id]).pet_states.first.swf_assets.for_json.all
end end
render :json => @swf_assets render :json => @swf_assets
end end

View file

@ -1,7 +1,14 @@
var PREVIEW_SWF_ID = 'item-preview-swf', var PREVIEW_SWF_ID = 'item-preview-swf',
PREVIEW_SWF = document.getElementById(PREVIEW_SWF_ID), PREVIEW_SWF = document.getElementById(PREVIEW_SWF_ID),
IMPRESS_HOST = PREVIEW_SWF.getAttribute('data-impress-host'), IMPRESS_HOST = PREVIEW_SWF.getAttribute('data-impress-host'),
speciesList = $('#item-preview a'); speciesList = $('#item-preview a'),
MainWardrobe;
if(console === undefined || console.log === undefined) {
function log() {}
} else {
log = $.proxy(console, 'log');
}
function impressUrl(path) { function impressUrl(path) {
return 'http://' + IMPRESS_HOST + path; return 'http://' + IMPRESS_HOST + path;
@ -10,9 +17,15 @@ function impressUrl(path) {
function PetType() {} function PetType() {}
PetType.prototype.load = function () { PetType.prototype.load = function () {
var url = '/species/' + this.species_id + '/color/' + this.color_id + '/pet_type.json'; var url = '/species/' + this.species_id + '/color/' + this.color_id + '/pet_type.json',
pet_type = this;
$.getJSON(url, function (data) { $.getJSON(url, function (data) {
console.log(data); pet_type.id = data.id;
pet_type.body_id = data.body_id;
$.getJSON('/pet_types/' + data.id + '/swf_assets.json', function (assets) {
pet_type.assets = assets;
Preview.update();
});
}); });
} }
@ -31,16 +44,47 @@ PetType.create_from_link = function (link) {
return pet_type; return pet_type;
} }
swfobject.embedSWF( Preview = new function Preview() {
impressUrl('/assets/swf/preview.swf'), // URL var assets = [], swf_id, swf, updateWhenFlashReady = false;
PREVIEW_SWF_ID, // ID
400, // width this.setFlashIsReady = function () {
400, // height log('flash ready');
'9', // required version swf = document.getElementById(swf_id);
impressUrl('/assets/js/swfobject/expressInstall.swf'), // express install URL if(updateWhenFlashReady) this.update();
{'swf_assets_path': impressUrl('/assets')}, // flashvars }
{'wmode': 'transparent', 'allowscriptaccess': 'always'} // params
) this.update = function (assets) {
var assets;
log('want to update');
if(swf) {
log('got to update');
log(PetType.current.assets);
assets = $.each(PetType.current.assets, function () {
this.local_path = this.local_url;
});
log(assets);
swf.setAssets(assets);
} else {
updateWhenFlashReady = true;
}
}
this.embed = function (id) {
swf_id = id;
swfobject.embedSWF(
impressUrl('/assets/swf/preview.swf'), // URL
id, // ID
400, // width
400, // height
'9', // required version
impressUrl('/assets/js/swfobject/expressInstall.swf'), // express install URL
{'swf_assets_path': impressUrl('/assets')}, // flashvars
{'wmode': 'transparent', 'allowscriptaccess': 'always'} // params
);
}
}
Preview.embed(PREVIEW_SWF_ID);
PetType.create_from_link(speciesList.eq(Math.floor(Math.random()*speciesList.length))).setAsCurrent(); PetType.create_from_link(speciesList.eq(Math.floor(Math.random()*speciesList.length))).setAsCurrent();
@ -48,3 +92,5 @@ speciesList.click(function (e) {
e.preventDefault(); e.preventDefault();
PetType.create_from_link($(this)).setAsCurrent(); PetType.create_from_link($(this)).setAsCurrent();
}); });
MainWardrobe = { View: { Outfit: Preview } };