Pre-release
AdventureJS Docs Downloads
Score: 0 Moves: 0
// destroyAsset.js
(function () {
  /* global adventurejs A */
  var p = adventurejs.Game.prototype;
  /**
   * <strong>destroyAsset()</strong> removes an asset from the game world.
   * @method adventurejs.Game#destroyAsset
   * @memberOf adventurejs.Game
   * @param {Object} asset The asset to be removed.
   */
  p.destroyAsset = p.destroy = function Game_destroyAsset(
    asset,
    deleet = false
  ) {
    if ("string" === typeof asset) asset = this.game.getAsset(asset);
    if (!asset) return false;
    let results;

    // clear intervals
    if ("undefined" === typeof this.game.world._intervals[asset.id]) {
      delete this.world._intervals[asset.id];
    }

    if (asset.destroy) {
      results = asset.destroy();
      if ("undefined" !== typeof results) return results;
    }
    asset.is.destroyed = true;
    asset.is.extant = false;

    // remove from place
    // if (asset.setPlace) asset.setPlace();

    // remove from lookup? add destroyed flag?

    // if it's fungible then delete it regardless
    if (deleet || asset.is.fungible) {
      this.game.removeAssetFromLookup(asset);
      delete this.game.world[asset.id];
      asset = null;
    }

    return true;
  };
})();