// printNounDisambiguation.js
(function () {
/* global AdventureJS A */
var p = AdventureJS.Parser.prototype;
/**
*
* @memberOf AdventureJS.Parser
* @method AdventureJS.Parser#printNounDisambiguation
* @param {Object} params
* @TODO support for platonics, ie
* which did you mean, a pistachio from the pouch,
* or the one | one that you're carrying?
*/
p.printNounDisambiguation = function Parser_printNounDisambiguation({
parsedNoun,
nounIndex,
container,
preposition,
}) {
this.game.log(
"L1095",
"log",
"high",
`[printNounDisambiguation.js] printNounDisambiguation \n${parsedNoun.matches.qualified}`,
"Parser"
);
const chooseName = function (asset) {
let name = "";
if (asset.stack) {
name = asset.stack.getStackName(true);
} else if (asset.id === this.game.world._player) {
name = this.game.dictionary.inflect("ourself");
} else if (asset.use_proper_name && asset.proper_name) {
name = asset.proper_name;
} else if (asset.use_articles) {
name = asset.article_name;
} else {
name = asset.definite_name;
}
return name;
};
var output_class = "";
// is parsedNoun plural?
// and we need the singular form?
var msg = `Which did {we} mean? `;
// 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++) {
const asset = this.game.getAsset(parsedNoun.matches.qualified[i]);
msg += `<li>${preposition ?? preposition + " "}${chooseName(asset)}</li>`;
}
msg += "</ol>";
}
// present choices in paragraph
else {
for (var i = 0; i < parsedNoun.matches.qualified.length; i++) {
const asset = this.game.getAsset(parsedNoun.matches.qualified[i]);
let name = chooseName(asset);
if (i === parsedNoun.matches.qualified.length - 1) {
msg += "or ";
}
if (this.game.settings.show_disambiguation_as_numbered_paragraph) {
msg += `<span class='ajs-choice'>${i + 1}) </span>`;
}
// if (i === 0) {
// name = A.FX.sentencecase(name);
// }
msg += `${preposition ?? preposition} ${name}`.trim();
if (i < parsedNoun.matches.qualified.length - 1) {
msg += ", ";
}
if (i === parsedNoun.matches.qualified.length - 1) {
msg += "? ";
}
}
}
let newparams = {
["noun" + nounIndex]: true,
index: nounIndex,
};
if (container) newparams.container = true;
// save for next turn disambiguation
this.input_history[0].setDisambiguate(newparams);
if (msg) this.game.print(msg, output_class);
return;
};
})();