Pre-release
AdventureJS Docs Downloads
Score: 0 Moves: 0
// selectTangible.js

(function () {
  /* global AdventureJS A */

  var p = AdventureJS.Parser.prototype;

  /**
   * Exclude from a list of assets all non-tangible assets.
   * @method AdventureJS.Parser#selectTangible
   * @memberOf AdventureJS.Parser
   * @param {Array} list
   * @returns {Array}
   */
  p.selectTangible = function Parser_selectTangible(list) {
    if ("string" === typeof list) list = [list];
    if (!Array.isArray(list)) {
      this.game.log(
        "L1251",
        "error",
        "critical",
        ["[selectTangible.js] selectTangible() received non-array", list],
        "Parser"
      );
      return [];
    }
    this.game.log(
      "L1132",
      "log",
      "high",
      `[selectTangible.js] selectTangible() receive:\n${list}`,
      "Parser"
    );
    var foundObjects = [];
    for (var i = 0; i < list.length; i++) {
      var object = this.game.getAsset(list[i]);

      if (
        object instanceof AdventureJS.Assets.Tangible ||
        // || object instanceof AdventureJS.Assets.Substance
        object instanceof AdventureJS.Assets.Room ||
        object instanceof AdventureJS.Assets.Exit ||
        //|| object instanceof AdventureJS.Assets.Floor
        //|| object instanceof AdventureJS.Assets.Ceiling
        object instanceof AdventureJS.Assets.Scenery ||
        object instanceof AdventureJS.AssetHelpers.Platonic ||
        object.is.global /*&& !object.is.abstract @todo handle abstractions */
      ) {
        foundObjects.push(list[i]);
        continue;
      }
    }

    this.game.log(
      "L1680",
      "log",
      "high",
      `[selectTangible.js] selectTangible() return:\n${foundObjects}`,
      "Parser"
    );

    return foundObjects;
  };
})();