// patchVerb.js
(function () {
/* global adventurejs A */
var p = adventurejs.Dictionary.prototype;
/**
* <strong>patchVerb</strong> enables an author to revise the properties
* of an existing verb. For example, let's say you want to revise the
* verb "plug" so that it works in the dark - meaning that players
* it can operate on assets the player can't see. You might copy the
* <code>plug.phrase1</code> and in your game file, call patchVerb with
* line <code>visible: true</code> removed. Use game.patchVerb() as a shortcut.
* <pre class="display"><code class="language-javascript">MyGame.patchVerb({
* name: "plug",
* phrase1:{
* accepts_noun: true,
* requires_noun: true,
* accepts_preposition: true,
* noun_must_be:
* {
* known: true,
* tangible: true,
* present: true,
* <span class="strikethrough">visible: true,</span>
* reachable: true,
* },
* },
* });</code></pre>
* @memberOf adventurejs.Dictionary
* @method adventurejs.Dictionary#patchVerb
* @param {Object} patchVerb
* @returns {object}
*/
p.patchVerb = function (patchVerb) {
if ("object" !== typeof patchVerb) {
var msg =
"Dictionary.patchVerb takes an object, but received " +
typeof patchVerb +
": " +
patchVerb;
this.game.log("L1323", "warn", "critical", msg, "dictionary");
return false;
}
if ("undefined" === typeof patchVerb.name) {
var msg =
"Dictionary.patchVerb received an object without a name: " +
JSON.stringify(patchVerb);
this.game.log("L1324", "warn", "critical", msg, "dictionary");
return false;
}
if ("undefined" === typeof this.verbs[patchVerb.name]) {
var msg =
"Dictionary.patchVerb received a verb name that doesn't exist: " +
patchVerb.name;
this.game.log("L1325", "warn", "critical", msg, "Verb");
return false;
}
var verb = this.verbs[patchVerb.name];
// add new synonyms, if any, to verb lookup
// does not allow removal of existing words
if (patchVerb.synonyms) {
this.game.dictionary.verb_lookup[verb.name].synonyms =
this.game.dictionary.verb_lookup[verb.name].synonyms.concat(
patchVerb.synonyms
);
}
verb.set(patchVerb); // copy incoming props to existing verb
verb.initialize();
if (false !== verb) {
this.game.log(
"L1326",
"log",
"medium",
"patchVerb successfully patched verb " + verb.name + ".",
"dictionary"
);
}
return verb;
};
})();