Advertisement
Guest User

STV_StageSelector

a guest
Oct 24th, 2016
184
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //=============================================================================
  2. // STV_StageSelector.js
  3. //=============================================================================
  4.  
  5. /*:
  6.  * @plugindesc v1.1 - STV_StageSelector
  7.  * || This will add a level selector to your Project
  8.  * @author SkottyTV || Special Thanks: Lantiz
  9.  *
  10.  * @param ----- Window -----
  11.  *
  12.  * @param Show Window
  13.  * @desc Show or Hide Window Skin
  14.  * TRUE = show window / FALSE = hide window
  15.  * @default TRUE
  16.  *
  17.  * @param Background Picture
  18.  * @desc The Background Picture in img/pictures/
  19.  * (leave empty for no Background Picture)
  20.  * @default
  21.  *
  22.  * @param Backbar Color
  23.  * @desc The default Backbar Color
  24.  * (default 15)
  25.  * @default 15
  26.  *
  27.  * @param ----- Text -----
  28.  *
  29.  * @param Chapter Text
  30.  * @desc Default Text for "Chapter"
  31.  * @default Chapter
  32.  *
  33.  * @param Transfer Text
  34.  * @desc Default Text for "Start"
  35.  * @default Transfer
  36.  *
  37.  * @param Back Text
  38.  * @desc Default Text for "Back"
  39.  * @default Back
  40.  *
  41.  * @param Info Text
  42.  * @desc Default Text for "Info"
  43.  * @default Info
  44.  *
  45.  * @param ----- Icons -----
  46.  *
  47.  * @param Completed Icon
  48.  * @desc Default Icon for completed levels
  49.  * @default 87
  50.  *
  51.  * @param --- Functions ---
  52.  *
  53.  * @param Show Level ID
  54.  * @desc Show Level ID in front of name
  55.  * TRUE = show, FALSE = hide
  56.  * @default TRUE
  57.  *
  58.  * @param Transfer Direction
  59.  * @desc Direction the Player looks after Transfer
  60.  * 2 = down, 4 = left, 6 = right, 8 = up, 0 = as before
  61.  * @default 0
  62.  *
  63.  * @param Transfer Type
  64.  * @desc The Type of the Transfer
  65.  * 0 = Fade Black, 1 = Fade White, 2 = none/instant
  66.  * @default 0
  67.  *
  68.  * @help
  69.  *
  70.  * ////////////////////////////////////////////////////////////////////////////
  71.  * ----------------------------- Terms of Usage: ------------------------------
  72.  * ////////////////////////////////////////////////////////////////////////////
  73.  
  74.  * Feel free to use this Plugin in 1. Non-Commercial Games, 2. Commercial Games
  75.  * However it would be nice to give proper Credits to "SkottyTV"
  76.  * Also a free copy of your Game would be a nice move :)
  77.  *
  78.  * Many Thanks to the Forum User "Lantiz" !
  79.  *
  80.  * Have Fun And Enjoy! :)
  81.  *
  82.  *
  83.  *
  84.  * ////////////////////////////////////////////////////////////////////////////
  85.  * --------------------------------- Updates:----------------------------------
  86.  * ////////////////////////////////////////////////////////////////////////////
  87.  *
  88.  * Update v1.0
  89.  * - Basic Functionality
  90.  * - Bug fixes
  91.  * - upgrades
  92.  *
  93.  * Updated v1.1
  94.  * - Bug Fixes
  95.  *
  96.  *
  97.  * ////////////////////////////////////////////////////////////////////////////
  98.  * -------------------------------- Commands: ---------------------------------
  99.  * ////////////////////////////////////////////////////////////////////////////
  100.  
  101.  * Plugin Command:
  102.  *   StageSelector open            # Opens the Stage Selector.
  103.  *   StageSelector reveal 1 3      # Shows Stage 1 Level 3 inside StageSelector.
  104.  *   StageSelector complete 2 5    # Completes Level 5 of Stage 2.
  105.  *
  106.  * Event Note:
  107.  *   <STVSS start>                 # This Event will be the start position
  108.  *                                   of the Player after the Transfer.
  109.  * Map Note:
  110.  *   <STVSS Stage: 1,4>            # This Map will be Stage 1, Level 4.
  111.  *   <STVSS Info>                  # Start of all Infos.
  112.  *   Some Info here                # The Info Text.
  113.  *   </STVSS Info>                 # End of all Infos.
  114.  *
  115.  *
  116.  * ////////////////////////////////////////////////////////////////////////////
  117.  * -------------------------- Examples / Tutorials: ---------------------------
  118.  * ////////////////////////////////////////////////////////////////////////////
  119.  *
  120.  * For a Map notebox it could look like this:
  121.  *
  122.  * <STVSS Stage: 1,3>
  123.  * <STVSS Info>
  124.  * This is Stage 1 Level 3.
  125.  * This is some colored \c[2]Info \c[0]Text.
  126.  * You can even put Variables \V[1] here!
  127.  * </STVSS Info>
  128.  *
  129.  *
  130.  */
  131.  
  132.  
  133. // ----------------------------------------------------------------------------------------------------------------------------
  134. // STV_SkillSystem Parameters
  135. // ----------------------------------------------------------------------------------------------------------------------------
  136.     var stv_StageSelector_parameters = PluginManager.parameters('STV_StageSelector');
  137.    
  138.     // ----- Window -----
  139.     var stv_StageSelector_showWindow = String(stv_StageSelector_parameters['Show Window'] || 'TRUE');
  140.     var stv_StageSelector_bgPicture = String(stv_StageSelector_parameters['Background Picture'] || '');
  141.     var stv_StageSelector_backBarColor = Number(stv_StageSelector_parameters['Backbar Color'] || 15);
  142.    
  143.     // ----- Text -----
  144.     var stv_StageSelector_chapterText = String(stv_StageSelector_parameters['Chapter Text'] || 'Chapter');
  145.     var stv_StageSelector_transferText = String(stv_StageSelector_parameters['Transfer Text'] || 'Transfer');
  146.     var stv_StageSelector_backText = String(stv_StageSelector_parameters['Back Text'] || 'Back');
  147.     var stv_StageSelector_descText = String(stv_StageSelector_parameters['Info Text'] || 'Info');
  148.    
  149.     // --- Icons ---
  150.     var stv_StageSelector_completedIcon = Number(stv_StageSelector_parameters['Completed Icon'] || 87);
  151.    
  152.     // --- Functions ---
  153.     var stv_StageSelector_showLevelId = String(stv_StageSelector_parameters['Show Level ID'] || 'TRUE');
  154.     var stv_StageSelector_transferDirection = Number(stv_StageSelector_parameters['Transfer Direction'] || 0);
  155.     var stv_StageSelector_transferType = Number(stv_StageSelector_parameters['Transfer Type'] || 0);
  156.    
  157.  
  158. // ----------------------------------------------------------------------------------------------------------------------------
  159. // Scene MonsterCardsManager create
  160. // ----------------------------------------------------------------------------------------------------------------------------  
  161.     Scene_StageSelector = function() {
  162.         this.initialize.apply(this, arguments);
  163.     };
  164.  
  165.     Scene_StageSelector.prototype = Object.create(Scene_MenuBase.prototype);
  166.     Scene_StageSelector.prototype.constructor = Scene_StageSelector;
  167.  
  168.     Scene_StageSelector.prototype.initialize = function() {
  169.         Scene_MenuBase.prototype.initialize.call(this);
  170.     };                                                          
  171.    
  172.     Scene_StageSelector.prototype.createBackground = function() {
  173.         this._backgroundSprite = new Sprite();
  174.         this._backgroundSprite.move(0, 0, Graphics.width, Graphics.height);
  175.         this._backgroundSprite.bitmap = SceneManager.backgroundBitmap();
  176.         this.addChild(this._backgroundSprite);
  177.         if (stv_StageSelector_bgPicture){
  178.             this._foregroundSprite = new Sprite();
  179.             this._foregroundSprite.move(0, 0, Graphics.width, Graphics.height);
  180.             this._foregroundSprite.bitmap = ImageManager.loadPicture(stv_StageSelector_bgPicture);
  181.             this.addChild(this._foregroundSprite);
  182.         }
  183.     };
  184.    
  185.     Scene_StageSelector.prototype.create = function() {
  186.         Scene_MenuBase.prototype.create.call(this);
  187.        
  188.         this.createWindowPositions();
  189.        
  190.         this.createChapterWindow();
  191.         this.createLevelWindow();
  192.         this.createInfoWindow();
  193.         this.createCommandWindow();
  194.        
  195.         if(stv_StageSelector_showWindow != "TRUE"){
  196.             this._chapterWindow.opacity = 0;
  197.             this._levelWindow.opacity = 0;
  198.             this._infoWindow.opacity = 0;
  199.             this._commandWindow.opacity = 0;
  200.         }
  201.     };
  202.    
  203. // ----------------------------------------------------------------------------------------------------------------------------
  204. // Create Window Positions
  205. // ----------------------------------------------------------------------------------------------------------------------------
  206.     Scene_StageSelector.prototype.createWindowPositions = function() {
  207.         var maxWidth = Graphics.boxWidth,
  208.             maxHeight = Graphics.boxHeight;
  209.        
  210.         var cX = 0,
  211.             cY = 0,
  212.             cW = maxWidth,
  213.             cH = (maxHeight/4);
  214.         this._chapterWindow = new Window_StageSelector_Chapter(cX, cY, cW, cH);
  215.        
  216.         var lX = cX,
  217.             lY = cH,
  218.             lW = cW/3,
  219.             lH = maxHeight-cH;
  220.         this._levelWindow = new Window_StageSelector_Level(lX, lY, lW, lH);
  221.        
  222.         var iX = lW,
  223.             iY = lY,
  224.             iW = cW-lW,
  225.             iH = lH;
  226.         this._infoWindow = new Window_StageSelector_Info(iX, iY, iW, iH);
  227.        
  228.         var hX = iX,
  229.             hY = maxHeight - 75,
  230.             hW = iW,
  231.             hH = 75;
  232.         this._commandWindow = new Window_StageSelector_Command(hX, hY, hW, hH);
  233.     };
  234.  
  235. // ----------------------------------------------------------------------------------------------------------------------------
  236. // Refresh Windows
  237. // ----------------------------------------------------------------------------------------------------------------------------
  238.     Scene_StageSelector.prototype.refreshWindows = function() {
  239.             this._chapterWindow.refresh();
  240.             this._levelWindow.refresh();
  241.             this._infoWindow.refresh();
  242.             this._commandWindow.refresh();
  243.     };
  244.  
  245. // ----------------------------------------------------------------------------------------------------------------------------
  246. // Setup Chapter Window
  247. // ----------------------------------------------------------------------------------------------------------------------------
  248.     Scene_StageSelector.prototype.createChapterWindow = function() {
  249.         this._chapterWindow.setHandler('ok', this.selectChapter.bind(this));
  250.         this._chapterWindow.setHandler('cancel', this.popScene.bind(this));
  251.         this._chapterWindow.setLevelWindow(this._levelWindow);
  252.         this.addWindow(this._chapterWindow);
  253.         this._chapterWindow.activate();
  254.     };
  255.    
  256. // ----------------------------------------------------------------------------------------------------------------------------
  257. // Setup Level Window
  258. // ----------------------------------------------------------------------------------------------------------------------------
  259.     Scene_StageSelector.prototype.createLevelWindow = function() {
  260.         this._levelWindow.setHandler('ok', this.selectLevel.bind(this));
  261.         this._levelWindow.setHandler('cancel', this.cancelLevel.bind(this));
  262.         this._levelWindow.setInfoWindow(this._infoWindow);
  263.         this.addWindow(this._levelWindow);
  264.     };
  265.    
  266. // ----------------------------------------------------------------------------------------------------------------------------
  267. // Setup Info Window
  268. // ----------------------------------------------------------------------------------------------------------------------------
  269.     Scene_StageSelector.prototype.createInfoWindow = function() {
  270.         this.addWindow(this._infoWindow);
  271.     };
  272.    
  273. // ----------------------------------------------------------------------------------------------------------------------------
  274. // Setup Command Window
  275. // ----------------------------------------------------------------------------------------------------------------------------
  276.     Scene_StageSelector.prototype.createCommandWindow = function() {
  277.         this._commandWindow.setHandler('start', this.startLevel.bind(this));
  278.         this._commandWindow.setHandler('cancel', this.cancelCommand.bind(this));
  279.         this.addWindow(this._commandWindow);
  280.         this._commandWindow.deactivate();
  281.         this._commandWindow.hide();
  282.     };
  283.    
  284. // ----------------------------------------------------------------------------------------------------------------------------
  285. // On Chapter Select
  286. // ----------------------------------------------------------------------------------------------------------------------------
  287.     Scene_StageSelector.prototype.selectChapter = function() {
  288.         if (this._chapterWindow._list[0]) {
  289.             this._chapterWindow.deactivate();
  290.             this._levelWindow.activate();
  291.         } else {
  292.             this.popScene();
  293.         }
  294.     };
  295.  
  296. // ----------------------------------------------------------------------------------------------------------------------------
  297. // On Level Select
  298. // ----------------------------------------------------------------------------------------------------------------------------
  299.     Scene_StageSelector.prototype.selectLevel = function() {
  300.         this._levelWindow.deactivate();
  301.         this._commandWindow.show();
  302.         this._commandWindow.activate();
  303.     };
  304.    
  305. // ----------------------------------------------------------------------------------------------------------------------------
  306. // On Start Select
  307. // ----------------------------------------------------------------------------------------------------------------------------
  308.     Scene_StageSelector.prototype.startLevel = function() {
  309.         this.popScene();
  310.         $stv_stageselector.transfer($stv_stageselector.selectedLevel);
  311.     };
  312.    
  313. // ----------------------------------------------------------------------------------------------------------------------------
  314. // On Command Cancel
  315. // ----------------------------------------------------------------------------------------------------------------------------
  316.     Scene_StageSelector.prototype.cancelCommand = function() {
  317.         this._commandWindow.deactivate();
  318.         this._commandWindow.hide();
  319.         this._levelWindow.activate();
  320.     };
  321.    
  322. // ----------------------------------------------------------------------------------------------------------------------------
  323. // On Level Cancel
  324. // ----------------------------------------------------------------------------------------------------------------------------
  325.     Scene_StageSelector.prototype.cancelLevel = function() {
  326.         this._chapterWindow.activate();
  327.         this._levelWindow.deactivate();
  328.         this._levelWindow.select(0);
  329.     };
  330.  
  331. // ----------------------------------------------------------------------------------------------------------------------------
  332. // Fill Chapter Window
  333. // ----------------------------------------------------------------------------------------------------------------------------
  334.     function Window_StageSelector_Chapter() {
  335.         this.initialize.apply(this, arguments);
  336.     }
  337.  
  338.     Window_StageSelector_Chapter.prototype = Object.create(Window_Selectable.prototype);
  339.     Window_StageSelector_Chapter.prototype.constructor = Window_StageSelector_Chapter;
  340.  
  341.     Window_StageSelector_Chapter.lastTopRow = 0;
  342.     Window_StageSelector_Chapter.lastIndex  = 0;
  343.  
  344.     Window_StageSelector_Chapter.prototype.initialize = function(x, y, width, height) {
  345.         Window_Selectable.prototype.initialize.call(this, x, y, width, height);
  346.         this.refresh();
  347.         this.setTopRow(Window_StageSelector_Chapter.lastTopRow);
  348.         this.select(Window_StageSelector_Chapter.lastIndex);
  349.     };
  350.    
  351.     Window_StageSelector_Chapter.prototype.maxCols = function() {
  352.         return 4;
  353.     };
  354.  
  355.     Window_StageSelector_Chapter.prototype.maxItems = function() {
  356.         return this._list ? this._list.length : 0;
  357.     };
  358.    
  359.     Window_StageSelector_Chapter.prototype.update = function() {
  360.         Window_Selectable.prototype.update.call(this);
  361.         this.updateStatus();
  362.     };
  363.    
  364.     Window_StageSelector_Chapter.prototype.refresh = function() {
  365.         this._list = [];
  366.         for (var i = 1; i < $stv_stageselector._stageList.length; i++) {
  367.             var stage = $stv_stageselector._stageList[i];
  368.             for (var j = 1; j < stage.length; j++) {
  369.                 if (stage[j]._revealed) {
  370.                     this._list.push(stage);
  371.                     break;
  372.                 }
  373.             }
  374.         }
  375.         this.contents.clear();
  376.         this.drawAllItems();
  377.     };
  378.  
  379.     Window_StageSelector_Chapter.prototype.drawItem = function(index) {
  380.         var stage = this._list[index],
  381.             rect = this.itemRect(index);
  382.         this.drawText(stv_StageSelector_chapterText + " " + stage[0], rect.x, rect.y, rect.width, 'center');
  383.     };
  384.    
  385.     Window_StageSelector_Chapter.prototype.setLevelWindow = function(window) {
  386.         this._levelWindow = window;
  387.         this.updateStatus();
  388.     };
  389.    
  390.     Window_StageSelector_Chapter.prototype.updateStatus = function() {
  391.         var chapter = this._list[this.index()];
  392.         $stv_stageselector.selectedChapter = chapter;
  393.         if (this._levelWindow) this._levelWindow.setChapter(chapter);
  394.     };
  395.  
  396. // ----------------------------------------------------------------------------------------------------------------------------
  397. // Fill Level Window
  398. // ----------------------------------------------------------------------------------------------------------------------------    
  399.     function Window_StageSelector_Level() {
  400.         this.initialize.apply(this, arguments);
  401.     }
  402.  
  403.     Window_StageSelector_Level.prototype = Object.create(Window_Selectable.prototype);
  404.     Window_StageSelector_Level.prototype.constructor = Window_StageSelector_Level;
  405.  
  406.     Window_StageSelector_Level.lastTopRow = 0;
  407.     Window_StageSelector_Level.lastIndex  = 0;
  408.  
  409.     Window_StageSelector_Level.prototype.initialize = function(x, y, width, height) {
  410.         Window_Selectable.prototype.initialize.call(this, x, y, width, height);
  411.         this.setTopRow(Window_StageSelector_Level.lastTopRow);
  412.         this.select(Window_StageSelector_Level.lastIndex);
  413.     };
  414.    
  415.     Window_StageSelector_Level.prototype.maxCols = function() {
  416.         return 1;
  417.     };
  418.  
  419.     Window_StageSelector_Level.prototype.maxItems = function() {
  420.         return this._list ? this._list.length : 0;
  421.     };
  422.    
  423.     Window_StageSelector_Level.prototype.update = function() {
  424.         Window_Selectable.prototype.update.call(this);
  425.         this.updateStatus();
  426.     };
  427.  
  428.     Window_StageSelector_Level.prototype.refresh = function() {
  429.         this._list = [];
  430.         if (this._chapter) {
  431.             for (var i = 1; i < this._chapter.length; i++) {
  432.                 var level = this._chapter[i];
  433.                     if (level._revealed) this._list.push(level);
  434.             }
  435.         this.contents.clear();
  436.         this.drawAllItems();
  437.         }
  438.     };
  439.  
  440.     Window_StageSelector_Level.prototype.drawItem = function(index) {
  441.         var level = this._list[index],
  442.             rect = this.itemRect(index),
  443.             levelNr = "";
  444.        
  445.         if (stv_StageSelector_showLevelId == "TRUE") levelNr = "%1: ".format((level._levelId).padZero(3));
  446.  
  447.         this.drawText(levelNr, rect.x, rect.y);
  448.         this.drawText(level.displayName, rect.x + this.textWidth(levelNr), rect.y, this.contents.width - 40 - this.textWidth(levelNr));
  449.         if (level._completed) this.drawIcon(stv_StageSelector_completedIcon, rect.x + rect.width - 32, rect.y + 2, "center");
  450.     };
  451.    
  452.     Window_StageSelector_Level.prototype.setChapter = function(chapter) {
  453.         this._chapter = chapter;
  454.         this.refresh();
  455.     };
  456.    
  457.     Window_StageSelector_Level.prototype.setInfoWindow = function(window) {
  458.         this._infoWindow = window;
  459.         this.updateStatus();
  460.     };
  461.    
  462.     Window_StageSelector_Level.prototype.updateStatus = function() {
  463.         var level = this._list[this.index()];
  464.         $stv_stageselector.selectedLevel = level;
  465.         if (this._infoWindow) this._infoWindow.setLevel(level);
  466.     };
  467.    
  468. // ----------------------------------------------------------------------------------------------------------------------------
  469. // Fill Info Window
  470. // ----------------------------------------------------------------------------------------------------------------------------    
  471.     function Window_StageSelector_Info() {
  472.         this.initialize.apply(this, arguments);
  473.     }
  474.  
  475.     Window_StageSelector_Info.prototype = Object.create(Window_Base.prototype);
  476.     Window_StageSelector_Info.prototype.constructor = Window_StageSelector_Info;
  477.  
  478.     Window_StageSelector_Info.prototype.initialize = function(x, y, width, height) {
  479.         Window_Base.prototype.initialize.call(this, x, y, width, height);
  480.     };
  481.    
  482.     Window_StageSelector_Info.prototype.update = function() {
  483.         Window_Base.prototype.update.call(this);
  484.     };
  485.    
  486.     Window_StageSelector_Info.prototype.setLevel = function(level) {
  487.         this._level = level;
  488.         this.refresh();
  489.     };
  490.    
  491.     Window_StageSelector_Info.prototype.drawHead = function() {
  492.         this.contents.clear();
  493.        
  494.         this.contents.paintOpacity = 180;
  495.         this.contents.fillRect(0, 0, this.contents.width, this.lineHeight(), this.textColor(stv_StageSelector_backBarColor));
  496.         this.contents.paintOpacity = 255;
  497.        
  498.         if (this._level._completed) {
  499.             this.drawIcon(stv_StageSelector_completedIcon, 0, 2);
  500.             this.drawIcon(stv_StageSelector_completedIcon, this.contents.width - 32, 2);
  501.         }
  502.        
  503.         this.drawText(this._level.displayName, (this.contents.width/2) - (this.textWidth(this._level.displayName)/2), 0);
  504.     };
  505.    
  506.     Window_StageSelector_Info.prototype.drawDesc = function() {
  507.         this.drawText(stv_StageSelector_descText, (this.contents.width/2) - (this.textWidth(stv_StageSelector_descText)/2), this.lineHeight()*2);
  508.         this.contents.fillRect(0, this.lineHeight()*3, this.contents.width, 1, this.textColor(0));
  509.         this.drawTextEx(this._level._desc, 0, this.lineHeight()*2);
  510.     };
  511.    
  512.     Window_StageSelector_Info.prototype.refresh = function() {
  513.         if (this._level) {
  514.             this.drawHead();
  515.             this.drawDesc();
  516.         }
  517.     };
  518.  
  519. // ----------------------------------------------------------------------------------------------------------------------------
  520. // Fill Command Window 2
  521. // ----------------------------------------------------------------------------------------------------------------------------
  522.     function Window_StageSelector_Command() {
  523.         this.initialize.apply(this, arguments);
  524.     }
  525.  
  526.     Window_StageSelector_Command.prototype = Object.create(Window_HorzCommand.prototype);
  527.     Window_StageSelector_Command.prototype.constructor = Window_StageSelector_Command;
  528.  
  529.     Window_StageSelector_Command.prototype.initialize = function(x, y, width, height) {
  530.         Window_HorzCommand.prototype.initialize.call(this, x, y, width, height);
  531.     };
  532.  
  533.     Window_StageSelector_Command.prototype.maxCols = function() {
  534.         return 2;
  535.     };
  536.    
  537.     Window_StageSelector_Command.prototype.windowWidth = function() {
  538.         return (Graphics.boxWidth/3)*2;
  539.     };
  540.    
  541.     Window_StageSelector_Command.prototype.makeCommandList = function() {
  542.         this.addCommand(stv_StageSelector_transferText, 'start');
  543.         this.addCommand(stv_StageSelector_backText, 'cancel');
  544.     };
  545.  
  546. // ----------------------------------------------------------------------------------------------------------------------------
  547. // Alias methods
  548. // ----------------------------------------------------------------------------------------------------------------------------
  549.     STV_StageSelector_PluginCommand = Game_Interpreter.prototype.pluginCommand;
  550.     STV_StageSelector_Create = DataManager.createGameObjects;
  551.     STV_StageSelector_Save = DataManager.makeSaveContents;
  552.     STV_StageSelector_Load = DataManager.extractSaveContents;
  553.  
  554. // ----------------------------------------------------------------------------------------------------------------------------
  555. // DataManager
  556. // ----------------------------------------------------------------------------------------------------------------------------
  557.     var $stv_stageselector = null;
  558.  
  559.     DataManager.makeSaveContents = function() {
  560.         contents = STV_StageSelector_Save.call(this);
  561.         contents.stvstageselector = $stv_stageselector;
  562.         return contents;
  563.     };
  564.  
  565.     DataManager.extractSaveContents = function(contents) {
  566.         STV_StageSelector_Load.call(this, contents);
  567.         $stv_stageselector = contents.stvstageselector;
  568.     };
  569.    
  570.     DataManager.createGameObjects = function() {
  571.         STV_StageSelector_Create.call(this);
  572.         $stv_stageselector = new STV_StageSelector();
  573.     };
  574.    
  575. // ----------------------------------------------------------------------------------------------------------------------------
  576. // STV_StageSelector Functions
  577. // ----------------------------------------------------------------------------------------------------------------------------
  578.  
  579.     function STV_StageSelector() {
  580.         this.initialize.apply(this, arguments);
  581.     }
  582.    
  583.     STV_StageSelector.prototype.initialize = function() {
  584.         this.selectedChapter = null;
  585.         this.selectedLevel = null;
  586.         this.setup();
  587.     };
  588.    
  589.     // Setup
  590.     STV_StageSelector.prototype.setup = function() {
  591.         this.createMapList();
  592.         this.createStageList();
  593.         this._mapList = [null]; //delete Map List after needed for more Memory
  594.     };
  595.    
  596.     // Get Maps
  597.     STV_StageSelector.prototype.getMaps = function(filename) {
  598.         var fs = require('fs');
  599.         var dir = window.location.pathname.replace(/(\/www|)\/[^\/]*$/, '/');
  600.         if (dir.match(/^\/([A-Z]\:)/)) {
  601.             dir = dir.slice(1);
  602.         }
  603.         filename = decodeURIComponent(dir) + 'data/' + filename;
  604.         return JsonEx.parse(fs.readFileSync(filename, 'utf8'));
  605.     };
  606.    
  607.     // Create Map List
  608.     STV_StageSelector.prototype.createMapList = function() {
  609.         this._mapList = [null];
  610.         for (var i = 1; i < $dataMapInfos.length; i++) {
  611.             var filename = 'Map%1.json'.format(i.padZero(3));
  612.         this._mapList.push(this.getMaps(filename));
  613.         }
  614.     };
  615.    
  616.     // Create Stage List
  617.     STV_StageSelector.prototype.createStageList = function() {
  618.         this._stageList = [null];
  619.         for (var i = 1; i < $dataMapInfos.length; i++) {
  620.             var note = this._mapList[i].note,
  621.                 desc = "";
  622.             if (note.match(/<STVSS Info>((.|\n)*?)<\/STVSS Info>/g)) {
  623.                 desc = String(RegExp.$1);
  624.             }
  625.             if (note.match(/<(?:STVSS STAGE):[ ](.*)>/i)) {
  626.                 var string = String(RegExp.$1).split(","),
  627.                     stage = Number(string[0]),
  628.                     level = Number(string[1]);
  629.                
  630.                 if (!this._stageList[stage]) this._stageList[stage] = [];
  631.                 this._stageList[stage][0] = stage;
  632.                 this._stageList[stage][level] = {};
  633.                 this._stageList[stage][level].displayName = this._mapList[i].displayName;
  634.                 this._stageList[stage][level].events = this._mapList[i].events;
  635.                 this._stageList[stage][level].note = this._mapList[i].note;
  636.                 this._stageList[stage][level].bgm = this._mapList[i].bgm;
  637.                 this._stageList[stage][level].bgs = this._mapList[i].bgs;
  638.                 this._stageList[stage][level]._desc = desc;
  639.                 this._stageList[stage][level]._revealed = false;
  640.                 this._stageList[stage][level]._completed = false;
  641.                 this._stageList[stage][level]._mapId = i;
  642.                 this._stageList[stage][level]._levelId = level;
  643.                 this._stageList[stage][level]._stageId = stage;
  644.             }
  645.         }
  646.     };
  647.    
  648.     // Transfer Player to Level
  649.     STV_StageSelector.prototype.transfer = function(level) {
  650.         for (var i = 1; i < level.events.length; i++) {
  651.             if (level.events[i]) {
  652.                 var note = level.events[i].note;
  653.                 if (note.match(/<STVSS START>/i)) {
  654.                     var mapId = level._mapId,
  655.                         x = level.events[i].x,
  656.                         y = level.events[i].y,
  657.                         dir = stv_StageSelector_transferDirection,
  658.                         type = stv_StageSelector_transferType;
  659.                     $gamePlayer.reserveTransfer(mapId, x, y, dir, type);
  660.                     break;
  661.                 }
  662.             }
  663.         }
  664.     };
  665.    
  666.     // Complete Level
  667.     STV_StageSelector.prototype.completeLevel = function(stageId, levelId) {
  668.         if (this._stageList[stageId][levelId]) {
  669.             this._stageList[stageId][levelId]._completed = true;
  670.         }
  671.     };
  672.    
  673.     // Reveal Level
  674.     STV_StageSelector.prototype.revealLevel = function(stageId, levelId) {
  675.         if (this._stageList[stageId][levelId]) {
  676.             this._stageList[stageId][levelId]._revealed = true;
  677.         }
  678.     };
  679.    
  680. // ----------------------------------------------------------------------------------------------------------------------------
  681. // Plugin Commands
  682. // ----------------------------------------------------------------------------------------------------------------------------
  683.     Game_Interpreter.prototype.pluginCommand = function(command, args) {
  684.         STV_StageSelector_PluginCommand.call(this, command, args);
  685.        
  686.         if (command === 'StageSelector') {
  687.             switch (args[0]) {
  688.                 case 'open':
  689.                     SceneManager.push(Scene_StageSelector);
  690.                 break;
  691.                 case 'complete':
  692.                     $stv_stageselector.completeLevel(args[1], args[2]);
  693.                 break;
  694.                 case 'reveal':
  695.                     $stv_stageselector.revealLevel(args[1], args[2]);
  696.                 break;
  697.             }
  698.         }
  699.     };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement