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

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

  var p = AdventureJS.Parser.prototype;

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

      // don't return substance containers?
      // considered this while working on tie
      // if (list[i].includes(":") && list[i].split(":")[0] === "substance") continue;

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

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

    return foundObjects;
  };
})();