Advertisement
Zalerinian

ExtText Beta

Dec 19th, 2015
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  //=============================================================================
  2.  // Plugin: External Text
  3.  // Author: Zalerinian
  4.  // Version: 1.2.1
  5.  // License: http://creativecommons.org/licenses/by/4.0/
  6.  //=============================================================================
  7.  
  8.  /*:
  9.   * @plugindesc Use external files to load all the text in your game! Convenient for multi-language support!
  10.   <pluginid ExtText>
  11.   * @author Zalerinian
  12.   *
  13.   * @param Text File
  14.   * @desc The default text file to load into the game.
  15.   * Default: text_en.json
  16.   * @default text_en.json
  17.   *
  18.   * @param Face File
  19.   * @desc The default file to load for predefined faces. This file should be in the text folder. Default: faces.json
  20.   * @default faces.json
  21.   *
  22.   * @param Text Folder
  23.   * @desc The folder to keep your text file(s). Make sure this folder exists! Default: data/text/
  24.   * @default data/text/
  25.   *
  26.   * @param Autofit Text
  27.   * @desc Automatically resize text to fit on the screen.
  28.   * @default true
  29.   *
  30.   * @param Remember Color
  31.   * @desc Remember the last text color used in a conversation, in case the line wrapping puts it on a new page.
  32.   * @default true
  33.   *
  34.   * @param Enable Name Window
  35.   * @desc Enable or disable the name window from being created. Set this to false if you don't intend to use the name window.
  36.   * @default true
  37.   *
  38.   * @param Name Window Margin
  39.   * @desc Code that returns the number of pixels there should be between the name window and side of the game screen.
  40.   * @default return Graphics.width / 5 - this.width / 2
  41.   *
  42.   * @param No Text Warning
  43.   * @desc This string will be returned if there is no text file currently loaded.
  44.   * @default No text file is loaded!
  45.   *
  46.   * @param Asynchronous Loading
  47.   * @desc Load files apart from the game loop?
  48.   * @default true
  49.   *
  50.   * @param Choice Variable
  51.   * @desc A variable used to store the index of the selected choice. Default: 1
  52.   * @default 1
  53.   *
  54.   * @param Number Variable
  55.   * @desc A variable used to store the value of the inputted number. Default: 2
  56.   * @default 2
  57.   *
  58.   * @param Item Variable
  59.   * @desc A variable used to store the item ID of the selected item, or 0 on cancel. Default: 3
  60.   * @default 3
  61.   *
  62.   * @help
  63.   * =============================================================================
  64.   *    Introduction
  65.   * =============================================================================
  66.   *
  67.   * The external text script will allow you to take all the text outside of the
  68.   * game editor, and put it in a nicely-formatted JSON file. To learn more about
  69.   * the JSON format, online resources are available to show how to use it. For
  70.   * example, https://en.wikipedia.org/wiki/JSON#Samples
  71.   *
  72.   * This plugin is an MV edition of Enelvon's popular External Text script for
  73.   * RPG Maker VX Ace.
  74.   *
  75.   * =============================================================================
  76.   *   Asynchronous Loading
  77.   * =============================================================================
  78.   *
  79.   * If this parameter is true, then files will be loaded asynchronously from the
  80.   * game, meaning that the game will continue running without waiting for the
  81.   * file to finish loading. This will improve game performance, as the game won't
  82.   * have to wait for the files to load in before continuing. However, this also
  83.   * means that the text or face data won't be accessible until after the loading
  84.   * is complete, which could possibly cause some issues early on in the game,
  85.   * and whenever the text file is changed.
  86.   *
  87.   * =============================================================================
  88.   *    Using faces
  89.   * =============================================================================
  90.   *
  91.   * The External text plugin allows you to define a face to use with each bit of
  92.   * text. In text file, in the key you wish to set up, simply add a "face"
  93.   * section, with a set of curly braces( {} ) as the value. Inside these curly
  94.   * braces, you must define the type (actor, party, or predefined), the ID for
  95.   * the selected types (Actor and Party must be numbers, predefined depends on
  96.   * they key set in the faces file). The ID for Actor and Party starts at 1.
  97.   * Additionally, you must also supply an index used to determine which face in
  98.   * the faceset to use. Indexes range from 0-7.
  99.   *
  100.   * =============================================================================
  101.   *    Controlling the window
  102.   * =============================================================================
  103.   *
  104.   * In order to control the position and appearance of the text window, you need
  105.   * to add a "window" section. In this section, you can define values for the
  106.   * "background" and "position" fields. The values for these are the same as
  107.   * those you would set in the editor.
  108.   *
  109.   * For example, "background" can be set to "dim" or "transparent" for the black
  110.   * background, or no background respectively. Any other values will result in
  111.   * the window looking like a regular window. The values are case-insensitive.
  112.   *
  113.   * =============================================================================
  114.   *    Additional Inputs
  115.   * =============================================================================
  116.   *
  117.   * Because the full effects of the External Text script, to control faces,
  118.   * position, and appearance, all come from a plugin command or call, the plugin
  119.   * also includes controls for choice input, number input, and item selection.
  120.   *
  121.   * =============================================================================
  122.   *    Setting up the choice window
  123.   * =============================================================================
  124.   *
  125.   * To use a choice window with a text key, the first step is to add a "choice"
  126.   * field to your text file. This will hold the settings for the choice window.
  127.   * The choice window supports the same values for "background" and "position"
  128.   * that the regular window has. In addition, the choice window requires at
  129.   * least "choice" and "variable" properties, with optional "default" and
  130.   * "cancel" properties to define which what the default selection is, and what
  131.   * happens if the user cancels the selection.
  132.   *
  133.   * The choice variable setting for the plugin refers to a variable that will
  134.   * hold the index of the selected choice. Indexes start at 0, and range to
  135.   * <number of choices> - 1.
  136.   * Because the choice input is not set up directly in the editor, this variable
  137.   * must be used in conditional branches so that you can perform different
  138.   * actions based on the selected choice.
  139.   *
  140.   * The "choice" property should be an array of string values, holding the
  141.   * text for each choice. By default, RPG Maker MV only supports 6 choices in a
  142.   * choice selection. With External Text, however, there is no limit to the
  143.   * number of choices.
  144.   *
  145.   * The "default" property is the index (starting at 0) that will be highlighted
  146.   * by default.
  147.   *
  148.   * The "cancel" property is the index of the action to use when the selection is
  149.   * cancelled by the player. A value of -1 will disallow the player from
  150.   * cancelling the selection.
  151.   *
  152.   * If the "cancel" property is a valid value that allows the user to cancel the
  153.   * selection (any value from 0 to the <number of choices> - 1), and the user
  154.   * cancels the selection, this is the index that will be selected.
  155.   *
  156.   * =============================================================================
  157.   *    Setting up the number input window
  158.   * =============================================================================
  159.   *
  160.   * To set up a number input, the text key must have a "number" section with at
  161.   * least a "variable" and "digits" properties. There is an optional "dvar"
  162.   * property that may be used if the "digits" property is set to "variable"
  163.   *
  164.   * The number variable setting is the variable ID that will store the value of
  165.   * the number inputted.
  166.   *
  167.   * The "digits" field can be either a number, representing the number of digits
  168.   * that may be inputted, or the string "variable", indicating that the number
  169.   * of digits to be used can be found in a variable, with the ID stored in the
  170.   * "dvar" property.
  171.   *
  172.   * The "dvar" property is used when the "digits" property is set to "variable".
  173.   * "dvar" should be a variable ID that will hold the number of digits that may
  174.   * be inputted.
  175.   *
  176.   * =============================================================================
  177.   *    Setting up the item selection window
  178.   * =============================================================================
  179.   *
  180.   * Finally, the item input event command is also available. To use it, the text
  181.   * key must have a "number" section. There is only one available option
  182.   * for the item selection command, "type".
  183.   *
  184.   * The item variable setting is a variable ID that will hold the item ID, found
  185.   * in the database, after an item is picked, or 0 if the user cancels the
  186.   * selection.
  187.   *
  188.   * The "type" property is a string that may contain either "regular", "key",
  189.   * "hidden a", or "hidden b". These are all item types that are available in the
  190.   * engine by default. If you don't know what "hidden a" or "hidden b" are,
  191.   * please check the engine help file, as these are new.
  192.   *
  193.   */
  194.  
  195. var Imported = Imported || {};
  196.  
  197. var Zale = Zale || {};
  198. Zale.ExtText = Zale.ExtText || {};
  199.  
  200. (function(){
  201.   if(Imported["MVCommons"] && PluginManager.version("MVCommons", ">=", "1.0.3")) {
  202.     var author = [{
  203.       email: "support@razelon.com",
  204.       name: "Zalerinian",
  205.       website: "http://www.razelon.com"
  206.       }];
  207.     var v = PluginManager.register("ExternalText", "1.2.1", PluginManager.getBasicPlugin("ExternalText").description, author, "2016-3-15", ["MVCommons"], true);
  208.     if(v === undefined) {
  209.       throw new Error("Unable to load ExternalText due to mising dependencies!");
  210.     } else if (v === false){
  211.       PluginManager.printPlugin("ExternalText")
  212.       throw new Error("Unable to load ExternalText due to registration failure! Is there another version running?");
  213.     }
  214.   } else {
  215.     SceneManager.stop();
  216.     throw new Error("External Text requires some functionality of the MVCommons plugin!");
  217.   }
  218. })();
  219.  
  220. (function($){
  221.   "use strict";
  222.  
  223.   // ==========================================================================
  224.   //
  225.   // Parameter Setup
  226.   //  Sets up the parameters of the plugin and stores them in the ExtText
  227.   //  section of the Zale object.
  228.   //
  229.   // ==========================================================================
  230.   var params = PluginManager.parameters("ExtText");
  231.   Zale.ExtText.PARAMETERS  = params;
  232.   Zale.ExtText.TEXTFILE    = params["Text File"];
  233.   Zale.ExtText.TEXTFOLDER  = params["Text Folder"];
  234.   Zale.ExtText.FACEFILE    = params["Face File"];
  235.   Zale.ExtText.CHOICEVAR   = params["Choice Variable"];
  236.   Zale.ExtText.ITEMVAR     = params["Item Variable"];
  237.   Zale.ExtText.NUMVAR      = params["Number Variable"];
  238.   Zale.ExtText.AUTOFIT     = MVC.Boolean(params["Autofit Text"]);
  239.   Zale.ExtText.REMCOLOR    = MVC.Boolean(params["Remember Color"])
  240.   Zale.ExtText.NAMEENABLED = MVC.Boolean(params["Enable Name Window"]);
  241.   Zale.ExtText.NAMEMARGIN  = Function(params["Name Window Margin"]);
  242.   Zale.ExtText.NOTEXTWARN  = params["No Text Warning"];
  243.   Zale.ExtText.LOADASYNC   = MVC.Boolean(params["Asynchronous Loading"]);
  244.   Zale.ExtText.lastColor   = "#ffffff";
  245.  
  246.   // ==========================================================================
  247.   //
  248.   // String.prototype.endsWith Polyfill
  249.   //  This block of code ensures that if the browser using this script doesn't
  250.   //  support the .endsWith function, that it will be made compatible by
  251.   //  adding out own implementation of the function.
  252.   //
  253.   // ==========================================================================
  254.   if (!String.prototype.endsWith) {
  255.    String.prototype.endsWith = function(searchString, position) {
  256.        var subjectString = this.toString();
  257.        if (typeof position !== 'number' || !isFinite(position) || Math.floor(position) !== position || position > subjectString.length) {
  258.          position = subjectString.length;
  259.        }
  260.        position -= searchString.length;
  261.        var lastIndex = subjectString.indexOf(searchString, position);
  262.        return lastIndex !== -1 && lastIndex === position;
  263.    };
  264.   }
  265.  
  266.   /**
  267.    * ==========================================================================
  268.    *
  269.    * Game_System.prototype.initialize()
  270.    *
  271.    * @note
  272.    *  Sets the default text and face files, and then loads them using
  273.    *  their respective methods.
  274.    *
  275.    * ==========================================================================
  276.    */
  277.   Zale.ExtText.GSYS_init_TEng2kfuj = Game_System.prototype.initialize;
  278.   Game_System.prototype.initialize = function() {
  279.     Zale.ExtText.GSYS_init_TEng2kfuj.call(this);
  280.     this._textFile = Zale.ExtText.TEXTFILE;
  281.     this._faceFile = Zale.ExtText.FACEFILE;
  282.   }
  283.  
  284.   /**
  285.     * ==========================================================================
  286.     *
  287.     * Game_System.prototype.textFile
  288.     *
  289.     * @note
  290.     *  Defines the getters and setters for the textFile property of Game_System.
  291.     *  This does not change the file loaded, and only the file to load when
  292.     *  loading a save. This is called internally by TextManager.loadTextFile.
  293.     *
  294.     * ==========================================================================
  295.     */
  296.   Object.defineProperty(Game_System.prototype, "textFile", {
  297.     get: function() {
  298.       return this._textFile;
  299.     },
  300.  
  301.     set: function(value) {
  302.       this._textFile = value;
  303.     },
  304.     configurable: true
  305.   });
  306.  
  307.   /**
  308.    * ==========================================================================
  309.    * Game_System.prototype.faceFile
  310.    *
  311.    * @note
  312.    *  Defines the getters and setters for the faceFile property of Game_System.
  313.    *  This doesn't change the faces loaded, only the file to load when loading
  314.    *  a save. The faces file outlines the predefined faces that may be used
  315.    *  with text keys, and can easily be switched to a different file for
  316.    *  dynamic character costumes. This is called internally by
  317.    *  TextManager.loadFaceFile.
  318.    *
  319.    * ==========================================================================
  320.    */
  321.   Object.defineProperty(Game_System.prototype, "faceFile", {
  322.     get: function() {
  323.       return this._faceFile;
  324.     },
  325.  
  326.     set: function(value) {
  327.       this._faceFile = value;
  328.     },
  329.     configurable: true
  330.   });
  331.  
  332.  
  333.   // ==========================================================================
  334.   //    DataManager
  335.   // ==========================================================================
  336.  
  337.   /**
  338.    * ==========================================================================
  339.    *
  340.    * DataManager.loadGameWithoutRescue()
  341.    *
  342.    * @note
  343.    *  Loads the sotred text and face files on load so that the data is ready
  344.    *  to go once a game is loaded!
  345.    *
  346.    * ==========================================================================
  347.    */
  348.   Zale.ExtText.DM_lgwr_RTVIOwnoSNC4b9 = DataManager.loadGameWithoutRescue;
  349.   DataManager.loadGameWithoutRescue = function(id) {
  350.     var r = Zale.ExtText.DM_lgwr_RTVIOwnoSNC4b9.call(this, id);
  351.     if(!r) {
  352.       return r;
  353.     }
  354.     if(typeof $gameSystem.textFile !== 'string') {
  355.       $gameSystem.textFile = Zale.ExtText.TEXTFILE;
  356.     }
  357.     if(typeof $gameSystem.faceFile !== 'string') {
  358.       $gameSystem.faceFile = Zale.ExtText.FACEFILE;
  359.     }
  360.     TextManager.loadTextFile($gameSystem.textFile);
  361.     TextManager.loadFaceFile($gameSystem.faceFile);
  362.     return true;
  363.   }
  364.  
  365.   /**
  366.    * ==========================================================================
  367.    *
  368.    * DataManager.createGameObjects()
  369.    *
  370.    * @note
  371.    *  Aliases the createGameObjects function to also load in the default
  372.    *  text and face files into $gameSystem.
  373.    *
  374.    * ==========================================================================
  375.    */
  376.   Zale.ExtText.DM_cgo_vpioivnOIEUV5 = DataManager.createGameObjects;
  377.   DataManager.createGameObjects = function() {
  378.     Zale.ExtText.DM_cgo_vpioivnOIEUV5.call(this);
  379.     TextManager.loadTextFile($gameSystem.textFile);
  380.     TextManager.loadFaceFile($gameSystem.faceFile);
  381.   }
  382.  
  383.  
  384.   // ==========================================================================
  385.   //    Window Message
  386.   // ==========================================================================
  387.  
  388.   /**
  389.    * ==========================================================================
  390.    *
  391.    * Window_Base.prototype.convertEscapeCharacters(string text)
  392.    *
  393.    * @note
  394.    *  This aliased function is responsible for replacing the \t[key] text codes
  395.    *  with the text from the given key.
  396.    *
  397.    * ==========================================================================
  398.    */
  399.   Zale.ExtText.WBase_cec_VNOCxoiwrv1 = Window_Base.prototype.convertEscapeCharacters
  400.   Window_Base.prototype.convertEscapeCharacters = function(text) {
  401.     text = Zale.ExtText.WBase_cec_VNOCxoiwrv1.call(this, text);
  402.     text = text.replace(/\x1bt\[(.+?)\]/gi, function(){
  403.       return TextManager.text(arguments[1]);
  404.     });
  405.     return text
  406.   }
  407.  
  408.   /*
  409.    * Window_Base.prototype.drawItemName(item, x, y, width)
  410.    * @param item The item we're drawing the name of.
  411.    * @param {Number} x The x position to draw at.
  412.    * @param {Number} y The y position to draw at.
  413.    * @param {Number} width The max width to draw the name with.
  414.    * @note
  415.    * This function is aliased to ensure that if the name is a text key, we can
  416.    * replace it with the correct value.
  417.    */
  418.   Zale.ExtText.WB_din = Window_Base.prototype.drawItemName;
  419.   Window_Base.prototype.drawItemName = function(item, x, y, width) {
  420.     if(item) {
  421.       item.name = item.name.replace(/\\t\[(.+?)\]/gi, function(m, k) {
  422.         return TextManager.text(k);
  423.       });
  424.     }
  425.     Zale.ExtText.WB_din.call(this, item, x, y, width);
  426.   }
  427.  
  428.   /**
  429.    * ==========================================================================
  430.    *
  431.    * Window_Message.prototype.createSubWindows()
  432.    *
  433.    * @note
  434.    *  Aliases the createSubWindows method to additionally call the
  435.    *  createNameWindow function if the name window is enabled.
  436.    *
  437.    * ==========================================================================
  438.    */
  439.   Zale.ExtText.WMessage_csw_OIcnblwkCn2rrc = Window_Message.prototype.createSubWindows;
  440.   Window_Message.prototype.createSubWindows = function() {
  441.     Zale.ExtText.WMessage_csw_OIcnblwkCn2rrc.call(this);
  442.     if(Zale.ExtText.NAMEENABLED){
  443.       this.createNameWindow();
  444.     }
  445.   }
  446.  
  447.   /**
  448.    * ==========================================================================
  449.    *
  450.    * Window_Message.prototype.updatePlacement()
  451.    *
  452.    * @note
  453.    *  Aliases the updatePlacement function to also call the name subwindow's
  454.    *  "proprietary" updatePlacement function, but only if the name window is
  455.    *  enabled.
  456.    *
  457.    * ==========================================================================
  458.    */
  459.   Zale.ExtText.WMessage_uplace_YGWfgcognvop42nc = Window_Message.prototype.updatePlacement;
  460.   Window_Message.prototype.updatePlacement = function() {
  461.     Zale.ExtText.WMessage_uplace_YGWfgcognvop42nc.call(this);
  462.     if(Zale.ExtText.NAMEENABLED) {
  463.       this._nameWindow.updatePlacement(this);
  464.     }
  465.   }
  466.  
  467.   /**
  468.    * ==========================================================================
  469.    *
  470.    * Window_Message.prototype.terminateMessage()
  471.    *
  472.    * @note
  473.    *  Aliases the terminateMessage function to also close the name subwindow,
  474.    *  if the name window is enabled.
  475.    *
  476.    * ==========================================================================
  477.    */
  478.   Zale.ExtText.WMessage_term_ZNGIOiwofnoizr222cn = Window_Message.prototype.terminateMessage;
  479.   Window_Message.prototype.terminateMessage = function() {
  480.     Zale.ExtText.WMessage_term_ZNGIOiwofnoizr222cn.call(this);
  481.     if(Zale.ExtText.NAMEENABLED){
  482.       this._nameWindow.close();
  483.     }
  484.   }
  485.  
  486.   /**
  487.    * ==========================================================================
  488.    *
  489.    * Window_Message.prototype.startMessage()
  490.    *
  491.    * @note
  492.    *  Aliases the startMessage function to check if Autofit Text should be
  493.    *  enabled. If Autofit is enabled, the text in the textState object is
  494.    *  set to the text returned by the TextManager.resizeText function.
  495.    *
  496.    * ==========================================================================
  497.    */
  498.   Zale.ExtText.WMessage_startm_NIOVnoind = Window_Message.prototype.startMessage;
  499.   Window_Message.prototype.startMessage = function() {
  500.     Zale.ExtText.WMessage_startm_NIOVnoind.call(this);
  501.     if(Zale.ExtText.AUTOFIT) {
  502.       var lines = TextManager.resizeText(this._textState.text, this.contentsWidth() - this._textState.left)
  503.       this._textState.text = lines.join("\n");
  504.     }
  505.   }
  506.  
  507.   /**
  508.    * ==========================================================================
  509.    * Window_Message.prototype.changeTextColor(string color)
  510.    *
  511.    * @note
  512.    *  Aliases the changeTextColor function in Window_Message. In addition to
  513.    *  its regular duties, if the Remember Color option was set to true in the
  514.    *  plugin's configuration, this will set the value Zale.ExtText.lastcolor
  515.    *  in order to retain the last color used in text pages.
  516.    *
  517.    * ==========================================================================
  518.    */
  519.   Zale.ExtText.WMessage_ctc_IONciowvn8hnanovi = Window_Message.prototype.changeTextColor;
  520.   Window_Message.prototype.changeTextColor = function(color) {
  521.     if(Zale.ExtText.REMCOLOR) {
  522.       Zale.ExtText.lastColor = this.contents.textColor;
  523.     }
  524.     Zale.ExtText.WMessage_ctc_IONciowvn8hnanovi.call(this, color);
  525.   }
  526.  
  527.   /**
  528.    * ==========================================================================
  529.    * Window_Message.prototype.resetFontSettings()
  530.    *
  531.    * @note
  532.    *  Aliases the resetFontSettings function. After resetting all the font
  533.    *  settings to their defaults, the alias will check if the last text color
  534.    *  was remembered. If it was, the window's text color will be set to the
  535.    *  last color that was stored in the settings.
  536.    *
  537.    * ==========================================================================
  538.    */
  539.   Zale.ExtText.WMessage_rfs_NOIsionwiocn240 = Window_Message.prototype.resetFontSettings;
  540.   Window_Message.prototype.resetFontSettings = function() {
  541.     Zale.ExtText.WMessage_rfs_NOIsionwiocn240.call(this);
  542.     if(Zale.ExtText.REMCOLOR) {
  543.       this.contents.textColor = Zale.ExtText.lastColor;
  544.     }
  545.   }
  546.  
  547.   /**
  548.    * ==========================================================================
  549.    * Window_Message.prototype.processEscapeCharacter(string code,
  550.    *    object textState)
  551.    *
  552.    * @note
  553.    *  Aliases the processEscapeCharacter function. This alias allows you to
  554.    *  set the name in the name window in the text. This will only have an
  555.    *  affect if the name window is enabled.
  556.    *
  557.    * ==========================================================================
  558.    */
  559.   Zale.ExtText.WMessage_pec_NOCionoi2rgnioo = Window_Message.prototype.processEscapeCharacter;
  560.   Window_Message.prototype.processEscapeCharacter = function(code, textState) {
  561.     if(Zale.ExtText.NAMEENABLED && code.toLowerCase() === 'n') {
  562.       var substr = textState.text.substring(textState.index);
  563.       if(/<([.\s\S]*?)>/m.test(substr)) {
  564.         var match = /<([.\s\S]*?)>/m.exec(substr);
  565.         textState.index += match[0].length;
  566.         this.setName(this.convertEscapeCharacters(match[1]));
  567.       }
  568.     }
  569.     Zale.ExtText.WMessage_pec_NOCionoi2rgnioo.call(this, code, textState);
  570.   }
  571.  
  572.   /**
  573.    * ==========================================================================
  574.    * Window_Message.prototype.newPage(object textState)
  575.    *
  576.    * @note
  577.    *  If the return value of Game_Message.prototype.characterName (defined
  578.    *  below) is not null, and the name window exists, then we set the name
  579.    *  for the name window here.
  580.    *
  581.    * ==========================================================================
  582.    */
  583.  
  584.   Zale.ExtText.WMessage_npage_NCOWOFNdoon = Window_Message.prototype.newPage;
  585.   Window_Message.prototype.newPage = function(textState) {
  586.     Zale.ExtText.WMessage_npage_NCOWOFNdoon.call(this, textState);
  587.     if(this._nameWindow && $gameMessage.characterName()) {
  588.       this.setName($gameMessage.characterName());
  589.     }
  590.   }
  591.  
  592.   /**
  593.    * ==========================================================================
  594.    * Window_Message.prototype.createNamewindow()
  595.    *
  596.    * @note
  597.    *  Creates the name window and sets its initial position based on the
  598.    *  message window's. The window is added as a separate child from the
  599.    *  window layer, because the name window overlaps the message window, and
  600.    *  this can cause issues with windowskins that have rounded corners, as the
  601.    *  transparent pixels on the corners would overwrite the windows drawn
  602.    *  before.
  603.    *  This is an issue directly with Pixi.js, and thus no easy solution is
  604.    *  available.
  605.    *
  606.    * ==========================================================================
  607.    */
  608.   Window_Message.prototype.createNameWindow = function() {
  609.     this._nameWindow = new Window_Help(1);
  610.     this._nameWindow.openness = 0;
  611.     this._nameWindow.updatePlacement = function(parent) {
  612.       this.x = Zale.ExtText.NAMEMARGIN.bind(this)();
  613.       if(parent.y > 0) {
  614.         this.y = parent.y - this.height / 1.5;
  615.       } else {
  616.         this.y = parent.height - this.height / 1.5;
  617.       }
  618.     }
  619.     SceneManager._scene.addChild(this._nameWindow);
  620.   }
  621.  
  622.   /**
  623.    * ==========================================================================
  624.    * Window_Message.prototype.closeName()
  625.    *
  626.    * @note
  627.    *  If the name window exists, it is closed using Window_Base's close
  628.    *  function. This provides us with the little closing animation.
  629.    *
  630.    * ==========================================================================
  631.    */
  632.   Window_Message.prototype.closeName = function() {
  633.     if(this._nameWindow){
  634.       this._nameWindow.close();
  635.     }
  636.   }
  637.  
  638.   /**
  639.    * ==========================================================================
  640.    * Window_Message.prototype.setName(string name)
  641.    *
  642.    * @note
  643.    *  If the messae window exists, this function sets its text to the given
  644.    *  string, and resizes and repositions the window to accomodate the text.
  645.    *
  646.    * ==========================================================================
  647.    */
  648.   Window_Message.prototype.setName = function(name) {
  649.     if(this._nameWindow){
  650.       this._nameWindow.width = this._nameWindow.textWidth(name) + 8 + this.padding * 2;
  651.       this._nameWindow.setText(name);
  652.       this._nameWindow.updatePlacement(this);
  653.       this._nameWindow.open();
  654.     }
  655.   }
  656.  
  657.  
  658.  
  659.  
  660.   // ==========================================================================
  661.   //    Game Message
  662.   // ==========================================================================
  663.  
  664.   /**
  665.    * ==========================================================================
  666.    *
  667.    * Game_Message.prototype.clear()
  668.    *
  669.    * @note
  670.    *  Aliases Game_Message's clear method. This sets the _characterName
  671.    *  property to null, signalling that there should be no name window
  672.    *  present with the current message.
  673.    *
  674.    * ==========================================================================
  675.    */
  676.   Zale.ExtText.GMessage_clr_Zoqbop429dncqnf = Game_Message.prototype.clear;
  677.   Game_Message.prototype.clear = function() {
  678.     Zale.ExtText.GMessage_clr_Zoqbop429dncqnf.call(this);
  679.     this._characterName = null;
  680.   }
  681.  
  682.   /**
  683.    * ==========================================================================
  684.    *
  685.    * Game_Message.prototype.setCharacterName(string name)
  686.    *
  687.    * @note
  688.    *  Sets the _characterName property to the given string, which will be
  689.    *  displayed in the name window, if it is enabled.
  690.    *
  691.    * ==========================================================================
  692.    */
  693.   Game_Message.prototype.setCharacterName = function(name) {
  694.     this._characterName = name;
  695.   }
  696.  
  697.   /**
  698.    * ==========================================================================
  699.    *
  700.    * Game_Message.prototype.characterName()
  701.    *
  702.    * @note
  703.    *  Returns the current calue of the _characterName property.
  704.    *
  705.    * @return A string containing the current name for the name window.
  706.    *
  707.    * ==========================================================================
  708.    */
  709.   Game_Message.prototype.characterName = function() {
  710.     return this._characterName;
  711.   }
  712.  
  713.  
  714.   // ==========================================================================
  715.   //    Game Interpeter
  716.   // ==========================================================================
  717.  
  718.   /**
  719.    * ==========================================================================
  720.    *
  721.    * Game_Inptereter.prototype.pluginCommand()
  722.    *
  723.    * @note
  724.    *  Allows the game developer to show text by using a plugin command
  725.    *  starting with ExternalText, with the first argument being the text key
  726.    *  to display.
  727.    *
  728.    * ==========================================================================
  729.    */
  730.   Zale.ExtText.GI_pcom_OISqs1cdkjz = Game_Interpreter.prototype.pluginCommand;
  731.   Game_Interpreter.prototype.pluginCommand = function(command, args) {
  732.     Zale.ExtText.GI_pcom_OISqs1cdkjz.call(this, command, args);
  733.     if(command.match(/External[_-]*Text/i)) {
  734.       if(args.length > 0){
  735.         if(args[0].toLowerCase() == "show") {
  736.           TextManager.displayMessage(args.slice(1).join(" "));
  737.           this.setWaitMode('message');
  738.         } else if(args[0].toLowerCase() == "load") {
  739.           if(args[1] == "text") {
  740.             TextManager.loadTextFile(args.slice(2).join(" "));
  741.           } else if(args[1] == "face") {
  742.             TextManager.loadFaceFile(args.slice(2).join(" "));
  743.           }
  744.         }
  745.       }
  746.     }
  747.   }
  748.  
  749.   /**
  750.    * ==========================================================================
  751.    *
  752.    * Game_Interpreter.prototype.showText()
  753.    *
  754.    * @note
  755.    *  A method to add to the Game_Interpretter class so as to give people who
  756.    *  prefer the old way of interacting with plugins a way to use the
  757.    *  External Text script.
  758.    *
  759.    *
  760.    * ==========================================================================
  761.    */
  762.   Game_Interpreter.prototype.showText = function(key) {
  763.     TextManager.displayMessage(key);
  764.     this.setWaitMode('message');
  765.   }
  766.  
  767.  
  768.   // ==========================================================================
  769.   //    TextManager
  770.   // ==========================================================================
  771.  
  772.   /*
  773.    * TextManager.basic(id)
  774.    * @param {Number} id The basic text id.
  775.    * @note
  776.    * Aliases this function to return the term with any text keys replaced.
  777.    */
  778.   Zale.ExtText.TM_basic = TextManager.basic;
  779.   $.basic = function(basicId) {
  780.       return Zale.ExtText.TM_basic.call(this, basicId).replace(/\\t\[(.+?)\]/gi, function(m, k) {
  781.         return TextManager.text(k);
  782.       }) || '';
  783.   };
  784.  
  785.   /*
  786.    * TextManager.param(id)
  787.    * @param {Number} id The param text id.
  788.    * @note
  789.    * Aliases this function to return the term with any text keys replaced.
  790.    */
  791.   Zale.ExtText.TM_param = TextManager.param;
  792.   $.param = function(paramId) {
  793.       return Zale.ExtText.TM_param.call(this, paramId).replace(/\\t\[(.+?)\]/gi, function(m, k) {
  794.         return TextManager.text(k);
  795.       }) || '';
  796.   };
  797.  
  798.   /*
  799.    * TextManager.command(id)
  800.    * @param {Number} id The command text id.
  801.    * @note
  802.    * Aliases this function to return the term with any text keys replaced.
  803.    */
  804.   Zale.ExtText.TM_command = TextManager.command;
  805.   $.command = function(commandId) {
  806.       return Zale.ExtText.TM_command.call(this, commandId).replace(/\\t\[(.+?)\]/gi, function(m, k) {
  807.         return TextManager.text(k);
  808.       }) || '';
  809.   };
  810.  
  811.   /*
  812.    * TextManager.message(id)
  813.    * @param {Number} id The message text id.
  814.    * @note
  815.    * Aliases this function to return the term with any text keys replaced.
  816.    */
  817.   Zale.ExtText.TM_message = TextManager.message;
  818.   $.message = function(messageId) {
  819.       return Zale.ExtText.TM_message.call(this, messageId).replace(/\\t\[(.+?)\]/gi, function(m, k) {
  820.         return TextManager.text(k);
  821.       }) || '';
  822.   };
  823.  
  824.   /**
  825.    * ==========================================================================
  826.    *
  827.    * TextManager.resizeText(string text, int maxWidth, [bitmap measure])
  828.    *
  829.    * @param text The text to resize
  830.    * @param maxWidth The max width that the text should fit in
  831.    * @param measure A bitmap with which to meaure text size. Optional.
  832.    *
  833.    * @note
  834.    *  Takes the given text and resizes it by splitting it by word, or letter
  835.    *  if absolutely needed, to fit within the given width. The result is
  836.    *  returned as an array.
  837.    *
  838.    * @return An array of strings.
  839.    *
  840.    * ==========================================================================
  841.    */
  842.   $.resizeText = function(text, maxWidth, measure) {
  843.     if(!maxWidth) {
  844.       throw new Error("No max width given!");
  845.     }
  846.     if(!(measure instanceof Bitmap)) {
  847.       measure = new Bitmap(1, 1);
  848.     }
  849.     var words = text.split(" ");
  850.     var lines = [];
  851.     var line = "";
  852.     var length = 0;
  853.     for(var i = 0; i < words.length; i++) {
  854.       var word = words[i];
  855.       if(measure.measureTextWidth(this.realText(word)) > maxWidth) {
  856.         for(var j = 0; j < word.length; j++) {
  857.           if(length + measure.measureTextWidth(this.realText(word[j]) + "-") > maxWidth) {
  858.             lines.push(line + "-");
  859.             line = word[j];
  860.             length = measure.measureTextWidth(this.realText(line));
  861.           } else {
  862.             length += measure.measureTextWidth(this.realText(word[j]));
  863.             line += word[j];
  864.             if(word[j] === '\n') {
  865.               length = 0;
  866.             }
  867.           }
  868.         }
  869.       } else if(length + measure.measureTextWidth(this.realText(word) + " ") > maxWidth) {
  870.         lines.push(line.trim());
  871.         line = word + " ";
  872.         length = measure.measureTextWidth(this.realText(line));
  873.       } else {
  874.         length += measure.measureTextWidth(this.realText(word) + " ");
  875.         line += word + " ";
  876.         if(word.indexOf('\n') !== -1) {
  877.           // Logically, new lines would only be at the end.
  878.           length = 0;
  879.         }
  880.       }
  881.     }
  882.     lines.push(line);
  883.     return lines;
  884.   }
  885.  
  886.   /**
  887.    * ==========================================================================
  888.    *
  889.    * TextManager.realText(string str)
  890.    *
  891.    * @param str The string to check for and convert escape codes.
  892.    *
  893.    * @note
  894.    *  This function takes the given string and replaces them with the text
  895.    *  they end up producing to the end user, so that the result can be
  896.    *  properly resized for autofit to process it.
  897.    *
  898.    * @return A string with text codes replaced.
  899.    *
  900.    * ==========================================================================
  901.    */
  902.   $.realText = function(str) {
  903.     var w = new Window_Base(0, 0, 0, 0);
  904.     str = str.replace(/\\/g, '\x1b');
  905.     str = str.replace(/\x1bt\[(.+?)\]/gi);
  906.     str = str.replace(/\x1b\x1b/gi, '\\');
  907.     str = str.replace(/\x1bV\[(\d+)\]/gi, function() {
  908.         return $gameVariables.value(parseInt(arguments[1]));
  909.     }.bind(this));
  910.     str = str.replace(/\x1bN\[(\d+)\]/gi, function() {
  911.         return w.actorName(parseInt(arguments[1]));
  912.     }.bind(this));
  913.     str = str.replace(/\x1bP\[(\d+)\]/gi, function() {
  914.         return w.partyMemberName(parseInt(arguments[1]));
  915.     }.bind(this));
  916.     str = str.replace(/\x1bG/gi, TextManager.currencyUnit);
  917.     str = str.replace(/\x1b\{/g, '');
  918.     str = str.replace(/\x1b\}/g, '');
  919.     str = str.replace(/\x1b\$/g, '');
  920.     str = str.replace(/\x1b\./g, '');
  921.     str = str.replace(/\x1b\|/g, '');
  922.     str = str.replace(/\x1b\!/g, '');
  923.     str = str.replace(/\x1b\>/g, '');
  924.     str = str.replace(/\x1b\</g, '');
  925.     str = str.replace(/\x1b\^/g, '');
  926.     str = str.replace(/\x1bN<[.\s\S]+/i, '');
  927.     return str;
  928.   }
  929.  
  930.   /**
  931.    * ==========================================================================
  932.    *
  933.    * TextManager.loadTextFile(string file, [function onLoad],
  934.    *    [function onError])
  935.    *
  936.    * @param file The text file to load.
  937.    * @param onLoad An optional function to be called after loading.
  938.    * @param onError An option function to be called on an error loading.
  939.    *
  940.    * @note
  941.    *  Loads the given filename from the predefined text folder and sets it as
  942.    *  the text.
  943.    *
  944.    * ==========================================================================
  945.    */
  946.   $.loadTextFile = function(file, onLoad, onError) {
  947.     if(!file.endsWith(".json")) {
  948.       file += ".json";
  949.     }
  950.     if($gameSystem) {
  951.       $gameSystem.textFile = file;
  952.     }
  953.     try {
  954.       if(Zale.ExtText.LOADASYNC){
  955.         DataManager.ajaxLoadFileAsync(Zale.ExtText.TEXTFOLDER + file, null, function(xhr, path, name) {
  956.           if(xhr.status < 400) {
  957.             TextManager._text = JSON.parse(xhr.responseText);
  958.             if(typeof onLoad === 'function') {
  959.               onLoad.call(this);
  960.             }
  961.           } else {
  962.             console.error("Unable to load text file!");
  963.             if(typeof onError === 'function') {
  964.               onError.call(this);
  965.             }
  966.           }
  967.         });
  968.       } else {
  969.         TextManager._text = DataManager.ajaxLoadFile(Zale.ExtText.TEXTFOLDER + file, "text/json");
  970.       }
  971.     } catch(e) {
  972.       console.error(e);
  973.     }
  974.   }
  975.  
  976.   /**
  977.    * ==========================================================================
  978.    *
  979.    * TextManager.loadFaceFile(string file, [function onLoad],
  980.    *    [function onError])
  981.    *
  982.    * @param file The file to load for predefined faces, inside the text
  983.    *  folder.
  984.    * @param onLoad An optional function to be called on loading.
  985.    * @param onError An optional function to call if there was an error
  986.    *  loading.
  987.    *
  988.    * @note
  989.    *  Loads the specified file and sets it as the predefined faces file.
  990.    *
  991.    * ==========================================================================
  992.    */
  993.   $.loadFaceFile = function(file, onLoad, onError) {
  994.     if(!file.endsWith(".json")) {
  995.       file += ".json";
  996.     }
  997.     if($gameSystem) {
  998.       $gameSystem.faceFile = file;
  999.     }
  1000.     try {
  1001.       if(Zale.ExtText.LOADASYNC) {
  1002.         DataManager.ajaxLoadFileAsync(Zale.ExtText.TEXTFOLDER + file, null, function(xhr, path, name) {
  1003.           if(xhr.status < 400) {
  1004.             TextManager._faces = JSON.parse(xhr.responseText);
  1005.             if(typeof onLoad === 'function') {
  1006.               onLoad.call(this);
  1007.             }
  1008.           } else {
  1009.             console.error("Unable to load text file!");
  1010.             if(typeof onError === 'function') {
  1011.               onError.call(this);
  1012.             }
  1013.           }
  1014.         });
  1015.       } else {
  1016.         TextManager._faces = DataManager.ajaxLoadFile(Zale.ExtText.TEXTFOLDER + file, "text/json");
  1017.       }
  1018.     } catch(e) {
  1019.       console.error(e);
  1020.     }
  1021.   }
  1022.  
  1023.   /**
  1024.    * ==========================================================================
  1025.    *
  1026.    * TextManager.text(string key)
  1027.    *
  1028.    * @param key The key name to get the text for.
  1029.    *
  1030.    * @note
  1031.    *  Gets the text for the given key. If no key is found, an error message
  1032.    *  is returned and printed to the console. If no file is loaded, an error
  1033.    *  message is printed to the console, and undefined is returned.
  1034.    *
  1035.    * @return String on success, undefined on failure.
  1036.    *
  1037.    * ==========================================================================
  1038.    */
  1039.   $.text = function(key) {
  1040.     if(!this._text) {
  1041.       console.error("Attempt to get text before any text file is loaded!");
  1042.       return Zale.ExtText.NOTEXTWARN;
  1043.     }
  1044.     if(this._text[key]) {
  1045.       return this._text[key].text;
  1046.     } else {
  1047.       return "No text found for '" + key + "'!";
  1048.     }
  1049.   }
  1050.  
  1051.   /**
  1052.    * ==========================================================================
  1053.    *
  1054.    * TextManager.textObject(string key)
  1055.    *
  1056.    * @param key The key to load the text object of.
  1057.    *
  1058.    * @note
  1059.    *  Loads the whle text object for the given key. Errors if there is no text
  1060.    *  file loaded.
  1061.    *
  1062.    * @return JS Object on success, undefine don failure.
  1063.    *
  1064.    * ==========================================================================
  1065.    */
  1066.   $.textObject = function(key) {
  1067.     if(!this._text) {
  1068.       console.error("Attempt to get text before any text file is loaded!");
  1069.       return undefined;
  1070.     }
  1071.     if(this._text[key]) {
  1072.       return this._text[key];
  1073.     } else {
  1074.       return {text: "No text found for '" + key + "'!"}
  1075.     }
  1076.   }
  1077.  
  1078.   /**
  1079.    * ==========================================================================
  1080.    *
  1081.    * TextManager.displayMessage(string key)
  1082.    *
  1083.    * @param key A string representing the key to load
  1084.    *
  1085.    * @note
  1086.    *  Dispays the tet from the given key, and also checks for and sets up the
  1087.    *  faces, item selection, number input, and choice selection. Each
  1088.    *  branch in the setup calls it's own methods to get the data that will be
  1089.    *  set, and then another to actually set the data. This allows other
  1090.    *  plugins to have plenty of opportunities to interact and change how
  1091.    *  External Text works.
  1092.    *
  1093.    * ==========================================================================
  1094.    */
  1095.   $.displayMessage = function(key) {
  1096.     var data = this.textObject(key);
  1097.     if(data) {
  1098.       if(data.face) {
  1099.         this.setFace(this._processFace(data.face));
  1100.       }
  1101.       if(data.window) {
  1102.         if(data.window.background) {
  1103.           this.setWindowBackground(this._processWindowBackground(data.window.background));
  1104.         }
  1105.         if(data.window.position) {
  1106.           this.setWindowPosition(this._processWindowPosition(data.window.position));
  1107.         }
  1108.       }
  1109.  
  1110.       if(data.choice) {
  1111.         if(data.choice.background) {
  1112.           this.setChoiceBackground(this._processWindowBackground(data.choice.background));
  1113.         }
  1114.         if(data.choice.position) {
  1115.           this.setChoicePosition(this._processWindowPosition(data.choice.position));
  1116.         }
  1117.         var def = data.choice.default;
  1118.         var can = data.choice.cancel;
  1119.         var v = data.choice.variable;
  1120.         this.setChoiceList((v || Zale.ExtText.CHOICEVAR), data.choice.choices, def ? def : 0, can ? can : -1);
  1121.       }
  1122.  
  1123.       if(data.number) {
  1124.         var digits = 0;
  1125.         if(typeof data.number.digits === "string" && data.number.digits.toLowerCase() === "variable"){
  1126.           digits = $gameVariables.value(data.number.dvar);
  1127.         } else {
  1128.           digits = data.number.digits;
  1129.         }
  1130.         var v = data.number.variable;
  1131.         this.setNumberInput((v || Zale.ExtText.NUMVAR), digits);
  1132.       }
  1133.  
  1134.       if(data.item) {
  1135.         var v = data.item.variable;
  1136.         this.setItemInput((v || Zale.ExtText.ITEMVAR), this._processItemInput);
  1137.       }
  1138.  
  1139.       if(data.name) {
  1140.         $gameMessage.setCharacterName(data.name);
  1141.       } else {
  1142.         $gameMessage.setCharacterName(null);
  1143.       }
  1144.  
  1145.       $gameMessage.add(data.text);
  1146.     } else {
  1147.       $gameMessage.add("No text data found for " + key);
  1148.       console.error("No text data found for " + key);
  1149.     }
  1150.   }
  1151.  
  1152.   /**
  1153.    * ==========================================================================
  1154.    *
  1155.    * TextManager._processFace(object data)
  1156.    *
  1157.    * @param data A JS object containing face data
  1158.    *
  1159.    * @note
  1160.    *  Checks the values of the object to determine what face to display.
  1161.    *
  1162.    * @return An array containing the face file and index to display.
  1163.    *
  1164.    * ==========================================================================
  1165.    */
  1166.   $._processFace = function(data) {
  1167.     var face = ['', 0];
  1168.     switch(data.type.toLowerCase()) {
  1169.       case "actor":
  1170.         face = this._getActorFace(data);
  1171.         break;
  1172.       case "party":
  1173.         face = this._getPartyFace(data);
  1174.         break;
  1175.       case "predefined":
  1176.         face = this._getPredefinedFace(data);
  1177.         break;
  1178.       default:
  1179.         break;
  1180.     }
  1181.     return face;
  1182.   }
  1183.  
  1184.   /**
  1185.    * ==========================================================================
  1186.    *
  1187.    * TextManager._processItemInput(object data)
  1188.    *
  1189.    * @param data A JS object containing item input data
  1190.    *
  1191.    * @note
  1192.    *  Checks the values of the object to determine what items to display.
  1193.    *  1 is regular items, 2 is key items, 3 is hidden a items, and 4 is
  1194.    *  hidden b items.
  1195.    *
  1196.    * @return A number indicating the type of item to display.
  1197.    *
  1198.    * ==========================================================================
  1199.    */
  1200.   $._processItemInput = function(data) {
  1201.     var type = 1;
  1202.     switch(data.item.type.toLowerCase()) {
  1203.       case "regular":
  1204.         type = 1;
  1205.         break;
  1206.       case "key":
  1207.         type = 2;
  1208.         break;
  1209.       case "hidden a":
  1210.         type = 3;
  1211.         break;
  1212.       case "hidden b":
  1213.         type = 4;
  1214.         break;
  1215.     }
  1216.     return type;
  1217.   }
  1218.  
  1219.   /**
  1220.    * ==========================================================================
  1221.    *
  1222.    * TextManager._processWindowBackground(object data)
  1223.    *
  1224.    * @param data A JS object that contains window background data
  1225.    *
  1226.    * @note
  1227.    *  Checks the value of the object to determind what the background should
  1228.    *  be set as.
  1229.    *
  1230.    * @return An integer representing background type.
  1231.    *
  1232.    * ==========================================================================
  1233.    */
  1234.   $._processWindowBackground = function(data) {
  1235.     var type = 0;
  1236.     switch(data.toLowerCase()) {
  1237.       case "transparent":
  1238.         type = 2;
  1239.         break;
  1240.       case "dim":
  1241.         type = 1;
  1242.         break;
  1243.       default:
  1244.         type = 0;
  1245.         break;
  1246.     }
  1247.     return type;
  1248.   }
  1249.  
  1250.   /**
  1251.    * ==========================================================================
  1252.    *
  1253.    * TextManager._processWindowPosition(string data)
  1254.    *
  1255.    * @param data A string representing the position for the window.
  1256.    *
  1257.    * @note
  1258.    *  Based on the given string, the windows position will be placed on the
  1259.    *  top, middle, or bottom (default) of the screen.
  1260.    *
  1261.    * @return An integer used to set the window position.
  1262.    *
  1263.    * ==========================================================================
  1264.    */
  1265.   $._processWindowPosition = function(data) {
  1266.     var position = 2;
  1267.     switch(data.toLowerCase()) {
  1268.       case "top":
  1269.         position = 0;
  1270.         break;
  1271.       case "middle":
  1272.         position = 1;
  1273.         break;
  1274.       default:
  1275.         break;
  1276.     }
  1277.     return position;
  1278.   }
  1279.  
  1280.   /**
  1281.    * ==========================================================================
  1282.    *
  1283.    * TextManager._getActorFace(object data)
  1284.    *
  1285.    * @param data A JS object that contains data for the face to display.
  1286.    *
  1287.    * @note
  1288.    *  This funciton will return the image filename and index for the face to
  1289.    *  for the current message. If the actor with the given ID doesn't exist,
  1290.    *  then the retun values will both be undefined.
  1291.    *
  1292.    * @return An array of the face filename and index..
  1293.    *
  1294.    * ==========================================================================
  1295.    */
  1296.   $._getActorFace = function(data) {
  1297.     var face, index;
  1298.     if($gameActors.actor(data.id)) {
  1299.       face = $gameActors.actor(data.id).faceName();
  1300.       if(data.index){
  1301.         index = data.index;
  1302.       } else {
  1303.         index = $gameActors.actor(data.id).faceIndex();
  1304.       }
  1305.     }
  1306.     return [face, index];
  1307.   }
  1308.  
  1309.   /**
  1310.    * ==========================================================================
  1311.    *
  1312.    * TextManager._getPartyFace(object data)
  1313.    *
  1314.    * @param data A JS object that contains data for getting a face from a
  1315.    *  party memeber.
  1316.    *
  1317.    * @note
  1318.    *  Returns the image filename based on a current party member. If an index
  1319.    *  is not specified, the index of the face setup in the editor is used.
  1320.    *
  1321.    * @return An array of the image filename and index.
  1322.    *
  1323.    * ==========================================================================
  1324.    */
  1325.   $._getPartyFace = function(data) {
  1326.     var face, index;
  1327.     if(data.id) {
  1328.       var member = $gameParty.members[id - 1];
  1329.       face = member.faceName();
  1330.       if(data.index) {
  1331.         index = member.faceIndex();
  1332.       } else {
  1333.         index = data.index;
  1334.       }
  1335.     }
  1336.     return [face, index];
  1337.   }
  1338.  
  1339.   /**
  1340.    * ==========================================================================
  1341.    *
  1342.    * TextManager._getPredefinedFace(object data)
  1343.    *
  1344.    * @param data A JS object containing data for face in the faces file.
  1345.    *
  1346.    * @note
  1347.    *  Checks the given data to see what face should be picked from the faces
  1348.    *  file.
  1349.    *
  1350.    * @return An array of the image filename and index.
  1351.    *
  1352.    * ==========================================================================
  1353.    */
  1354.   $._getPredefinedFace = function(data) {
  1355.     var face, index;
  1356.     if(data.id) {
  1357.       if(this._faces[data.id]) {
  1358.         face  = this._faces[data.id].file;
  1359.         index = this._faces[data.id].index;
  1360.       }
  1361.     }
  1362.     return [face, index];
  1363.   }
  1364.  
  1365.   /**
  1366.    * ==========================================================================
  1367.    *
  1368.    * TextManager._getNormalFace(object data)
  1369.    *
  1370.    * @param data A JS object that contains data about a face for the message.
  1371.    *
  1372.    * @note
  1373.    *  Returns an array with the filename and index as defined in the data.
  1374.    *
  1375.    * @return An array of the image filename and index.
  1376.    *
  1377.    *
  1378.    * ==========================================================================
  1379.    */
  1380.   $._getNormalFace = function(data) {
  1381.     var face, index;
  1382.     if(data.id) {
  1383.       face  = data.id;
  1384.       index = data.index || 0;
  1385.     }
  1386.     return [face, index];
  1387.   }
  1388.  
  1389.   /**
  1390.    * ==========================================================================
  1391.    *
  1392.    * TextManager._getChoiceCallback()
  1393.    *
  1394.    * @note
  1395.    *  This function returns an anonymous function that is called when a choice
  1396.    *  has been made in the choice selection. The function takes one argument,
  1397.    *  the index of the choice selected (starting at 0);
  1398.    *
  1399.    * @return Returns a function that wil be called on choice selection.
  1400.    *
  1401.    * ==========================================================================
  1402.    */
  1403.   $._getChoiceCallback = function(v) {
  1404.     return function(branch) {
  1405.         $gameVariables.setValue([ (v || Number(Zale.ExtText.CHOICEVAR)) ], branch);
  1406.       }
  1407.   }
  1408.  
  1409.   /**
  1410.    * ==========================================================================
  1411.    *
  1412.    * TextManager.setWindowBackground(number type)
  1413.    *
  1414.    * @param type A number to represent the background type
  1415.    *
  1416.    * @note
  1417.    *  0 is normal, 1 is dim, any other number is transparent.
  1418.    *
  1419.    * ==========================================================================
  1420.    */
  1421.   $.setWindowBackground = function(type) {
  1422.     $gameMessage.setBackground(type);
  1423.   }
  1424.  
  1425.   /**
  1426.    * ==========================================================================
  1427.    *
  1428.    * TextManager.setChoiceBackground(number type)
  1429.    *
  1430.    * @param type A number to represen the background type
  1431.    *
  1432.    * @note
  1433.    *  0 is normal, 1 is dim, any otehr number is transparent.
  1434.    *
  1435.    * ==========================================================================
  1436.    */
  1437.   $.setChoiceBackground = function(type) {
  1438.     $gameMessage.setChoiceBackground(type);
  1439.   }
  1440.  
  1441.   /**
  1442.    * ==========================================================================
  1443.    *
  1444.    * TextManager.setWindowPosition(number pos)
  1445.    *
  1446.    * @param pos A number representing the position for the message window.
  1447.    *
  1448.    * @note
  1449.    *  0 is top, 1 is middle, 2 is bottom. Floats are also acceptable to
  1450.    *  further change the position of the window.
  1451.    *
  1452.    * ==========================================================================
  1453.    */
  1454.   $.setWindowPosition = function(pos) {
  1455.     $gameMessage.setPositionType(pos);
  1456.   }
  1457.  
  1458.   /**
  1459.    * ==========================================================================
  1460.    *
  1461.    * TextManager.setChoicePosition(number pos)
  1462.    *
  1463.    * @param pos An integer indicating the position of the choice window.
  1464.    *
  1465.    * @note
  1466.    *  Sets the position of the choice window.
  1467.    *  0 is left, 1 is middle, 2 is right.
  1468.    *
  1469.    * ==========================================================================
  1470.    */
  1471.   $.setChoicePosition = function(pos) {
  1472.     $gameMessage.setChoicePositionType(pos);
  1473.   }
  1474.  
  1475.   /**
  1476.    * ==========================================================================
  1477.    *
  1478.    * TextManager.Function()
  1479.    *
  1480.    * @param pos A number representing the position for the choice window.
  1481.    *
  1482.    * @note
  1483.    *  0 is left, 1 is middle, 2 is right. Floats are also acceptable to
  1484.    *  further change the position of the choice window.
  1485.    *
  1486.    * ==========================================================================
  1487.    */
  1488.   $.setChoiceList = function(v, list, def, can) {
  1489.     $gameMessage.setChoices(list, def, can);
  1490.     $gameMessage.setChoiceCallback(this._getChoiceCallback(v));
  1491.   }
  1492.  
  1493.   /**
  1494.    * ==========================================================================
  1495.    *
  1496.    * TextManager.setFace(array face)
  1497.    *
  1498.    * @param face An array containing a face filename and index
  1499.    *
  1500.    * @note
  1501.    *  Sets the face for the message window to display with the current text.
  1502.    *  The filename is expected to be the first element in the array, with the
  1503.    *  face index being the second.
  1504.    *
  1505.    * ==========================================================================
  1506.    */
  1507.   $.setFace = function(face) {
  1508.     $gameMessage.setFaceImage(face[0], face[1]);
  1509.   }
  1510.  
  1511.   /**
  1512.    * ==========================================================================
  1513.    *
  1514.    * TextManager.setNumberInput(number v, number digits)
  1515.    *
  1516.    * @param v The variable number to store the result in
  1517.    * @params digits The number of digits to allow the input to be.
  1518.    *
  1519.    * @note
  1520.    *  Sets the values eneded for number input in $gameMessage. The
  1521.    *  Game_Message class handles what types of input to display with the text
  1522.    *  itself, depending on what values are set (Number input, Item selection,
  1523.    *  or the choice window).
  1524.    *
  1525.    * ==========================================================================
  1526.    */
  1527.   $.setNumberInput = function(v, digits) {
  1528.     $gameMessage.setNumberInput(v, digits);
  1529.   }
  1530.  
  1531.   /**
  1532.    * ==========================================================================
  1533.    *
  1534.    * TextManager.setItemInput(number v, number type)
  1535.    *
  1536.    * @param v The variable ID to store the selected item's ID in.
  1537.    * @param type A number to determine what type of item may be selected.
  1538.    *
  1539.    * @note
  1540.    *  MV has 4 item types to choose from, Regular, Key, Hidden A, and
  1541.    *  Hidden B. The Hidden A and B item tyes are not displayed in the item
  1542.    *  menu with the default system. They only show up when using an item
  1543.    *  selection. Additionally, the two groups are separate, allowing you to
  1544.    *  keep items separated into the two hidden groups as needed.
  1545.    *  Regular items are type 1.
  1546.    *  Key items are type 2.
  1547.    *  Hidden A items are type 3.
  1548.    *  Hdden B items are type 4.
  1549.    *
  1550.    * ==========================================================================
  1551.    */
  1552.   $.setItemInput = function(v, type) {
  1553.     $gameMessage.setItemChoice(v, type);
  1554.   }
  1555.  
  1556. })(TextManager);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement