Advertisement
Drykul

Expression Spy

Jul 31st, 2016
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //=============================================================================
  2. // ExpressionSpy.js v1.1
  3. //=============================================================================
  4.  
  5. /*:
  6.  * @plugindesc Updates selected expressions in real time in a separate window.
  7.  * <id:Expression Spy>
  8.  * @author Drykul
  9.  *
  10.  * @param Game Variables
  11.  * @desc The $gameVariables to be monitored.                          Ex: 1, 2, 5, 15
  12.  * @default
  13.  *
  14.  * @param Game Switches
  15.  * @desc The $gameSwitches to be monitored.                           Ex: 1, 2, 5, 15
  16.  * @default
  17.  *
  18.  * @param Custom Expressions
  19.  * @desc Custom expressions to be monitored.                          Ex: $gameActors.actor(1).hp, myCustomVar, 1 + 2
  20.  * @default
  21.  *
  22.  * @help
  23.  * The custom expression field can be literally any expression you'd like to
  24.  * monitor, including any calculations. Entries such as
  25.  * $gameActors.actor(1).hp + $gameVariables.value(1)
  26.  * will be accepted and evaluated.
  27.  *
  28.  * If you have any bugs to report, requests, or questions you can contact me
  29.  * at drykul(at)cloud9studios.net. I'm also on www.rpgmakerweb.com and
  30.  * www.rpgmakervxace.net as shaynec1981 as well as www.rpgmakermv.co as drykul.
  31.  *
  32.  * No credit is necessary for use of this script in either free
  33.  * or commercial projects. Just shoot me a line and let me know if it was
  34.  * worth your time! :)
  35.  *
  36.  * /~~CHANGE LOG~~/
  37.  * 3-23-16: 1.1 release - changed update to Game_Screen
  38.  *                      - fixed multiple expression spy windows being open at once
  39.  *                      - expression spy window now won't open if no variables,
  40.  *                        switches, or expressions are specified
  41.  *
  42.  * 3-22-16: 1.0 release
  43.  */
  44.  
  45. ////// Main function
  46. function expressionSpy() {
  47.     if (typeof Scene_Map.prototype.expressionSpyWindow != 'undefined' && typeof Scene_Map.prototype.expressionSpyWindow.document != 'undefined') {
  48.         Scene_Map.prototype.expressionSpyWindow.document.open();
  49.         if (esVariablesArray[0] != "") {
  50.             for (i = 0; i < esVariablesArray.length; i++) {
  51.                 Scene_Map.prototype.expressionSpyWindow.document.write("$gameVariables[" + esVariablesArray[i] + "] = " + $gameVariables.value(esVariablesArray[i]) + "<br>");
  52.             };
  53.             Scene_Map.prototype.expressionSpyWindow.document.write("---------------------------------------------------------------" + "<br>");
  54.         };
  55.         if (esSwitchesArray[0] != "") {
  56.             for (i = 0; i < esSwitchesArray.length; i++) {
  57.                 Scene_Map.prototype.expressionSpyWindow.document.write("$gameSwitches[" + esSwitchesArray[i] + "] = " + $gameSwitches.value(esSwitchesArray[i]) + "<br>");
  58.             };
  59.             Scene_Map.prototype.expressionSpyWindow.document.write("---------------------------------------------------------------" + "<br>");
  60.         };
  61.         if (esExpressionsArray[0] != "") {
  62.             for (i = 0; i < esExpressionsArray.length; i++) {
  63.  
  64.                 try {
  65.                     Scene_Map.prototype.expressionSpyWindow.document.write(esExpressionsArray[i] + " = " + eval(esExpressionsArray[i]) + "<br>");
  66.                 } catch (err) {
  67.                     Scene_Map.prototype.expressionSpyWindow.document.write("Watched expression " + esExpressionsArray[i] + " does not exist!" + "<br>");
  68.                 };
  69.             };
  70.         };
  71.     };
  72. };
  73.  
  74. ////// Create variables and Expression Spy window
  75. var alis_SM_initialize = Scene_Map.prototype.initialize;
  76. Scene_Map.prototype.initialize = function () {
  77.  
  78.     var scriptParameters = $plugins.filter(function (p) {
  79.         return p.description.contains("<id:Expression Spy>")
  80.     })[0].parameters;
  81.  
  82.     esVariablesArray = scriptParameters['Game Variables'].split(",");
  83.     for (i = 0; i < esVariablesArray.length; i++) {
  84.         esVariablesArray[i] = esVariablesArray[i].trim();
  85.     };
  86.     esVariablesArray = uniq(esVariablesArray);
  87.  
  88.     esSwitchesArray = scriptParameters['Game Switches'].split(",");
  89.     for (i = 0; i < esSwitchesArray.length; i++) {
  90.         esSwitchesArray[i] = esSwitchesArray[i].trim();
  91.     };
  92.     esSwitchesArray = uniq(esSwitchesArray);
  93.  
  94.     esExpressionsArray = scriptParameters['Custom Expressions'].split(",");
  95.     esExpressionsArray = uniq(esExpressionsArray);
  96.  
  97.     alis_SM_initialize.call(this);
  98.     if (typeof Scene_Map.prototype.expressionSpyWindow != 'undefined') {
  99.         Scene_Map.prototype.expressionSpyWindow.close();
  100.     };
  101.     if (scriptParameters['Game Variables'] != "" || scriptParameters['Game Switches'] != "" || scriptParameters['Custom Expressions'] != "") {
  102.         Scene_Map.prototype.expressionSpyWindow = window.open();
  103.         Scene_Map.prototype.expressionSpyWindow.resizeTo(800, 400);
  104.         Scene_Map.prototype.expressionSpyWindow.moveTo(0, 300);
  105.         require('nw.gui').Window.get().focus();
  106.     };
  107. };
  108.  
  109.  
  110. ////// Call ExpressionSpy every update frame from Game_Screen
  111. var alias_GS_Update = Game_Screen.prototype.update;
  112. Game_Screen.prototype.update = function () {
  113.     alias_GS_Update.call(this);
  114.     expressionSpy();
  115. };
  116.  
  117.  
  118. ////// Remove duplicate entries from an array
  119. function uniq(a) {
  120.     var seen = {};
  121.     return a.filter(function (item) {
  122.         return seen.hasOwnProperty(item) ? false : (seen[item] = true);
  123.     });
  124. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement