// removeAssetFromLookup.js
(function () {
/* global AdventureJS A */
var p = AdventureJS.Game.prototype;
/**
* <strong>removeAssetFromLookup()</strong> removes all
* references to an asset's ID from game.world_lookup.
* @method AdventureJS.Game#removeAssetFromLookup
* @memberOf AdventureJS.Game
* @param {Object} asset The asset to be removed.
*/
p.removeAssetFromLookup = function Game_removeAssetFromWorld(asset) {
if ("string" === typeof asset) asset = this.game.getAsset(asset);
if (!asset) return false;
// remove the primary reference
delete this.game.world_lookup[asset.id];
// remove references under other keywords
for (let prop in this.game.world_lookup) {
const index = this.game.world_lookup[prop].IDs.indexOf(asset.id);
if (index > -1) {
this.game.world_lookup[prop].IDs.splice(index, 1);
}
}
// references stored in this.world._fungibles?
if (asset.is.dispensed) {
if (this.world._fungibles.includes(asset.id)) {
this.world._fungibles.splice(
this.world._fungibles.indexOf(asset.id),
1
);
}
}
return true;
};
})();