Pre-release
Adventure.js Docs Downloads
Score: 0 Moves: 0
// selectKnown.js

(function () {
  /*global adventurejs A*/
  "use strict";

  var p = adventurejs.Parser.prototype;

  /**
   * Exclude from a list of assets all assets that are unknown by player.
   * @method adventurejs.Parser#selectKnown
   * @memberOf adventurejs.Parser
   * @param {Array} list
   * @returns {Array}
   */
  p.selectKnown = function Parser_selectKnown(list) {
    if ("string" === typeof list) list = [list];
    if (!Array.isArray(list)) {
      this.game.log(
        "warn",
        "critical",
        "selectKnown.js > received non-array",
        "Parser"
      );
      return [];
    }
    var foundObjects = [];
    for (var i = 0; i < list.length; i++) {
      var object;
      object = this.game.getAsset(list[i]);

      //console.warn( "selectKnown examining " + list[i] );
      // is it a substance in a container we haven't examined?
      var sub = list[i].split(":"); // asset:aspect:substance
      if (3 === sub.length) {
        console.warn("sub", sub);
        var known = this.game.getAsset(sub[0]).aspects[sub[1]].vessel
          .vessel_is_known;
        if (!known) {
          continue;
        }
      }

      if (object instanceof adventurejs.Substance) {
        //var container = this.game.getAsset( list[i] );
        if (!object.is.known) {
          continue;
        }
      }

      /**
       * Objects become known once they're "seen" by player.
       * Omit unknown object, but also omit if any of its
       * anscestors are unknown. It's possible for a known
       * object to be inside an unknown object, but this state
       * is unlikely to happen by accident, so we'll take unknown
       * anscestors to mean the object was deliberately hidden.
       */
      if (!object.is.known) {
        continue;
      }
      if (object.areAnscestorsUnknown && object.areAnscestorsUnknown()) {
        continue;
      }
      foundObjects.push(list[i]);
    }

    //console.log( "selectKnown returned " + foundObjects );
    return foundObjects;
  };
})();