ezmash

Cross Reference Tool (MV)

Dec 22nd, 2016
5,046
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //=============================================================================
  2. // CrossReferenceTool.js
  3. // by Shaz
  4. // last updated 2016.12.22
  5. //=============================================================================
  6.  
  7. /*:
  8.  * @plugindesc Shows database references throughout your project.
  9.  * @author Shaz
  10.  *
  11.  * @help This plugin does not provide plugin commands.
  12.  *
  13.  * This plugin adds a new option to the Title Screen to list all references
  14.  * to all database items throughout your project.
  15.  *
  16.  * The first time you run it when launching the game there will be a delay
  17.  * as the list is built.
  18.  *
  19.  * This tool looks for the \v[#] escape code in all names, descriptions and
  20.  * text that could be displayed, as well as text boxes.  It also looks for
  21.  * the v[#] escape code in damage formulae.
  22.  *
  23.  * This tool does NOT look for any other escape codes, and will not pick up
  24.  * anything introduced by other plugins, or any plugin or script calls, or
  25.  * any other reference in damage formulae.  If you have plugins that introduce
  26.  * new esacpe codes and you want to modify or create an add-on for this plugin
  27.  * to handle them, the functions you should look at are:
  28.  *    XRefManager.scanDbText
  29.  *    XRefManager.scanDmg
  30.  *
  31.  * If the Change Equipment command is used with slot 2, both the weapon and
  32.  * armor with that id will be referenced, as the actor (or class) may or may
  33.  * not have a dual wield trait at the time the command is run.
  34.  *
  35.  */
  36.  
  37.  
  38. // XRef Classes
  39. function Event_Ref() {
  40.   this.initialize.apply(this, arguments);
  41. };
  42.  
  43. Event_Ref.prototype.initialize = function(id, name, page, line) {
  44.   this._id = id;
  45.   this._name = name;
  46.   this._page = page;
  47.   this._line = line;
  48. };
  49.  
  50. function Reference() {
  51.   this.initialize.apply(this, arguments);
  52. };
  53.  
  54. Reference.prototype.initialize = function(objType, objId, srcType, srcId, evt, ref, seq) {
  55.   this._objType = objType;
  56.   this._objId = objId;
  57.   this._srcType = srcType;
  58.   this._srcId = srcId;
  59.   this._evt = evt;
  60.   this._ref = ref;
  61.   this._seq = seq;
  62. };
  63.  
  64. function References() {
  65.   this.initialize.apply(this, arguments);
  66. };
  67.  
  68. References.prototype.initialize = function() {
  69.   this._references = [];
  70. };
  71.  
  72. References.prototype.add = function(ref) {
  73.   this._references.push(ref);
  74. };
  75.  
  76. References.prototype.refs = function() {
  77.   return this._references;
  78. };
  79.  
  80. function Referenced_Objects() {
  81.   this.initialize.apply(this, arguments);
  82. };
  83.  
  84. Referenced_Objects.prototype.initialize = function() {
  85.   this._objects = {};
  86. };
  87.  
  88. Referenced_Objects.prototype.add = function(ref) {
  89.   if (!this._objects[ref._objId]) {
  90.     this._objects[ref._objId] = new References();
  91.   }
  92.   this._objects[ref._objId].add(ref);
  93. };
  94.  
  95. Referenced_Objects.prototype.ids = function() {
  96.   return Object.keys(this._objects);
  97. };
  98.  
  99. Referenced_Objects.prototype.xrefs = function(id) {
  100.   return this._objects[id] ? this._objects[id].refs() : [];
  101. }
  102.  
  103. function Cross_References() {
  104.   this.initialize.apply(this, arguments);
  105. };
  106.  
  107. Cross_References.prototype.initialize = function() {
  108.   this._referencedObjects = {};
  109. };
  110.  
  111. Cross_References.prototype.add = function(ref) {
  112.   if (!this._referencedObjects[ref._objType]) {
  113.     this._referencedObjects[ref._objType] = new Referenced_Objects();
  114.   }
  115.   this._referencedObjects[ref._objType].add(ref);
  116. };
  117.  
  118. Cross_References.prototype.xrefs = function(type, id) {
  119.   return this._referencedObjects[type] ? this._referencedObjects[type].xrefs(id) : [];
  120. };
  121.  
  122. Cross_References.prototype.xrefIds = function(type) {
  123.   return this._referencedObjects[type] ? this._referencedObjects[type].ids() : [];
  124. };
  125.  
  126. Cross_References.prototype.xrefTypes = function() {
  127.   return Object.keys(this._referencedObjects);
  128. };
  129.  
  130. // XRef Manager
  131. function XRefManager() {
  132.   throw new Error('This is a static class');
  133. };
  134.  
  135. XRefManager._crossReferences = new Cross_References();
  136. XRefManager._isLoaded = false;
  137. XRefManager._cmdCode = null;
  138. XRefManager._eventId = null;
  139. XRefManager._eventName = null;
  140. XRefManager._eventPage = null;
  141. XRefManager._eventLine = null;
  142. XRefManager._srcType = null;
  143. XRefManager._srcId = null;
  144.  
  145. XRefManager.dataSources = function(sym) {
  146.   switch (sym) {
  147.     case 'switch' :      return $dataSystem.switches;    break;
  148.     case 'variable' :    return $dataSystem.variables;   break;
  149.     case 'commonEvent' : return $dataCommonEvents;       break;
  150.     case 'actor' :       return $dataActors;             break;
  151.     case 'class' :       return $dataClasses;            break;
  152.     case 'skill' :       return $dataSkills;             break;
  153.     case 'item' :        return $dataItems;              break;
  154.     case 'weapon' :      return $dataWeapons;            break;
  155.     case 'armor' :       return $dataArmors;             break;
  156.     case 'enemy' :       return $dataEnemies;            break;
  157.     case 'troop' :       return $dataTroops;             break;
  158.     case 'state' :       return $dataStates;             break;
  159.     case 'animation' :   return $dataAnimations;         break;
  160.     case 'map' :         return $dataMapInfos;           break;
  161.   }
  162. };
  163.  
  164. XRefManager.dataTitles = function(sym) {
  165.   switch (sym) {
  166.     case 'switch' :      return 'Switch';        break;
  167.     case 'variable' :    return 'Variable';      break;
  168.     case 'commonEvent' : return 'Common Event';  break;
  169.     case 'actor' :       return 'Actor';         break;
  170.     case 'class' :       return 'Class';         break;
  171.     case 'skill' :       return 'Skill';         break;
  172.     case 'item' :        return 'Item';          break;
  173.     case 'weapon' :      return 'Weapon';        break;
  174.     case 'armor' :       return 'Armor';         break;
  175.     case 'enemy' :       return 'Enemy';         break;
  176.     case 'troop' :       return 'Troop';         break;
  177.     case 'state' :       return 'State';         break;
  178.     case 'animation' :   return 'Animation';     break;
  179.     case 'map' :         return 'Map';           break;
  180.   }
  181. };
  182.  
  183. XRefManager.command = function(code) {
  184.   switch (code) {
  185.     case 401 : return 'Show Text';              break;
  186.     case 102 : return 'Show Choices';           break;
  187.     case 103 : return 'Input Number';           break;
  188.     case 104 : return 'Select Item';            break;
  189.     case 405 : return 'Show Scrolling Text';    break;
  190.     case 111 : return 'Conditional Branch';     break;
  191.     case 119 : return 'Common Event';           break;
  192.     case 121 : return 'Control Switches';       break;
  193.     case 122 : return 'Control Variables';      break;
  194.     case 125 : return 'Change Gold';            break;
  195.     case 126 : return 'Change Items';           break;
  196.     case 127 : return 'Change Weapons';         break;
  197.     case 128 : return 'Change Armors';          break;
  198.     case 129 : return 'Change Party Member';    break;
  199.     case 201 : return 'Transfer Player';        break;
  200.     case 202 : return 'Set Vehicle Location';   break;
  201.     case 203 : return 'Set Event Location';     break;
  202.     case 505 : return 'Set Movement Route';     break;
  203.     case 212 : return 'Show Animation';         break;
  204.     case 231 : return 'Show Picture';           break;
  205.     case 232 : return 'Move Picture';           break;
  206.     case 285 : return 'Get Location Info';      break;
  207.     case 301 : return 'Battle Processing';      break;
  208.     case 302 :
  209.     case 605 : return 'Shop Processing';        break;
  210.     case 303 : return 'Name Input Processing';  break;
  211.     case 311 : return 'Change HP';              break;
  212.     case 312 : return 'Change MP';              break;
  213.     case 326 : return 'Change TP';              break;
  214.     case 313 : return 'Change State';           break;
  215.     case 314 : return 'Recover All';            break;
  216.     case 315 : return 'Change EXP';             break;
  217.     case 316 : return 'Change Level';           break;
  218.     case 317 : return 'Change Parameter';       break;
  219.     case 318 : return 'Change Skill';           break;
  220.     case 319 : return 'Change Equipment';       break;
  221.     case 320 : return 'Change Name';            break;
  222.     case 321 : return 'Change Class';           break;
  223.     case 322 : return 'Change Actor Images';    break;
  224.     case 324 : return 'Change Nickname';        break;
  225.     case 325 : return 'Change Profile';         break;
  226.     case 331 : return 'Change Enemy HP';        break;
  227.     case 332 : return 'Change Enemy MP';        break;
  228.     case 342 : return 'Change Enemy TP';        break;
  229.     case 333 : return 'Change Enemy State';     break;
  230.     case 336 : return 'Enemy Transform';        break;
  231.     case 337 : return 'Show Battle Animation';  break;
  232.     case 339 : return 'Force Action';           break;
  233.     default : return code;
  234.   }
  235. };
  236.  
  237. XRefManager.objName = function(objType, objId) {
  238.   switch (objType) {
  239.     case 'switch':
  240.     case 'variable':
  241.       return this.dataSources(objType)[objId];
  242.       break;
  243.     default:
  244.       return this.dataSources(objType)[objId] ? this.dataSources(objType)[objId].name : '';
  245.   }
  246. };
  247.  
  248. XRefManager.objTypes = function() {
  249.   return this._crossReferences.xrefTypes();
  250. };
  251.  
  252. XRefManager.refs = function(objType, objId) {
  253.   return this._crossReferences.xrefs(objType, objId);
  254. };
  255.  
  256. XRefManager.loadReferences = function() {
  257.   if (this._isLoaded) return;
  258.  
  259.   console.log('Building list of cross references.  Back in a sec ...');
  260.  
  261.   $dataActors.forEach(function(actor) {             this.buildActorXRefs(actor); }.bind(this));
  262.   $dataClasses.forEach(function(cls) {              this.buildClassXRefs(cls); }.bind(this));
  263.   $dataSkills.forEach(function(skill) {             this.buildSkillXRefs(skill); }.bind(this));
  264.   $dataItems.forEach(function(item) {               this.buildItemXRefs(item); }.bind(this));
  265.   $dataWeapons.forEach(function(weapon) {           this.buildWeaponXRefs(weapon); }.bind(this));
  266.   $dataArmors.forEach(function(armor) {             this.buildArmorXRefs(armor); }.bind(this));
  267.   $dataEnemies.forEach(function(enemy) {            this.buildEnemyXRefs(enemy); }.bind(this));
  268.   $dataTroops.forEach(function(troop) {             this.buildTroopXRefs(troop); }.bind(this));
  269.   $dataStates.forEach(function(state) {             this.buildStateXRefs(state); }.bind(this));
  270.   $dataCommonEvents.forEach(function(commonEvent) { this.buildCommonEventXRefs(commonEvent); }.bind(this));
  271.   $dataMapInfos.forEach(function(mapInfo) {         this.buildMapXRefs(mapInfo); }.bind(this));
  272.  
  273.   this._isLoaded = true;
  274. };
  275.  
  276. XRefManager.save = function(objType, objId, ref, seq) {
  277.   ref = ref || this._cmdCode;
  278.   seq = seq || null;
  279.   var evt = null;
  280.   if (this._eventId || this._eventPage || this._eventLine) {
  281.     evt = new Event_Ref(this._eventId, this._eventName, this._eventPage, this._eventLine);
  282.   }
  283.  
  284.   var xref = new Reference(objType, objId, this._srcType, this._srcId, evt, ref, seq);
  285.   this._crossReferences.add(xref);
  286. };
  287.  
  288. XRefManager.scanDbText = function(text, ref) {
  289.   ref = ref || this._cmdCode;
  290.   seq = 0;
  291.   var regExp = /\\v\[(\d+)\]/gim;
  292.   for (;;) {
  293.     var array = regExp.exec(text);
  294.     if (array) {
  295.       this.save('variable', array[1], ref, seq);
  296.       seq++;
  297.     } else {
  298.       break;
  299.     }
  300.   }
  301. };
  302.  
  303. XRefManager.scanDmg = function(dmg, ref) {
  304.   seq = 0;
  305.   var regExp = /v\[(\d+)\]/gim;
  306.   for (;;) {
  307.     var array = regExp.exec(dmg);
  308.     if (array) {
  309.       this.save('variable', array[1], ref, seq);
  310.       seq++;
  311.     } else {
  312.       break;
  313.     }
  314.   }
  315. }
  316.  
  317. XRefManager.scanTraits = function(traits) {
  318.   traits.forEach(function(trait, index) {
  319.     switch (trait.code) {
  320.       case Game_BattlerBase.TRAIT_STATE_RATE:
  321.       case Game_BattlerBase.TRAIT_STATE_RESIST:
  322.       case Game_BattlerBase.TRAIT_ATTACK_STATE:
  323.         this.save('state', trait.dataId, 'trait', index);
  324.         break;
  325.       case Game_BattlerBase.TRAIT_SKILL_ADD:
  326.       case Game_BattlerBase.TRAIT_SKILL_SEAL:
  327.         this.save('skill', trait.dataId, 'trait', index);
  328.         break;
  329.     }
  330.   }.bind(this));
  331. };
  332.  
  333. XRefManager.scanEffects = function(effects) {
  334.   effects.forEach(function(effect, index) {
  335.     switch(effect.code) {
  336.       case Game_Action.EFFECT_ADD_STATE:
  337.       case Game_Action.EFFECT_REMOVE_STATE:
  338.         this.save('state', effect.dataId, 'effect', index);
  339.         break;
  340.       case Game_Action.EFFECT_LEARN_SKILL:
  341.         this.save('skill', effect.dataId, 'effect', index);
  342.         break;
  343.       case Game_Action.EFFECT_COMMON_EVENT:
  344.         this.save('commonEvent', effect.dataId, 'effect', index);
  345.         break;
  346.     }
  347.   }.bind(this));
  348. }
  349.  
  350. XRefManager.buildActorXRefs = function(actor) {
  351.   if (!actor) return;
  352.  
  353.   this._srcType = 'actor';
  354.   this._srcId = actor.id;
  355.  
  356.   // text fields
  357.   this.scanDbText(actor.name, 'name');
  358.   this.scanDbText(actor.nickname, 'nickname');
  359.   this.scanDbText(actor.profile, 'profile');
  360.  
  361.   // class
  362.   this.save('class', actor.classId, 'class');
  363.  
  364.   // starting equipment
  365.   actor.equips.forEach(function(equip, slot) {
  366.     if (equip !== 0) {
  367.       if (slot === 0 ||
  368.         (slot === 1 && actor.traits.concat($dataClasses[actor.classId].traits).some(function(trait) {
  369.           return trait.code === Game_BattlerBase.TRAIT_SLOT_TYPE && trait.dataId === 1; // dual wield
  370.         }.bind(this)))) {
  371.         this.save('weapon', equip, 'equip', slot);
  372.       } else {
  373.         this.save('armor', equip, 'equip', slot);
  374.       }
  375.     }
  376.   }.bind(this));
  377.  
  378.   // traits
  379.   this.scanTraits(actor.traits);
  380. };
  381.  
  382. XRefManager.buildClassXRefs = function(cls) {
  383.   if (!cls) return;
  384.  
  385.   this._srcType = 'class';
  386.   this._srcId = cls.id;
  387.  
  388.   // text fields
  389.   this.scanDbText(cls.name, 'name');
  390.  
  391.   // learnings
  392.   cls.learnings.forEach(function(learning, index) {
  393.     if (learning.skillId) {
  394.       this.save('skill', learning.skillId, 'learnings', index);
  395.     }
  396.   }.bind(this));
  397.  
  398.   // traits
  399.   this.scanTraits(cls.traits);
  400. };
  401.  
  402. XRefManager.buildSkillXRefs = function(skill) {
  403.   if (!skill) return;
  404.  
  405.   this._srcType = 'skill';
  406.   this._srcId = skill.id;
  407.  
  408.   // text fields
  409.   this.scanDbText(skill.name, 'name');
  410.   this.scanDbText(skill.description, 'description');
  411.   this.scanDbText(skill.message1, 'message1');
  412.   this.scanDbText(skill.message2, 'message2');
  413.  
  414.   // damage formula
  415.   this.scanDmg(skill.damage.formula, 'damage');
  416.  
  417.   // animation
  418.   if (skill.animationId !== 0) {
  419.     this.save('animation', skill.animationId, 'animation');
  420.   }
  421.  
  422.   // effects
  423.   this.scanEffects(skill.effects);
  424. };
  425.  
  426. XRefManager.buildItemXRefs = function(item) {
  427.   if (!item) return;
  428.  
  429.   this._srcType = 'item';
  430.   this._srcId = item.id;
  431.  
  432.   // text fields
  433.   this.scanDbText(item.name, 'name');
  434.   this.scanDbText(item.description, 'description');
  435.  
  436.   // damage formula
  437.   this.scanDmg(item.damage.formula, 'damage');
  438.  
  439.   // animation
  440.   if (item.animationId !== 0) {
  441.     this.save('animation', item.animationId, 'animation');
  442.   }
  443.  
  444.   // effects
  445.   this.scanEffects(item.effects);
  446. };
  447.  
  448. XRefManager.buildWeaponXRefs = function(weapon) {
  449.   if (!weapon) return;
  450.  
  451.   this._srcType = 'weapon';
  452.   this._srcId = weapon.id;
  453.  
  454.   // text fields
  455.   this.scanDbText(weapon.name, 'name');
  456.   this.scanDbText(weapon.description, 'description');
  457.  
  458.   // animation
  459.   if (weapon.animationId !== 0) {
  460.     this.save('animation', weapon.animationId, 'animation');
  461.   }
  462.  
  463.   // traits
  464.   this.scanTraits(weapon.traits);
  465. }
  466.  
  467. XRefManager.buildArmorXRefs = function(armor) {
  468.   if (!armor) return;
  469.  
  470.   this._srcType = 'armor';
  471.   this._srcId = armor.id;
  472.  
  473.   // text fields
  474.   this.scanDbText(armor.name, 'name');
  475.   this.scanDbText(armor.description, 'description');
  476.  
  477.   //traits
  478.   this.scanTraits(armor.traits);
  479. };
  480.  
  481. XRefManager.buildEnemyXRefs = function(enemy) {
  482.   if (!enemy) return;
  483.  
  484.   this._srcType = 'enemy';
  485.   this._srcId = enemy.id;
  486.  
  487.   // text fields
  488.   this.scanDbText(enemy.name, 'name');
  489.  
  490.   // drop items
  491.   enemy.dropItems.forEach(function(dropItem, index) {
  492.     if (dropItem.kind !== 0) {
  493.       var kind = ['', 'item', 'weapon', 'armor'][dropItem.kind];
  494.       this.save(kind, dropItem.dataId, 'dropItem', index);
  495.     }
  496.   }.bind(this));
  497.  
  498.   // action patterns
  499.   enemy.actions.forEach(function(action, index) {
  500.     this.save('skill', action.skillId, 'actionPattern', index);
  501.     switch (action.conditionType) {
  502.       case 4:
  503.         this.save('state', action.conditionParam1, 'actionPattern', index);
  504.         break;
  505.       case 6:
  506.         this.save('switch', action.conditionParam1, 'actionPattern', index);
  507.         break;
  508.     }
  509.   }.bind(this));
  510.  
  511.   // traits
  512.   this.scanTraits(enemy.traits);
  513. };
  514.  
  515. XRefManager.buildTroopXRefs = function(troop) {
  516.   if (!troop) return;
  517.  
  518.   this._srcType = 'troop';
  519.   this._srcId = troop.id;
  520.   this._eventName = null;
  521.  
  522.   // text fields
  523.   this.scanDbText(troop.name, 'name');
  524.  
  525.   // members
  526.   troop.members.forEach(function(enemy, index) {
  527.     this.save('enemy', enemy.enemyId, 'members', index);
  528.   }.bind(this));
  529.  
  530.   // pages
  531.   troop.pages.forEach(function(page, index) {
  532.     this._eventPage = index + 1;
  533.     this._eventLine = 0;
  534.  
  535.     // page conditions
  536.     if (page.conditions.actorValid) {
  537.       this.save('actor', page.conditions.actorId, 'conditions', this._eventPage);
  538.     }
  539.     if (page.conditions.switchValid) {
  540.       this.save('switch', page.conditions.switchId, 'conditions', this._eventPage);
  541.     }
  542.  
  543.     // event commands
  544.     this.buildEventXRefs(page.list);
  545.  
  546.     this._eventPage = null;
  547.     this._eventLine = null;
  548.   }.bind(this));
  549. };
  550.  
  551. XRefManager.buildStateXRefs = function(state) {
  552.   if (!state) return;
  553.  
  554.   this._srcType = 'state';
  555.   this._srcId = state.id;
  556.  
  557.   // text fields
  558.   this.scanDbText(state.name, 'name');
  559.   this.scanDbText(state.message1, 'message1');
  560.   this.scanDbText(state.message2, 'message2');
  561.   this.scanDbText(state.message3, 'message3');
  562.   this.scanDbText(state.message4, 'message4');
  563.  
  564.   // traits
  565.   this.scanTraits(state.traits);
  566. };
  567.  
  568. XRefManager.buildCommonEventXRefs = function(commonEvent) {
  569.   if (!commonEvent) return;
  570.  
  571.   this._srcType = 'commonEvent';
  572.   this._srcId = commonEvent.id;
  573.   this._eventPage = 1;
  574.   this._eventLine = 0;
  575.   this._eventName = null;
  576.  
  577.   // conditions
  578.   if (commonEvent.trigger !== 0) {
  579.     this.save('switch', commonEvent.switchId, 'conditions');
  580.   }
  581.  
  582.   // event commands
  583.   this.buildEventXRefs(commonEvent.list);
  584.  
  585.   this._eventPage = null;
  586.   this._eventLine = null;
  587. };
  588.  
  589. XRefManager.buildMapXRefs = function(mapInfo) {
  590.   if (!mapInfo) return;
  591.  
  592.   this._srcType = 'map';
  593.   this._srcId = mapInfo.id;
  594.   this._eventId = null;
  595.   this._eventName = null;
  596.   this._eventPage = null;
  597.   this._eventLine = null;
  598.  
  599.   var filename = 'data/Map%1.json'.format(mapInfo.id.padZero(3));
  600.   var fs = require('fs');
  601.   var path = require('path');
  602.   var base = path.dirname(process.mainModule.filename);
  603.   path = path.join(base, filename);
  604.   var map = JSON.parse(fs.readFileSync(path));
  605.  
  606.   // text fields
  607.   this.scanDbText(mapInfo.name, 'name');
  608.   this.scanDbText(map.displayName, 'displayName');
  609.  
  610.   // encounter list
  611.   map.encounterList.forEach(function(troop, index) {
  612.     this.save('troop', troop.troopId, 'encounters', index);
  613.   }.bind(this));
  614.  
  615.   // events
  616.   map.events.forEach(function(event) {
  617.     if (event && event.pages.length > 0) {
  618.       this._eventId = event.id;
  619.       this._eventName = event.name;
  620.       this._eventPage = 0;
  621.       this._eventLine = 0;
  622.  
  623.       // text fields
  624.       this.scanDbText(event.name, 'name');
  625.  
  626.       // pages
  627.       event.pages.forEach(function(page, index) {
  628.         this._eventPage = index + 1;
  629.         this._eventLine = 0;
  630.  
  631.         // conditions
  632.         var cond = page.conditions;
  633.         if (cond.actorValid) {
  634.           this.save('actor', cond.actorId, 'conditions', this._eventPage);
  635.         }
  636.         if (cond.itemValid) {
  637.           this.save('item', cond.itemId, 'conditions', this._eventPage);
  638.         }
  639.         if (cond.switch1Valid) {
  640.           this.save('switch', cond.switch1Id, 'conditions', this._eventPage);
  641.         }
  642.         if (cond.switch2Valid) {
  643.           this.save('switch', cond.switch2Id, 'conditions', this._eventPage);
  644.         }
  645.         if (cond.variableValid) {
  646.           this.save('variable', cond.variableId, 'conditions', this._eventPage);
  647.         }
  648.  
  649.         // event commands
  650.         this.buildEventXRefs(page.list);
  651.  
  652.         this._eventPage = null;
  653.         this._eventLine = null;
  654.       }.bind(this));
  655.     }
  656.   }.bind(this));
  657. };
  658.  
  659. XRefManager.buildEventXRefs = function(list) {
  660.   if (!list) return;
  661.  
  662.   list.forEach(function(command, index) {
  663.     this._eventLine = index + 1;
  664.  
  665.     if (command) {
  666.       this._params = command.parameters;
  667.       this._cmdCode = command.code;
  668.       var methodName = 'command' + command.code;
  669.       if (typeof this[methodName] === 'function') {
  670.         this[methodName]();
  671.       }
  672.     }
  673.   }.bind(this));
  674. };
  675.  
  676. // Show Text
  677. XRefManager.command401 = function() {
  678.   this.scanDbText(this._params[0]);
  679. };
  680.  
  681. // Show Choices
  682. XRefManager.command102 = function() {
  683.   this._params[0].forEach(function(choice) {
  684.     this.scanDbText(choice);
  685.   }.bind(this));
  686. };
  687.  
  688. // Input Number
  689. XRefManager.command103 = function() {
  690.   this.save('variable', this._params[0]);
  691. };
  692.  
  693. // Select item
  694. XRefManager.command104 = function() {
  695.   this.save('variable', this._params[0]);
  696. };
  697.  
  698. // Show Scrolling Text
  699. XRefManager.command405 = function() {
  700.   this.scanDbText(this._params[0]);
  701. };
  702.  
  703. // Conditional Branch
  704. XRefManager.command111 = function() {
  705.   switch (this._params[0]) {
  706.     case 0:
  707.       this.save('switch', this._params[1]);
  708.       break;
  709.     case 1:
  710.       this.save('variable', this._params[1]);
  711.       if (this._params[2] !== 0) {
  712.         this.save('variable', this._params[3]);
  713.       }
  714.       break;
  715.     case 4:
  716.       this.save('actor', this._params[1]);
  717.       if (this._params[2] == 1) {
  718.         this.scanDbText(this._params[3]);
  719.       } else if (this._params[2] >= 2 && this._params[2] <= 6) {
  720.         this.save(['', '', 'class', 'skill', 'weapon', 'armor', 'state'][this._params[2]], this._params[3]);
  721.       }
  722.       break;
  723.     case 5:
  724.       if (this._params[2] === 1) { // enemy state
  725.         this.save('state', this._params[3]);
  726.       }
  727.       break;
  728.     case 8:
  729.       this.save('item', this._params[1]);
  730.       break;
  731.     case 9:
  732.       this.save('weapon', this._params[1]);
  733.       break;
  734.     case 10:
  735.       this.save('armor', this._params[1]);
  736.       break;
  737.   }
  738. };
  739.  
  740. // Common Event
  741. XRefManager.command117 = function() {
  742.   this.save('commonEvent', this._params[0]);
  743. };
  744.  
  745. // Control Switches
  746. XRefManager.command121 = function() {
  747.   for (var i = this._params[0]; i <= this._params[1]; i++) {
  748.     this.save('switch', i);
  749.   }
  750. };
  751.  
  752. // Control Variables
  753. XRefManager.command122 = function() {
  754.   if (this._params[3] === 1) {
  755.     this.save('variable', this._params[4]);
  756.   } else if (this._params[3] === 3 && this._params[4] <= 3) {
  757.     this.save(['item', 'weapon', 'armor', 'actor'][this._params[4]], this._params[5]);
  758.   }
  759.  
  760.   for (var i = this._params[0]; i <= this._params[1]; i++) {
  761.     this.save('variable', i);
  762.   }
  763. };
  764.  
  765. // Change Gold
  766. XRefManager.command125 = function() {
  767.   if (this._params[1] !== 0) {
  768.     this.save('variable', this._params[2]);
  769.   }
  770. };
  771.  
  772. // Change Items
  773. XRefManager.command126 = function() {
  774.   this.save('item', this._params[0]);
  775.   if (this._params[2] !== 0) {
  776.     this.save('variable', this._params[3]);
  777.   }
  778. };
  779.  
  780. // Change Weapons
  781. XRefManager.command127 = function() {
  782.   this.save('weapon', this._params[0]);
  783.   if (this._params[2] !== 0) {
  784.     this.save('variable', this._params[3]);
  785.   }
  786. };
  787.  
  788. // Change Armors
  789. XRefManager.command128 = function() {
  790.   this.save('armor', this._params[0]);
  791.   if (this._params[2] !== 0) {
  792.     this.save('variable', this._params[3]);
  793.   }
  794. };
  795.  
  796. // Change Party Member
  797. XRefManager.command129 = function() {
  798.   this.save('actor', this._params[0]);
  799. };
  800.  
  801. // Transfer Player
  802. XRefManager.command201 = function() {
  803.   if (this._params[0] !== 0) {
  804.     this.save('variable', this._params[1]);
  805.     this.save('variable', this._params[2]);
  806.     this.save('variable', this._params[3]);
  807.   }
  808. };
  809.  
  810. // Set Vehicle Location
  811. XRefManager.command202 = function() {
  812.   if (this._params[1] !== 0) {
  813.     this.save('variable', this._params[2]);
  814.     this.save('variable', this._params[3]);
  815.     this.save('variable', this._params[4]);
  816.   }
  817. };
  818.  
  819. // Set Event Location
  820. XRefManager.command203 = function() {
  821.   if (this._params[1] === 1) {
  822.     this.save('variable', this._params[2]);
  823.     this.save('variable', this._params[3]);
  824.   }
  825. };
  826.  
  827. // Set Movement Route (control switches)
  828. XRefManager.command505 = function() {
  829.   if (this._params[0].code === 27 || this._params[0].code === 28) {
  830.     this.save('switch', this._params[0].parameters[0]);
  831.   }
  832. };
  833.  
  834. // Show Animation
  835. XRefManager.command212 = function() {
  836.   this.save('animation', this._params[1]);
  837. };
  838.  
  839. // Show Picture
  840. XRefManager.command231 = function() {
  841.   if (this._params[3] !==  0) {
  842.     this.save('variable', this._params[4]);
  843.     this.save('variable', this._params[5]);
  844.   }
  845. };
  846.  
  847. // Move Picture
  848. XRefManager.command232 = function() {
  849.   if (this._params[3] !== 0) {
  850.     this.save('variable', this._params[4]);
  851.     this.save('variable', this._params[5]);
  852.   }
  853. };
  854.  
  855. // Get Location Info
  856. XRefManager.command285 = function() {
  857.   this.save('variable', this._params[0]);
  858.   if (this._params[2] !== 0) {
  859.     this.save('variable', this._params[3]);
  860.     this.save('variable', this._params[4]);
  861.   }
  862. };
  863.  
  864. // Battle Processing
  865. XRefManager.command301 = function() {
  866.   if (this._params[0] === 0) {
  867.     this.save('troop', this._params[1]);
  868.   } else if (this._params[0] === 1) {
  869.     this.save('variable', this._params[1]);
  870.   }
  871. };
  872.  
  873. // Shop Processing
  874. XRefManager.command302 = function() {
  875.   this.save(['item', 'weapon', 'armor'][this._params[0]], this._params[1]);
  876. };
  877.  
  878. XRefManager.command605 = function() {
  879.   this.save(['item', 'weapon', 'armor'][this._params[0]], this._params[1]);
  880. };
  881.  
  882. // Name Input Processing
  883. XRefManager.command303 = function() {
  884.   this.save('actor', this._params[0]);
  885. };
  886.  
  887. // Change HP
  888. XRefManager.command311 = function() {
  889.   this.save(['actor', 'variable'][this._params[0]], this._params[1]);
  890.   if (this._params[3] !== 0) {
  891.     this.save('variable', this._params[4]);
  892.   }
  893. };
  894.  
  895. // Change MP
  896. XRefManager.command312 = function() {
  897.   this.save(['actor', 'variable'][this._params[0]], this._params[1]);
  898.   if (this._params[3] !== 0) {
  899.     this.save('variable', this._params[4]);
  900.   }
  901. };
  902.  
  903. // Change TP
  904. XRefManager.command326 = function() {
  905.   this.save(['actor', 'variable'][this._params[0]], this._params[1]);
  906.   if (this._params[3] !== 0) {
  907.     this.save('variable', this._params[4]);
  908.   }
  909. };
  910.  
  911. // Change State
  912. XRefManager.command313 = function() {
  913.   this.save(['actor', 'variable'][this._params[0]], this._params[1]);
  914.   this.save('state', this._params[3]);
  915. };
  916.  
  917. // Recover All
  918. XRefManager.command314 = function() {
  919.   this.save(['actor', 'variable'][this._params[0]], this._params[1]);
  920. };
  921.  
  922. // Change EXP
  923. XRefManager.command315 = function() {
  924.   this.save(['actor', 'variable'][this._params[0]], this._params[1]);
  925.   if (this._params[3] !== 0) {
  926.     this.save('variable', this._params[4]);
  927.   }
  928. };
  929.  
  930. // Change Level
  931. XRefManager.command316 = function() {
  932.   this.save(['actor', 'variable'][this._params[0]], this._params[1]);
  933.   if (this._params[3] !== 0) {
  934.     this.save('variable', this._params[4]);
  935.   }
  936. };
  937.  
  938. // Change Parameter
  939. XRefManager.command317 = function() {
  940.   this.save(['actor', 'variable'][this._params[0]], this._params[1]);
  941.   if (this._params[4] !== 0) {
  942.     this.save('variable', this._params[5]);
  943.   }
  944. };
  945.  
  946. // Change skill
  947. XRefManager.command318 = function() {
  948.   this.save('skill', this._params[3]);
  949.   this.save(['actor', 'variable'][this._params[0]], this._params[1]);
  950. };
  951.  
  952. // Change Equipment
  953. XRefManager.command319 = function() {
  954.   // Slot 1 could be either a weapon or an armor item, depending on whether
  955.   // the actor has dual-wield ability.  This could change mid-game if their
  956.   // class is changed, so slot 1 reports as both a weapon and an armor item
  957.   this.save('actor', this._params[0]);
  958.   if (this._params[1] < 3) { // slot 1 or 2
  959.     this.save('weapon', this._params[2]);
  960.   }
  961.   if (this._params[1] > 1) { // slots 2, 3, 4 or 5
  962.     this.save('armor', this._params[2]);
  963.   }
  964. };
  965.  
  966. // Change Name
  967. XRefManager.command320 = function() {
  968.   this.save('actor', this._params[0]);
  969.   this.scanDbText(this._params[1], 'name');
  970. };
  971.  
  972. // Change Class
  973. XRefManager.command321 = function() {
  974.   this.save('actor', this._params[0]);
  975.   this.save('class', this._params[1]);
  976. };
  977.  
  978. // Change Actor Images
  979. XRefManager.command322 = function() {
  980.   this.save('actor', this._params[0]);
  981. };
  982.  
  983. // Change Nickname
  984. XRefManager.command324 = function() {
  985.   this.save('actor', this._params[0]);
  986.   this.scanDbText(this._params[1], 'nickname');
  987. };
  988.  
  989. // Change Profile
  990. XRefManager.command325 = function() {
  991.   this.save('actor', this._params[0]);
  992.   this.scanDbText(this._params[1], 'profile');
  993. };
  994.  
  995. // Change Enemy HP
  996. XRefManager.command331 = function() {
  997.   if (this._params[2] !== 0) {
  998.     this.save('variable', this._params[3]);
  999.   }
  1000. };
  1001.  
  1002. // Change Enemy MP
  1003. XRefManager.command332 = function() {
  1004.   if (this._params[2] !== 0) {
  1005.     this.save('variable', this._params[3]);
  1006.   }
  1007. };
  1008.  
  1009. // Change Enemy TP
  1010. XRefManager.command342 = function() {
  1011.   if (this._params[2] !== 0) {
  1012.     this.save('variable', this._params[3]);
  1013.   }
  1014. };
  1015.  
  1016. // Change Enemy State
  1017. XRefManager.command333 = function() {
  1018.   this.save('state', this._params[2]);
  1019. };
  1020.  
  1021. // Enemy Transform
  1022. XRefManager.command336 = function() {
  1023.   this.save('enemy', this._params[1]);
  1024. };
  1025.  
  1026. // Show Battle Animation
  1027. XRefManager.command337 = function() {
  1028.   this.save('animation', this._params[1]);
  1029. };
  1030.  
  1031. // Force Action
  1032. XRefManager.command339 = function() {
  1033.   this.save('skill', this._params[2]);
  1034.   if (this._params[0] !== 0) {
  1035.     this.save('actor', this._params[1]);
  1036.   }
  1037. };
  1038.  
  1039.  
  1040.  
  1041.  
  1042.  
  1043. // Title Screen
  1044.  
  1045. var _Window_TitleCommand_makeCommandList = Window_TitleCommand.prototype.makeCommandList;
  1046. Window_TitleCommand.prototype.makeCommandList = function() {
  1047.   _Window_TitleCommand_makeCommandList.call(this);
  1048.   this.addCommand('XRef', 'xref', $gameTemp.isPlaytest());
  1049. };
  1050.  
  1051. var _Scene_Title_createCommandWindow = Scene_Title.prototype.createCommandWindow;
  1052. Scene_Title.prototype.createCommandWindow = function() {
  1053.   _Scene_Title_createCommandWindow.call(this);
  1054.   this._commandWindow.setHandler('xref', this.commandXRef.bind(this));
  1055. };
  1056.  
  1057. Scene_Title.prototype.commandXRef = function() {
  1058.   XRefManager.loadReferences();
  1059.   SceneManager.push(Scene_XRef);
  1060. };
  1061.  
  1062.  
  1063.  
  1064.  
  1065. // XRef Command Window
  1066.  
  1067. function Window_XRefCommand() {
  1068.   this.initialize.apply(this, arguments);
  1069. }
  1070.  
  1071. Window_XRefCommand.prototype = Object.create(Window_Command.prototype);
  1072. Window_XRefCommand.prototype.construction = Window_XRefCommand;
  1073.  
  1074. Window_XRefCommand.prototype.initialize = function(x, y) {
  1075.   Window_Command.prototype.initialize.call(this, x, y);
  1076.   this.selectLast();
  1077. };
  1078.  
  1079. Window_XRefCommand._lastCommandSymbol = null;
  1080.  
  1081. Window_XRefCommand.initCommandPosition = function() {
  1082.   this._lastCommandSymbol = null;
  1083. };
  1084.  
  1085. Window_XRefCommand.prototype.standardFontSize = function() {
  1086.   return 24;
  1087. }
  1088.  
  1089. Window_XRefCommand.prototype.windowWidth = function() {
  1090.   return 200;
  1091. };
  1092.  
  1093. Window_XRefCommand.prototype.numVisibleRows = function() {
  1094.   return this.maxItems();
  1095. };
  1096.  
  1097. Window_XRefCommand.prototype.makeCommandList = function() {
  1098.   this.addCommand('Switches',       'switch',       XRefManager.objTypes().contains('switch'));
  1099.   this.addCommand('Variables',      'variable',     XRefManager.objTypes().contains('variable'));
  1100.   this.addCommand('Actors',         'actor',        XRefManager.objTypes().contains('actor'));
  1101.   this.addCommand('Classes',        'class',        XRefManager.objTypes().contains('class'));
  1102.   this.addCommand('Skills',         'skill',        XRefManager.objTypes().contains('skill'));
  1103.   this.addCommand('Items',          'item',         XRefManager.objTypes().contains('item'));
  1104.   this.addCommand('Weapons',        'weapon',       XRefManager.objTypes().contains('weapon'));
  1105.   this.addCommand('Armors',         'armor',        XRefManager.objTypes().contains('armor'));
  1106.   this.addCommand('Enemies',        'enemy',        XRefManager.objTypes().contains('enemy'));
  1107.   this.addCommand('Troops',         'troop',        XRefManager.objTypes().contains('troop'));
  1108.   this.addCommand('States',         'state',        XRefManager.objTypes().contains('state'));
  1109.   this.addCommand('Animations',     'animation',    XRefManager.objTypes().contains('animation'));
  1110.   this.addCommand('Common Events',  'commonEvent',  XRefManager.objTypes().contains('commonEvent'));
  1111. };
  1112.  
  1113. Window_XRefCommand.prototype.update = function() {
  1114.   Window_Command.prototype.update.call(this);
  1115.   if (this._selectionWindow) {
  1116.     this._selectionWindow.setMode(this.currentSymbol());
  1117.   }
  1118. };
  1119.  
  1120. Window_XRefCommand.prototype.setSelectionWindow = function(selectionWindow) {
  1121.   this._selectionWindow = selectionWindow;
  1122.   this.update();
  1123. };
  1124.  
  1125. Window_XRefCommand.prototype.processOk = function() {
  1126.   Window_XRefCommand._lastCommandSymbol = this.currentSymbol();
  1127.   Window_MenuCommand.prototype.processOk.call(this);
  1128. };
  1129.  
  1130. Window_XRefCommand.prototype.selectLast = function() {
  1131.   this.selectSymbol(Window_XRefCommand._lastCommandSymbol);
  1132. };
  1133.  
  1134.  
  1135. // XRef Selection Window
  1136.  
  1137. function Window_XRefSelection() {
  1138.   this.initialize.apply(this, arguments);
  1139. }
  1140.  
  1141. Window_XRefSelection.prototype = Object.create(Window_Selectable.prototype);
  1142. Window_XRefSelection.prototype.constructor = Window_XRefSelection;
  1143.  
  1144. Window_XRefSelection.prototype.initialize = function(x, y, width, height) {
  1145.   Window_Selectable.prototype.initialize.call(this, x, y, width, height);
  1146.   this._mode = 'none';
  1147.   this._data = [];
  1148. };
  1149.  
  1150. Window_XRefSelection.prototype.setMode = function(mode) {
  1151.   if (this._mode !== mode) {
  1152.     this._mode = mode;
  1153.     this.refresh();
  1154.     this.resetScroll();
  1155.   }
  1156. };
  1157.  
  1158. Window_XRefSelection.prototype.standardFontSize = function() {
  1159.   return 24;
  1160. }
  1161.  
  1162. Window_XRefSelection.prototype.maxCols = function() {
  1163.   return 2;
  1164. };
  1165.  
  1166. Window_XRefSelection.prototype.maxItems = function() {
  1167.   return this._data ? this._data.length : 0;
  1168. };
  1169.  
  1170. Window_XRefSelection.prototype.item = function() {
  1171.   var index = this.index();
  1172.   return this._data && index >= 0 ? this._data[index] : null;
  1173. };
  1174.  
  1175. Window_XRefSelection.prototype.makeItemList = function() {
  1176.   this._data = new Array(XRefManager.dataSources(this._mode).length - 1).join().split(',').map(function(item, index) { return ++index });
  1177. };
  1178.  
  1179. Window_XRefSelection.prototype.isCurrentItemEnabled = function() {
  1180.   return this.isEnabled(this.item());
  1181. };
  1182.  
  1183. Window_XRefSelection.prototype.isEnabled = function(item) {
  1184.   return XRefManager.refs(this._mode, item).length > 0
  1185. };
  1186.  
  1187. Window_XRefSelection.prototype.drawItem = function (index) {
  1188.   var item = this._data[index];
  1189.   if (item) {
  1190.     var rect = this.itemRect(index);
  1191.     rect.width -= this.textPadding();
  1192.     this.changePaintOpacity(this.isEnabled(item));
  1193.     var text = item.padZero(4) + ': ' + XRefManager.objName(this._mode, item);
  1194.     this.drawText(text, rect.x, rect.y, rect.width);
  1195.   }
  1196. };
  1197.  
  1198. Window_XRefSelection.prototype.setHelpWindow = function(helpWindow) {
  1199.   this._helpWindow = helpWindow;
  1200. };
  1201.  
  1202. Window_XRefSelection.prototype.updateHelp = function() {
  1203.   if (this._helpWindow && this.item()) {
  1204.     this._helpWindow.setText(XRefManager.dataTitles(this._mode) + ' ' +
  1205.       this.item().padZero(4) + ': ' + XRefManager.objName(this._mode, this.item()));
  1206.   }
  1207. };
  1208.  
  1209. Window_XRefSelection.prototype.refresh = function() {
  1210.   this.makeItemList();
  1211.   this.createContents();
  1212.   this.drawAllItems();
  1213. };
  1214.  
  1215.  
  1216.  
  1217. // XRef Results
  1218.  
  1219. function Window_XRefResults() {
  1220.   this.initialize.apply(this, arguments);
  1221. };
  1222.  
  1223. Window_XRefResults.prototype = Object.create(Window_Selectable.prototype);
  1224. Window_XRefResults.prototype.constructor = Window_XRefResults;
  1225.  
  1226. Window_XRefResults.prototype.initialize = function(x, y, width, height) {
  1227.   Window_Selectable.prototype.initialize.call(this, x, y, width, height);
  1228.   this._mode = 'none';
  1229.   this._data = [];
  1230.   this._selection = null;
  1231. };
  1232.  
  1233. Window_XRefResults.prototype.setMode = function(mode) {
  1234.   if (this._mode !== mode) {
  1235.     this._mode = mode;
  1236.   }
  1237. };
  1238.  
  1239. Window_XRefResults.prototype.setSelection = function(selection) {
  1240.   this._selection = selection;
  1241. };
  1242.  
  1243. Window_XRefResults.prototype.standardFontSize = function() {
  1244.   return 24;
  1245. }
  1246.  
  1247. Window_XRefResults.prototype.maxItems = function() {
  1248.   return this._data ? this._data.length : 0;
  1249. }
  1250.  
  1251. Window_XRefResults.prototype.makeItemList = function() {
  1252.   this._data = XRefManager.refs(this._mode, this._selection);
  1253. };
  1254.  
  1255. Window_XRefResults.prototype.drawItem = function(index) {
  1256.   var item = this._data[index];
  1257.   var rect = this.itemRect(index);
  1258.   if (item) {
  1259.     var text = XRefManager.dataTitles(item._srcType) + ' ' + item._srcId + ': ' + XRefManager.objName(item._srcType, item._srcId);
  1260.     if (item._evt) {
  1261.       text += '     ';
  1262.       if (item._evt._id) { text += 'EV' + item._evt._id.padZero(3) + ': ' + item._evt._name; };
  1263.       text += '     ' + item._evt._page + ':' + item._evt._line;
  1264.     }
  1265.     text += '     ' + XRefManager.command(item._ref);
  1266.     this.drawText(text, 2, rect.y, this.contentsWidth() - this.textPadding() * 2);
  1267.   } else {
  1268.     this.drawText(rect, 'No references found');
  1269.   }
  1270. };
  1271.  
  1272. Window_XRefResults.prototype.refresh = function() {
  1273.   this.makeItemList();
  1274.   this.createContents();
  1275.   this.drawAllItems();
  1276. };
  1277.  
  1278.  
  1279.  
  1280. // XRef Scene
  1281.  
  1282. function Scene_XRef() {
  1283.   this.initialize.apply(this, arguments);
  1284. };
  1285.  
  1286. Scene_XRef.prototype = Object.create(Scene_MenuBase.prototype);
  1287. Scene_XRef.prototype.constructor = Scene_XRef;
  1288.  
  1289. Scene_XRef.prototype.initialize = function() {
  1290.   Scene_MenuBase.prototype.initialize.call(this);
  1291. };
  1292.  
  1293. Scene_XRef.prototype.create = function() {
  1294.   Scene_MenuBase.prototype.create.call(this);
  1295.   this.createCommandWindow();
  1296.   this.createSelectionWindow();
  1297.   this.createHelpWindow();
  1298.   this.createResultWindow();
  1299. };
  1300.  
  1301. Scene_XRef.prototype.createBackground = function() {
  1302.  
  1303. };
  1304.  
  1305. Scene_XRef.prototype.createCommandWindow = function() {
  1306.   this._commandWindow = new Window_XRefCommand(0, 0);
  1307.   this._commandWindow.setHandler('switch',        this.commandChoice.bind(this));
  1308.   this._commandWindow.setHandler('variable',      this.commandChoice.bind(this));
  1309.   this._commandWindow.setHandler('actor',         this.commandChoice.bind(this));
  1310.   this._commandWindow.setHandler('class',         this.commandChoice.bind(this));
  1311.   this._commandWindow.setHandler('skill',         this.commandChoice.bind(this));
  1312.   this._commandWindow.setHandler('item',          this.commandChoice.bind(this));
  1313.   this._commandWindow.setHandler('weapon',        this.commandChoice.bind(this));
  1314.   this._commandWindow.setHandler('armor',         this.commandChoice.bind(this));
  1315.   this._commandWindow.setHandler('enemy',         this.commandChoice.bind(this));
  1316.   this._commandWindow.setHandler('troop',         this.commandChoice.bind(this));
  1317.   this._commandWindow.setHandler('state',         this.commandChoice.bind(this));
  1318.   this._commandWindow.setHandler('animation',     this.commandChoice.bind(this));
  1319.   this._commandWindow.setHandler('commonEvent',   this.commandChoice.bind(this));
  1320.   this._commandWindow.setHandler('cancel',        this.popScene.bind(this));
  1321.   this.addWindow(this._commandWindow);
  1322. };
  1323.  
  1324. Scene_XRef.prototype.createSelectionWindow = function() {
  1325.   var wx = this._commandWindow.x + this._commandWindow.width;
  1326.   var ww = Graphics.width - wx;
  1327.   this._selectionWindow = new Window_XRefSelection(wx, 0, ww, Graphics.height);
  1328.   this._selectionWindow.setHandler('ok',          this.onSelectionOk.bind(this));
  1329.   this._selectionWindow.setHandler('cancel',      this.onSelectionCancel.bind(this));
  1330.   this._commandWindow.setSelectionWindow(this._selectionWindow);
  1331.   this.addWindow(this._selectionWindow);
  1332. };
  1333.  
  1334. Scene_XRef.prototype.createHelpWindow = function() {
  1335.     this._helpWindow = new Window_Help(1);
  1336.     this._helpWindow.hide();
  1337.     this._selectionWindow.setHelpWindow(this._helpWindow);
  1338.     this.addWindow(this._helpWindow);
  1339. };
  1340.  
  1341. Scene_XRef.prototype.createResultWindow = function() {
  1342.   var wy = this._helpWindow.y + this._helpWindow.height;
  1343.   var wh = Graphics.height - wy;
  1344.   this._resultsWindow = new Window_XRefResults(0, wy, Graphics.width, wh);
  1345.   this._resultsWindow.setHandler('cancel',        this.onResultCancel.bind(this));
  1346.   this._resultsWindow.hide();
  1347.   this.addWindow(this._resultsWindow);
  1348. };
  1349.  
  1350. Scene_XRef.prototype.commandChoice = function() {
  1351.   this._selectionWindow.refresh();
  1352.   this._selectionWindow.activate();
  1353.   this._selectionWindow.select(0);
  1354. };
  1355.  
  1356. Scene_XRef.prototype.onSelectionOk = function() {
  1357.   this._lastSelection = this._selectionWindow.index();
  1358.   this._resultsWindow.setMode(this._commandWindow.currentSymbol());
  1359.   this._resultsWindow.setSelection(this._selectionWindow.item());
  1360.   this._resultsWindow.refresh();
  1361.   this._helpWindow.show();
  1362.   this._selectionWindow.updateHelp();
  1363.   this._selectionWindow.hide();
  1364.   this._selectionWindow.deselect();
  1365.   this._commandWindow.hide();
  1366.   this._resultsWindow.show();
  1367.   this._resultsWindow.activate();
  1368. };
  1369.  
  1370. Scene_XRef.prototype.onSelectionCancel = function() {
  1371.   this._selectionWindow.deselect();
  1372.   this._commandWindow.activate();
  1373. };
  1374.  
  1375. Scene_XRef.prototype.onResultCancel = function() {
  1376.   this._resultsWindow.hide();
  1377.   this._resultsWindow.deselect();
  1378.   this._helpWindow.hide();
  1379.   this._selectionWindow.show();
  1380.   this._selectionWindow.activate();
  1381.   this._selectionWindow.select(this._lastSelection);
  1382.   this._commandWindow.show();
  1383. };
Advertisement
Add Comment
Please, Sign In to add comment