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

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

  var p = adventurejs.Game.prototype;

  /**
   * Find assets that may modify other asset descriptions,
   * such as viewports (like eyeglasses), viewpoints (nests
   * from which things may look different), and light sources
   * such as flashlights and candles.
   * @method adventurejs.Game#findViewModifiers
   * @memberOf adventurejs.Game
   * @returns {Array}
   */
  p.findViewModifiers = function Game_findViewModifiers() {
    this.game.log("L1061", "log", "low", "findViewModifiers.js", "Game");
    let input = this.game.getInput();
    var adverb = input.getAdverb();
    var wornoptics, lightemitters;
    var player = this.game.getPlayer();
    var room = this.game.getCurrentRoom();

    // include adverb
    if (adverb) {
      input.pushViewModifier(adverb, null, "input");
    }

    // include any worn lenses
    wornoptics = player.getWornOptics();
    for (let i = 0; i < wornoptics.length; i++) {
      input.pushViewModifier("through", wornoptics[i], "auto");
    }

    // include anything emitting light
    lightemitters = room.findNestedAssetsWithProperty("is.emitting_light");
    for (let i = 0; i < lightemitters.length; i++) {
      let light = lightemitters[i];
      if (
        light.must.hold_to_see_with &&
        !this.game.parser.selectInHands(light.id).length
      ) {
        continue;
      }
      if (
        light.must.wear_to_see_with &&
        !this.game.parser.selectInHands(light.id).length
      ) {
        continue;
      }
      input.pushViewModifier("with", lightemitters[i], "auto");
    }

    // include player nest
    if (player.isNested()) {
      input.pushViewModifier("from", player.getNestAsset(), "auto");
    }

    // include current room
    input.pushViewModifier("in", this.game.getCurrentRoom(), "auto");

    return input.view_modifiers;
  };
})();