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

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

  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 =
        "patchVerb takes an object, but received " +
        typeof patchVerb +
        ": " +
        patchVerb;
      this.game.log("warn", "critical", msg, "dictionary");
      return false;
    }
    if ("undefined" === typeof patchVerb.name) {
      var msg =
        "patchVerb received an object without a name: " +
        JSON.stringify(patchVerb);
      this.game.log("warn", "critical", msg, "dictionary");
      return false;
    }
    if ("undefined" === typeof this.verbs[patchVerb.name]) {
      var msg =
        "patchVerb received a verb name that doesn't exist: " + patchVerb.name;
      this.game.log("warn", "critical", msg, "dictionary");
      return false;
    }
    var verb = this.verbs[patchVerb.name];
    // for( var prop in patchVerb )
    // {
    //   if (patchVerb.hasOwnProperty(prop)) {
    //     verb[ prop ] = patchVerb[ prop ];
    //   }
    // }
    verb.set(patchVerb);
    verb.initialize(); // this adds but does not remove
    // TODO account for removal of words from verb_lookup

    if (false !== verb) {
      this.game.log(
        "log",
        "medium",
        "patchVerb successfully patched verb " + verb.name + ".",
        "dictionary"
      );
    }
    return verb;
  };
})();