Pre-release
AdventureJS Docs Downloads
Score: 0 Moves: 0
// debug.js
(function () {
  /*global adventurejs A*/

  /**
   * @augments {adventurejs.Verb}
   * @class debug
   * @ajsnode game.dictionary.verbs.debug
   * @ajsconstruct MyGame.createVerb({ "name": "debug", [...] });
   * @ajsconstructedby adventurejs.Dictionary#createVerb
   * @hideconstructor
   * @ajsinstanceof Verb
   * @ajsnavheading UtilityVerbs
   * @summary Toggle game.settings.print_debug_messages.
   * @ajssynonyms debug
   * @tutorial Scripting_VerbSubscriptions
   * @tutorial Verbs_VerbAnatomy
   * @tutorial Verbs_VerbProcess
   * @tutorial Verbs_ModifyVerbs
   * @tutorial Verbs_WriteVerbs
   * @classdesc
   * <pre class="display border outline">
   * <span class="input">&gt; debug</span>
   * Debug messages enabled.
   * </pre>
   * <strong>debug</strong> toggles game.settings.print_debug_messages.
   */
  A.Preverbs.debug = {
    name: "debug",
    synonyms: ["debug"],

    /**
     * @ajsverbstructures
     * @memberof debug
     */
    accepts_structures: ["verb", "verb preposition"],

    /**
     * @memberof debug
     * @ajsverbphrase
     * phrase1:
     * {
     *   accepts_noun: false,
     *   accepts_preposition: true,
     *   requires_preposition: true,
     *   accepts_preposition_without_noun: true,
     *   accepts_these_prepositions: ["on","off"],
     * },
     */
    phrase1: {
      accepts_noun: false,
      accepts_preposition: true,
      requires_preposition: true,
      accepts_preposition_without_noun: true,
      accepts_these_prepositions: ["on", "off"],
    },

    do: function () {
      let input = this.game.getInput();
      let preposition = input.getPreposition(1);
      let structure = input.verified_sentence_structure;
      let msg = "";

      if (structure === "verb") {
        this.game.settings.print_debug_messages =
          !this.game.settings.print_debug_messages;
      }
      if (structure === "verb preposition") {
        this.game.settings.print_debug_messages =
          preposition === "on" ? true : false;
      }
      msg = `Debug messages ${
        this.game.settings.print_debug_messages ? "on" : "off"
      }. `;
      this.game.print(msg);
      return null;
    },
  };
})(); // debug