show biology assets on item preview from pet state
This commit is contained in:
parent
7fc59745e5
commit
4604a412fd
2 changed files with 60 additions and 14 deletions
|
@ -3,7 +3,7 @@ class SwfAssetsController < ApplicationController
|
|||
if params[:item_id]
|
||||
@swf_assets = Item.find(params[:item_id]).swf_assets.for_json.all
|
||||
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
|
||||
render :json => @swf_assets
|
||||
end
|
||||
|
|
|
@ -1,7 +1,14 @@
|
|||
var PREVIEW_SWF_ID = 'item-preview-swf',
|
||||
PREVIEW_SWF = document.getElementById(PREVIEW_SWF_ID),
|
||||
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) {
|
||||
return 'http://' + IMPRESS_HOST + path;
|
||||
|
@ -10,9 +17,15 @@ function impressUrl(path) {
|
|||
function PetType() {}
|
||||
|
||||
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) {
|
||||
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;
|
||||
}
|
||||
|
||||
swfobject.embedSWF(
|
||||
Preview = new function Preview() {
|
||||
var assets = [], swf_id, swf, updateWhenFlashReady = false;
|
||||
|
||||
this.setFlashIsReady = function () {
|
||||
log('flash ready');
|
||||
swf = document.getElementById(swf_id);
|
||||
if(updateWhenFlashReady) this.update();
|
||||
}
|
||||
|
||||
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
|
||||
PREVIEW_SWF_ID, // ID
|
||||
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();
|
||||
|
||||
|
@ -48,3 +92,5 @@ speciesList.click(function (e) {
|
|||
e.preventDefault();
|
||||
PetType.create_from_link($(this)).setAsCurrent();
|
||||
});
|
||||
|
||||
MainWardrobe = { View: { Outfit: Preview } };
|
||||
|
|
Loading…
Reference in a new issue