// patchVerb.js
(function () {
/* global adventurejs A */
var p = adventurejs.Dictionary.prototype;
/**
* A method to allow authors to revise predefined verbs.
* @memberOf adventurejs.Dictionary
* @method adventurejs.Dictionary#patchVerb
* @param {Object} patchVerb
*/
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, "warning");
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;
};
})();