Pre-release
Adventure.js Docs Downloads
Score: 0 Moves: 0
// toggleState.js
(function () {
  /*global adventurejs A*/
  "use strict";
  var p = adventurejs.Asset.prototype;
  /**
   * Apply the specified verb's state change to the asset.
   * @memberOf adventurejs.Asset
   * @method adventurejs.Asset#toggleState
   * @param {String} verb
   * @returns {Boolean}
   */
  p.toggleState = function Asset_toggleState(verb) {
    if (!this.canSetVerbState(verb)) return false;

    verb = this.game.dictionary.verbs[verb];

    if (verb.state && !this.is[verb.state]) {
      // ex: can do verb close if !is.closed
      this.is[verb.state] = true;
      return true;
    } else if (verb.unstate && this.is[verb.unstate]) {
      // ex: can do verb open if is.closed
      this.is[verb.unstate] = false;
      return true;
    }
    return false;
  };
})();