preloading accounts for body ID 0

This commit is contained in:
Emi Matchu 2010-06-08 10:58:13 -04:00
parent 7b91dd9cef
commit ecda2ae34e

View file

@ -58,6 +58,12 @@ function PetType() {
img.src = img.src.replace('/1/', '/2/'); img.src = img.src.replace('/1/', '/2/');
} }
this.deactivateWithItem = function (item) {
pet_type.deactivate(Item.LOAD_ERROR, {
item: item.name
});
}
this.load = function () { this.load = function () {
Item.current.load(this); Item.current.load(this);
loadAssets(); loadAssets();
@ -100,9 +106,13 @@ PetType.all = [];
PetType.all.load = function () { PetType.all.load = function () {
var body_ids = $.map(PetType.all, function (pt) { return pt.body_id }); var body_ids = $.map(PetType.all, function (pt) { return pt.body_id });
$.getJSON(Item.current.assets_url_base, {body_id: body_ids}, function (assets_by_body_id) { $.getJSON(Item.current.assets_url_base, {body_id: body_ids}, function (assets_by_body_id) {
$.each(assets_by_body_id, function (i) {
Item.current.assets_by_body_id[parseInt(i)] = this;
});
$.each(PetType.all, function () { $.each(PetType.all, function () {
var assets = assets_by_body_id[this.body_id] || []; if(Item.current.getAssetsForPetType(this).length == 0) {
Item.current.setAssetsForPetType(assets, this); this.deactivateWithItem(Item.current);
}
}); });
}); });
} }
@ -139,7 +149,7 @@ function Item(id) {
} }
this.getAssetsForPetType = function (pet_type) { this.getAssetsForPetType = function (pet_type) {
return this.assets_by_body_id[pet_type.body_id] || []; return this.assets_by_body_id[pet_type.body_id] || this.assets_by_body_id[0] || [];
} }
this.setAsCurrent = function () { this.setAsCurrent = function () {
@ -151,9 +161,7 @@ function Item(id) {
this.assets_by_body_id[pet_type.body_id] = assets; this.assets_by_body_id[pet_type.body_id] = assets;
pet_type.onUpdate(); pet_type.onUpdate();
} else { } else {
pet_type.deactivate(Item.LOAD_ERROR, { pet_type.deactivateWithItem(this);
item: this.name
});
} }
} }
} }