start by caching data for preview, remove aggressive preloading for the moment
This commit is contained in:
parent
40bb495a2b
commit
45f1ee868e
1 changed files with 63 additions and 34 deletions
|
@ -40,9 +40,10 @@ function LoadError(base_msg) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function PetType() {
|
function PetType() {
|
||||||
var pet_type = this;
|
var pet_type = this, loaded_data = false, loaded_assets = false;
|
||||||
|
|
||||||
this.activated = true;
|
this.activated = true;
|
||||||
|
this.assets = true;
|
||||||
|
|
||||||
this.deactivate = function (error, args) {
|
this.deactivate = function (error, args) {
|
||||||
var msg;
|
var msg;
|
||||||
|
@ -60,22 +61,24 @@ function PetType() {
|
||||||
this.load = function () {
|
this.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;
|
pet_type = this;
|
||||||
$.ajax({
|
function onComplete() { Item.current.load(pet_type); loadAssets(); }
|
||||||
url: url,
|
if(loaded_data) {
|
||||||
dataType: 'json',
|
onComplete();
|
||||||
success: function (data) {
|
} else {
|
||||||
pet_type.id = data.id;
|
$.ajax({
|
||||||
pet_type.body_id = data.body_id;
|
url: url,
|
||||||
Item.current.load(pet_type);
|
dataType: 'json',
|
||||||
$.getJSON('/pet_types/' + data.id + '/swf_assets.json', function (assets) {
|
success: function (data) {
|
||||||
pet_type.assets = assets;
|
pet_type.id = data.id;
|
||||||
Preview.update();
|
pet_type.body_id = data.body_id;
|
||||||
});
|
loaded_data = true;
|
||||||
},
|
onComplete();
|
||||||
error: function () {
|
},
|
||||||
pet_type.deactivate(PetType.LOAD_ERROR);
|
error: function () {
|
||||||
}
|
pet_type.deactivate(PetType.LOAD_ERROR);
|
||||||
});
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this.setAsCurrent = function () {
|
this.setAsCurrent = function () {
|
||||||
|
@ -90,6 +93,18 @@ function PetType() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function loadAssets() {
|
||||||
|
function onComplete() { if(pet_type == PetType.current) Preview.update(); }
|
||||||
|
if(!loaded_assets) {
|
||||||
|
$.getJSON('/pet_types/' + pet_type.id + '/swf_assets.json', function (assets) {
|
||||||
|
pet_type.assets = assets;
|
||||||
|
loaded_assets = true;
|
||||||
|
onComplete();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
onComplete();
|
||||||
|
}
|
||||||
|
|
||||||
function showDeactivationMsg() {
|
function showDeactivationMsg() {
|
||||||
Preview.disable(pet_type.deactivation_msg);
|
Preview.disable(pet_type.deactivation_msg);
|
||||||
}
|
}
|
||||||
|
@ -111,19 +126,30 @@ PetType.createFromLink = function (link) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function Item() {
|
function Item() {
|
||||||
|
this.assets_by_body_id = {};
|
||||||
|
|
||||||
this.load = function (pet_type) {
|
this.load = function (pet_type) {
|
||||||
var url = '/' + this.id + '/swf_assets.json?body_id=' + pet_type.body_id,
|
var url = '/' + this.id + '/swf_assets.json?body_id=' + pet_type.body_id,
|
||||||
item = this;
|
item = this;
|
||||||
$.getJSON(url, function (data) {
|
function onComplete() { if(pet_type == PetType.current) Preview.update() }
|
||||||
if(data.length) {
|
if(this.getAssetsForPetType(pet_type).length) {
|
||||||
item.assets = data;
|
onComplete();
|
||||||
Preview.update();
|
} else {
|
||||||
} else {
|
$.getJSON(url, function (data) {
|
||||||
pet_type.deactivate(Item.LOAD_ERROR, {
|
if(data.length) {
|
||||||
item: item.name
|
item.assets_by_body_id[pet_type.body_id] = data;
|
||||||
});
|
onComplete();
|
||||||
}
|
} else {
|
||||||
})
|
pet_type.deactivate(Item.LOAD_ERROR, {
|
||||||
|
item: item.name
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
this.getAssetsForPetType = function (pet_type) {
|
||||||
|
return this.assets_by_body_id[pet_type.body_id] || [];
|
||||||
}
|
}
|
||||||
|
|
||||||
this.setAsCurrent = function () {
|
this.setAsCurrent = function () {
|
||||||
|
@ -140,7 +166,7 @@ Item.createFromLocation = function () {
|
||||||
}
|
}
|
||||||
|
|
||||||
Preview = new function Preview() {
|
Preview = new function Preview() {
|
||||||
var assets = [], swf_id, swf, updateWhenFlashReady = false;
|
var swf_id, swf, updateWhenFlashReady = false;
|
||||||
|
|
||||||
this.setFlashIsReady = function () {
|
this.setFlashIsReady = function () {
|
||||||
swf = document.getElementById(swf_id);
|
swf = document.getElementById(swf_id);
|
||||||
|
@ -148,12 +174,15 @@ Preview = new function Preview() {
|
||||||
}
|
}
|
||||||
|
|
||||||
this.update = function (assets) {
|
this.update = function (assets) {
|
||||||
var assets = [];
|
var assets = [], asset_sources = [
|
||||||
|
PetType.current.assets,
|
||||||
|
Item.current.getAssetsForPetType(PetType.current)
|
||||||
|
];
|
||||||
if(swf) {
|
if(swf) {
|
||||||
$.each([PetType, Item], function () {
|
$.each(asset_sources, function () {
|
||||||
if(this.current.assets) assets = assets.concat(this.current.assets);
|
assets = assets.concat(this);
|
||||||
});
|
});
|
||||||
assets = $.each(assets, function () {
|
$.each(assets, function () {
|
||||||
this.local_path = this.local_url;
|
this.local_path = this.local_url;
|
||||||
});
|
});
|
||||||
swf.setAssets(assets);
|
swf.setAssets(assets);
|
||||||
|
@ -204,8 +233,8 @@ speciesList.each(function () {
|
||||||
|
|
||||||
MainWardrobe = { View: { Outfit: Preview } };
|
MainWardrobe = { View: { Outfit: Preview } };
|
||||||
|
|
||||||
setTimeout(function () {
|
/*setTimeout(function () {
|
||||||
$.each(PetType.all, function () {
|
$.each(PetType.all, function () {
|
||||||
this.load();
|
this.load();
|
||||||
});
|
});
|
||||||
}, 5000);
|
}, 5000);*/
|
||||||
|
|
Loading…
Reference in a new issue