Pre-release
AdventureJS Docs Downloads Devlog
Score: 0 Moves: 0
// renderPronoun.js
(function () {
  /* global AdventureJS A */

  var p = AdventureJS.Game.prototype;

  /**
   * This always uses the subject's pronouns.
   * @method AdventureJS.Game#renderPronoun
   * @memberOf AdventureJS.Game
   * @param {string} token The original template such as {our}.
   * @param {string} pronouns An optional pronoun type. If none provided, assumes subject.
   * @returns string;
   */
  p.renderPronoun = function Game_renderPronoun(token, pronouns, asset) {
    let pronoun = token;
    const input = this.game.getInput();
    const player = this.game.getPlayer();
    const subject = input.getSubject();

    if (asset)
      if (pronouns) {
        return this.game.dictionary.inflections[pronouns][pronoun];
      }

    let subject_not_player, token_is_subject;

    if (subject && subject.id !== player.id) {
      subject_not_player = true;
      // does the token resolve to the subject's name?
      if (
        "undefined" !== typeof this.game.world_lookup[token] &&
        this.game.world_lookup[token].IDs.includes(subject.id)
      ) {
        token_is_subject = true;
      }
    }

    if (subject_not_player && (token_is_subject || token === "we")) {
      pronoun = subject.proper_name || subject.Name;
    } else {
      pronoun = this.game.dictionary.inflections[subject.pronouns][pronoun];
    }
    return pronoun;
  }; // renderPronoun
})();