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

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

  var p = adventurejs.Parser.prototype;

  /**
   * Exclude from a list of assets all assets that are not global substances.
   * @method adventurejs.Parser#selectGlobalSubstance
   * @memberOf adventurejs.Parser
   * @param {Array} list
   * @returns {Array}
   */
  p.selectGlobalSubstance = function Parser_selectGlobalSubstance(list) {
    if (typeof list !== "object") {
      this.game.log(
        "L1564",
        "error",
        "critical",
        [
          `[selectGlobalSubstance.js] selectGlobalSubstance() received non-array,`,
          list,
        ],
        "Parser"
      );
      return [];
    }
    this.game.log(
      "L1138",
      "log",
      "high",
      `[selectGlobalSubstance.js] selectGlobalSubstance() receive:\n${list}`,
      "Parser"
    );
    var foundObjects = [];
    for (var i = 0; i < list.length; i++) {
      var object = list[i];
      var asset_aspect_substance = object.split(":");
      if (1 < asset_aspect_substance.length) {
        // discard substance-in-tangible
        continue;
      } else {
        object = this.game.getAsset(list[i]);
      }

      if (object instanceof adventurejs.Substance) {
        foundObjects.push(list[i]);
      }
    }

    return foundObjects;
  };
})();