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

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

  var p = adventurejs.Parser.prototype;

  /**
   *
   * @memberOf adventurejs.Parser
   * @method adventurejs.Parser#printNounDisambiguation
   * @param {Object} params
   */
  p.printNounDisambiguation = function Parser_printNounDisambiguation(params) {
    var parsedNoun = params.parsedNoun;
    var nounIndex = params.nounIndex;
    var output_class = "";
    var definite_names = [];
    var names = [];
    //console.warn( "parsedNoun",parsedNoun );

    // is parsedNoun plural?
    // and we need the singular form?

    var msg = "Which did $(we) mean? ";
    //+ parsedNoun.deserialized_input
    //+ ("undefined" !== typeof parsedNoun.singular ? parsedNoun.singular : "")

    // present choices in ordered list
    if (this.game.settings.show_disambiguation_as_ordered_list) {
      msg += "<ol>";
      for (var i = 0; i < parsedNoun.matches.qualified.length; i++) {
        msg += "<li>";
        msg +=
          " the " + this.game.getAsset(parsedNoun.matches.qualified[i]).name;
        msg += "</li>";
      }
      msg += "</ol>";
    }
    // present choices in paragraph
    else {
      for (var i = 0; i < parsedNoun.matches.qualified.length; i++) {
        var asset = this.game.getAsset(parsedNoun.matches.qualified[i]);
        var name = asset.name;
        var definite_name = asset.definite_name;

        if (i === parsedNoun.matches.qualified.length - 1) {
          msg += "or ";
        }

        if (this.game.settings.show_disambiguation_as_numbered_paragraph) {
          msg += `<span class='choice'>${i + 1}) </span>`;
        }

        names.push(name);
        definite_names.push(definite_name);

        if (i === 0) {
          definite_name = A.propercase(definite_name);
        }
        msg += definite_name;

        if (i < parsedNoun.matches.qualified.length - 1) {
          msg += ", ";
        }

        if (i === parsedNoun.matches.qualified.length - 1) {
          msg += "? ";
        }
      }
    }

    // save for next turn disambiguation
    this.input_history[0].setDisambiguate({
      ["noun" + nounIndex]: true,
      index: nounIndex,
      //names: names,
      //definite_names: definite_names,
    });

    if (msg) this.game.print(msg, output_class);
    return;
  };
})();