设为首页收藏本站|繁體中文

Project1

 找回密码
 注册会员
搜索
查看: 266|回复: 0
打印 上一主题 下一主题

[有事请教] TDDP的优化插件求助

[复制链接]

Lv2.观梦者

梦石
0
星屑
338
在线时间
97 小时
注册时间
2021-7-1
帖子
22
跳转到指定楼层
1
发表于 2023-10-9 16:14:18 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

加入我们,或者,欢迎回来。

您需要 登录 才可以下载或查看,没有帐号?注册会员

x
有点不会用...

JAVASCRIPT 代码复制
  1. //=============================================================================
  2. // TDDP_PreloadManager.js
  3. // Version: 1.1.1
  4. //=============================================================================
  5.  
  6. var Imported = Imported || {};
  7. Imported.TDDP_PreloadManager = "1.1.1";
  8.  
  9. var TDDP = TDDP || {};
  10. TDDP.PreloadManager = TDDP.PreloadManager || {};
  11. //=============================================================================
  12. /*:
  13.  * @plugindesc 1.1.1 Preload resources on scene/map load as well as game startup for a smoother gameplay experience.          id:TDDP_PreloadManager
  14.  *
  15.  * @author Tor Damian Design / Galenmereth
  16.  *
  17.  * @param Preload On Map Load
  18.  * @desc If you want to preload all assets found on a map upon loading the map, set this to true.
  19.  * @default true
  20.  *
  21.  * @param Preload System Music
  22.  * @desc If you want to preload all the Music specified in the Database System tab on startup, set this to true.
  23.  * @default false
  24.  *
  25.  * @param Preload System SFX
  26.  * @desc If you want to preload all the SFX specified in the Database System tab on startup, set this to true.
  27.  * @default false
  28.  *
  29.  * @param Print Debug to Console
  30.  * @desc If you want to see debug information in the console (F8) set this to true.
  31.  * @default false
  32.  *
  33.  * @help =~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
  34.  * Introduction / Table of contents
  35.  * =~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
  36.  * TDDP PreloadManager lets you preload resources on both startup (before the
  37.  * game title screen displays) and on map load (in between map transfers) to
  38.  * ensure resources such as pictures, music and sound effects are preloaded
  39.  * before called.
  40.  *
  41.  * By default MV will stream the resources as they are required. This plugin
  42.  * serves as an alternative for a smoother gameplay experience at the cost of
  43.  * more bandwidth.
  44.  *
  45.  * This Plugin will load all resources in all event pages on the map,
  46.  * regardless of if they will be triggered by the player at any time or not.
  47.  * Since page conditions cannot be predicted as they are dependent on player
  48.  * interaction, this is a necessity to ensure the right files are ready and
  49.  * preloaded.
  50.  *
  51.  * For updates and easy to use documentation, please go to the plugin's website:
  52.  * [url]http://mvplugins.tordamian.com/?p=29[/url]
  53.  *
  54.  * There you can also download a PDF of the documentation for offline use, and
  55.  * having the documentation in one cleanly presented place means you can always
  56.  * be sure it's the most recent available.
  57.  *
  58.  * Table of contents
  59.  * -----------------
  60.  * 1. Installation
  61.  * 2. Advanced Configuration
  62.  * 3. Terms & Conditions
  63.  *
  64.  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  65.  * 1. Installation
  66.  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  67.  * Drag and drop plugin .js file into your project's js/plugins folder, then
  68.  * enable it in the editor interface.
  69.  *
  70.  * Make sure this plugin is placed at the top for maximum compatibility.
  71.  *
  72.  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  73.  * 2. Advanced Configuration
  74.  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  75.  * There is an advanced configuration section if you open the plugin .js file
  76.  * in a text editor. Look for BOOT PRELOAD CONFIG -- ADVANCED USERS. This lets
  77.  * you define resources to preload on boot manually.
  78.  *
  79.  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  80.  * 3. Terms & Conditions
  81.  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  82.  * This plugin is free for both non-commercial and commercial use.
  83.  *
  84.  * A big thank you to Degica for making this plugin free for commercial use for
  85.  * everyone!
  86.  *
  87.  * MIT License
  88.  *
  89.  * Copyright (c) 2019 Tor Damian Design
  90.  *
  91.  * Permission is hereby granted, free of charge, to any person obtaining a copy
  92.  * of this software and associated documentation files (the "Software"), to deal
  93.  * in the Software without restriction, including without limitation the rights
  94.  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  95.  * copies of the Software, and to permit persons to whom the Software is
  96.  * furnished to do so, subject to the following conditions:
  97.  *
  98.  * The above copyright notice and this permission notice shall be included in all
  99.  * copies or substantial portions of the Software.
  100.  *
  101.  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  102.  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  103.  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  104.  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  105.  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  106.  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  107.  * SOFTWARE.
  108.  */
  109. /*
  110. * =============================================================================
  111. * BOOT PRELOAD CONFIG -- ADVANCED USERS
  112. * =============================================================================
  113. *
  114. * Tip: You can omit the filename, it will assume .png since this is what MV
  115. * prefers.
  116. *
  117. * -----------------------------------------------------------------------------
  118. * Image files to load on boot:
  119. * -----------------------------------------------------------------------------
  120. * Keys:
  121. *   animation
  122. *   battleback1
  123. *   battleback2
  124. *   character
  125. *   enemy
  126. *   face
  127. *   parallax
  128. *   picture
  129. *   svActor
  130. *   svEnemy
  131. *   system
  132. *   tileset
  133. *   title1
  134. *   title2
  135. *
  136. * If you have subfolders in any of these folders, just prepend that to the
  137. * filename, like this example, where the picture "arrow" is in the "cursors"
  138. * subfolder within the system folder:
  139. *
  140. * system: [
  141. *   "balloon",
  142. *   "cursors/arrow"
  143. * ]
  144. */
  145. TDDP.bootPreloadImages = {
  146.     /* Example
  147.     face: [
  148.         "Actor3"
  149.     ],
  150.     system: [
  151.       "myFile",
  152.       "subfolder/myOtherFile"
  153.     ]
  154.     */
  155. }
  156. /*
  157. *
  158. * -----------------------------------------------------------------------------
  159. * BGM files to load on boot
  160. * -----------------------------------------------------------------------------
  161. */
  162. TDDP.bootPreloadBGM = [
  163.     // "Town1"
  164. ]
  165. /*
  166. *
  167. * -----------------------------------------------------------------------------
  168. * BGS files to load on boot
  169. * -----------------------------------------------------------------------------
  170. */
  171. TDDP.bootPreloadBGS = [
  172.     // "Quake"
  173. ]
  174. /*
  175. *
  176. * -----------------------------------------------------------------------------
  177. * SFX files to load on boot.
  178. * -----------------------------------------------------------------------------
  179. */
  180. TDDP.bootPreloadSE = [
  181.     // "Open2"
  182. ]
  183. /*
  184. *
  185. * -----------------------------------------------------------------------------
  186. * ME files to load on boot.
  187. * -----------------------------------------------------------------------------
  188. */
  189. TDDP.bootPreloadME = [
  190.     // "Shock1"
  191. ]
  192. //=============================================================================
  193. // END OF BOOT PRELOAD CONFIG
  194. //=============================================================================
  195. var PreloadManager;
  196. (function() {
  197.     "use strict";
  198.     // Skip preloading if event test
  199.     if (DataManager.isEventTest()) return;
  200.     //=============================================================================
  201.     // Setting up parameters
  202.     //=============================================================================
  203.     var parameters         = $plugins.filter(function(p){return p.description.contains("id:TDDP_PreloadManager")})[0].parameters;
  204.     var preloadOnMapLoad   = Boolean(parameters['Preload On Map Load']       === 'true' || false);
  205.     var preloadSystemMusic = Boolean(parameters['Preload System Music']      === 'true' || false);
  206.     var preloadSystemSFX   = Boolean(parameters['Preload System SFX']        === 'true' || false);
  207.     var debug              = Boolean(parameters['Print Debug to Console']    === 'true' || false);
  208.     if(debug) console.log("========= TDDP PreloadManager: Debug mode on =========")
  209.  
  210.     PreloadManager = function() {
  211.         throw new Error('This is a static class');
  212.     };
  213.  
  214.     PreloadManager._callOnComplete = false;
  215.     PreloadManager._filesLoaded = 0;
  216.     PreloadManager._filesTotal = 0;
  217.     PreloadManager._ready = false;
  218.     PreloadManager._preloadedMaps = [];
  219.     PreloadManager._preloadedAudio = [];
  220.     PreloadManager._sessionRequestedImages = [];
  221.  
  222.     PreloadManager.callOnComplete = function(func) {
  223.         this._callOnComplete = func;
  224.     };
  225.  
  226.     PreloadManager.start = function() {
  227.         this._ready = true;
  228.         this._sessionRequestedImages = [];
  229.         this.controlIfReady(true);
  230.     };
  231.  
  232.     PreloadManager._projectPath = function() {
  233.         var path = window.location.pathname.replace(/\/[^\/]*$/, "/");
  234.         if (path.match(/^\/([A-Z]\:)/)) {
  235.             path = path.slice(1);
  236.         }
  237.         return decodeURIComponent(path);
  238.     };
  239.  
  240.     PreloadManager.controlAudioFileExistence = function(folder, filename) {
  241.         this.controlFileExistence("audio/" + folder + "/", filename, [".m4a", ".ogg"]);
  242.     };
  243.  
  244.     PreloadManager.controlFileExistence = function(folder, filename, extensions) {
  245.         if (StorageManager.isLocalMode() && Utils.isOptionValid('test')) {
  246.             var fs = require("fs");
  247.             var path = this._projectPath() + folder + filename;
  248.             for (var i=0, max=extensions.length; i < max; i++) {
  249.                 if (fs.existsSync(path + extensions[i])) return true;
  250.             }
  251.             throw new Error("PreloadManager: File " + folder + filename + " could not be found. Does it exist?")
  252.         }
  253.     };
  254.  
  255.     PreloadManager.preloadImages = function(type, filename, hue) {
  256.         if(filename.constructor === Array) {
  257.             for(var i = 0; i < filename.length; i++) {
  258.                 this.preloadImages(type, filename[i], hue);
  259.             }
  260.         } else {
  261.             if(filename.length > 0) {
  262.                 if (this._isImageRequested(type, filename)) return;
  263.                 var func = "load" + type.charAt(0).toUpperCase() + type.substr(1).toLowerCase();
  264.                 if(typeof ImageManager[func] === 'undefined') {
  265.                     e = "PreloadManager: " + type + " is not a valid image load key. Check your configuration.";
  266.                     Graphics.printError(e);
  267.                     throw new Error(e);
  268.                 }
  269.                 this._increaseFileNums();
  270.                 ImageManager[func](filename, hue).addLoadListener(this.onFileLoaded.bind(this, "(" + type + ") " + filename));
  271.                 this._registerRequestedImage(type, filename);
  272.             }
  273.         }
  274.     };
  275.  
  276.     PreloadManager.preloadBGM = function(audioObject) {
  277.         this.preloadAudio("bgm", audioObject);
  278.     };
  279.  
  280.     PreloadManager.preloadBGS = function(audioObject) {
  281.         this.preloadAudio("bgs", audioObject);
  282.     };
  283.  
  284.     PreloadManager.preloadSE = function(audioObject) {
  285.         this.preloadAudio("se", audioObject);
  286.     }
  287.  
  288.     PreloadManager.preloadME = function(audioObject) {
  289.         this.preloadAudio("me", audioObject);
  290.     }
  291.  
  292.     PreloadManager.preloadAudio = function(type, audioObject) {
  293.         if (!audioObject) return;
  294.         if(audioObject.constructor === Array) {
  295.             for(var i = 0, max = audioObject.length; i < max; i++) {
  296.                 this.preloadAudio(type, audioObject[i]);
  297.             }
  298.         } else {
  299.             if(audioObject.name.length <= 0) return;
  300.             if(this.isAudioCached(type, audioObject.name)) {
  301.                 if(debug) console.log(type + "/" + audioObject.name + " already preloaded; skipping.");
  302.                 return;
  303.             }
  304.             this._increaseFileNums();
  305.             this.controlAudioFileExistence(type, audioObject.name);
  306.             var bufferObject = AudioManager.createBuffer(type, audioObject.name);
  307.             bufferObject.addLoadListener(this.onAudioFileLoaded.bind(this, type, audioObject.name));
  308.         }
  309.     }
  310.  
  311.     PreloadManager.preloadAnimation = function(animationId) {
  312.         var animation = $dataAnimations[animationId];
  313.         this.preloadImages('animation', [animation.animation1Name, animation.animation2Name]);
  314.         for(var i=0, max=animation.timings.length; i<max; i++) {
  315.             var se = animation.timings[i].se;
  316.             this.preloadSE(se);
  317.         }
  318.     }
  319.  
  320.     PreloadManager.preloadMapResources = function(mapId) {
  321.         this._ready = false;
  322.         // Wait and ensure map is loaded
  323.         if(!DataManager.isMapDataLoaded()) return setTimeout(this.preloadMapResources.bind(this, mapId), 100);
  324.         var mapDebugName = mapId + " (" + $dataMapInfos[mapId].name + ")";
  325.         if(this._preloadedMaps.indexOf(mapId) > -1) {
  326.             if(debug) console.log("Map " + mapDebugName + " already preloaded, skipping.");
  327.         } else {
  328.             if(debug) console.log("Map " + mapDebugName + " preload starting.");
  329.             // Map is loaded, preload resources now
  330.             this.preloadBGM($dataMap.bgm);
  331.             this.preloadBGS($dataMap.bgs);
  332.             this.preloadImages('battleback1', $dataMap.battleback1Name);
  333.             this.preloadImages('battleback2', $dataMap.battleback2Name);
  334.             this.preloadImages('parallax', $dataMap.parallaxName);
  335.             // Cycle events and load appropriate resources
  336.             for(var i = 0, max = $dataMap.events.length; i < max; i++) {
  337.                 var event = $dataMap.events[i];
  338.                 if(!event) continue;
  339.                 for(var p = 0, pMax = event.pages.length; p < pMax; p++) {
  340.                     var page = event.pages[p];
  341.                     // Preload character graphic for page
  342.                     this.preloadImages('character', page.image.characterName);
  343.                     for(var l = 0, lMax = page.list.length; l < lMax; l++) {
  344.                         var listEntry = page.list[l];
  345.                         this.preloadEventListEntry(listEntry);
  346.                     }
  347.                 }
  348.             };
  349.             this._preloadedMaps.push(mapId);
  350.         }
  351.         this.start(true);
  352.     };
  353.  
  354.     PreloadManager.preloadEventListEntry = function(listEntry) {
  355.         var code = listEntry.code;
  356.         var parameters = listEntry.parameters;
  357.         switch(code) {
  358.             // Show Picture
  359.             case 231:
  360.                 this.preloadImages('picture', parameters[1]);
  361.                 break;
  362.             // Play BGM
  363.             case 241:
  364.                 this.preloadBGM(parameters[0]);
  365.                 break;
  366.             // Play BGS
  367.             case 245:
  368.                 this.preloadBGS(parameters[0]);
  369.                 break;
  370.             // Play ME
  371.             case 249:
  372.                 this.preloadME(parameters[0]);
  373.                 break;
  374.             // Play SE
  375.             case 250:
  376.                 this.preloadSE(parameters[0]);
  377.                 break;
  378.             // Change Parallax
  379.             case 284:
  380.                 this.preloadImages('parallax', parameters[0]);
  381.                 break;
  382.             // Show Text
  383.             case 101:
  384.                 this.preloadImages('face', parameters[0]);
  385.                 break;
  386.             // Show Animation
  387.             case 212:
  388.                 this.preloadAnimation(parameters[1]);
  389.                 break;
  390.         }
  391.     };
  392.  
  393.     PreloadManager.onFileLoaded = function(filename) {
  394.         this._filesLoaded += 1;
  395.         if(debug) console.log("Loaded file: " + filename + "(" + this._filesLoaded + "/" + this._filesTotal + ")");
  396.         this.controlIfReady();
  397.     };
  398.  
  399.     PreloadManager.onAudioFileLoaded = function(type, filename) {
  400.         this._cacheAudio(type, filename);
  401.         this.onFileLoaded("(" + type + ") " + filename);
  402.     };
  403.  
  404.     PreloadManager.controlIfReady = function(manual) {
  405.         if(this.isReady()) {
  406.             if(debug && !manual) console.log("All files loaded (" + this._filesLoaded + "/" + this._filesTotal + ")");
  407.             this._filesTotal = this._filesLoaded = 0;
  408.             if(this._callOnComplete) {
  409.                 this._callOnComplete.call();
  410.             }
  411.         }
  412.     }
  413.  
  414.     PreloadManager._cacheAudio = function(path, filename) {
  415.         this._preloadedAudio.push(path + filename);
  416.     };
  417.  
  418.     PreloadManager._registerRequestedImage = function(type, filename) {
  419.         this._sessionRequestedImages.push(type + filename);
  420.     };
  421.  
  422.     PreloadManager._isImageRequested = function(type, filename) {
  423.         return this._sessionRequestedImages.indexOf(type + filename) > -1;
  424.     }
  425.  
  426.     PreloadManager.isAudioCached = function(path, filename) {
  427.         return this._preloadedAudio.indexOf(path + filename) > -1;
  428.     }
  429.  
  430.     PreloadManager._increaseFileNums = function() {
  431.         this._ready = false;
  432.         this._filesTotal +=1;
  433.     };
  434.  
  435.     PreloadManager.isReady = function() {
  436.         if(this._filesLoaded >= this._filesTotal) {
  437.             if(this._ready || this._filesTotal == 0) {
  438.                 return true;
  439.             }
  440.         }
  441.         return false;
  442.     };
  443.  
  444.     var _isDatabaseLoaded = function() {
  445.         DataManager.checkError();
  446.         for (var i = 0; i < DataManager._databaseFiles.length; i++) {
  447.             if (!window[DataManager._databaseFiles[i].name]) {
  448.                 return false;
  449.             }
  450.         }
  451.         return true;
  452.     }
  453.  
  454.     //=============================================================================
  455.     // Scene_Boot extensions
  456.     //=============================================================================
  457.     var Scene_Boot_prototype_create =
  458.         Scene_Boot.prototype.create;
  459.     Scene_Boot.prototype.create = function() {
  460.         Scene_Boot_prototype_create.call(this);
  461.         this._performPreload();
  462.     };
  463.  
  464.     Scene_Boot.prototype._performPreload = function() {
  465.         if(!_isDatabaseLoaded()) return setTimeout(this._performPreload.bind(this), 5);
  466.         if(debug) console.log("========= TDDP PreloadManager: Boot Preload =========");
  467.         // Preload bootPreloadImages resources
  468.         if(TDDP.bootPreloadImages) {
  469.             for(var key in TDDP.bootPreloadImages) {
  470.                 if(TDDP.bootPreloadImages.hasOwnProperty(key)) {
  471.                     PreloadManager.preloadImages(key, TDDP.bootPreloadImages[key]);
  472.                 }
  473.             }
  474.         }
  475.         // Preload bootPreloadBGM resources
  476.         if(TDDP.bootPreloadBGM && TDDP.bootPreloadBGM.length > 0) {
  477.             for(var i = 0, max = TDDP.bootPreloadBGM.length; i < max; i++) {
  478.                 PreloadManager.preloadBGM({
  479.                     name: TDDP.bootPreloadBGM[i],
  480.                     volume: 90,
  481.                     pitch: 100
  482.                 });
  483.             }
  484.         }
  485.         // Preload bootPreloadBGS resources
  486.         if(TDDP.bootPreloadBGS && TDDP.bootPreloadBGS.length > 0) {
  487.             for(var i = 0, max = TDDP.bootPreloadBGS.length; i < max; i++) {
  488.                 PreloadManager.preloadBGS({
  489.                     name: TDDP.bootPreloadBGS[i],
  490.                     volume: 90,
  491.                     pitch: 100
  492.                 });
  493.             }
  494.         }
  495.         // Preload bootPreloadSE resources
  496.         if(TDDP.bootPreloadSE && TDDP.bootPreloadSE.length > 0) {
  497.             for(var i = 0, max = TDDP.bootPreloadSE.length; i < max; i++) {
  498.                 PreloadManager.preloadSE({
  499.                     name: TDDP.bootPreloadSE[i],
  500.                     volume: 90,
  501.                     pitch: 100
  502.                 });
  503.             }
  504.         }
  505.         // Preload bootPreloadME resources
  506.         if(TDDP.bootPreloadME && TDDP.bootPreloadME.length > 0) {
  507.             for(var i = 0, max = TDDP.bootPreloadME.length; i < max; i++) {
  508.                 PreloadManager.preloadME({
  509.                     name: TDDP.bootPreloadME[i],
  510.                     volume: 90,
  511.                     pitch: 100
  512.                 });
  513.             }
  514.         }
  515.         // Preload system SFX if set
  516.         if(preloadSystemSFX) {
  517.             if(debug) console.log("========= TDDP PreloadManager: Boot Preloading System SFX =========");
  518.             for(var i = 0, max = $dataSystem.sounds.length; i < max; i++) {
  519.                 PreloadManager.preloadSE($dataSystem.sounds[i]);
  520.             }
  521.         }
  522.         // Preload system BGM and ME if set
  523.         if(preloadSystemMusic) {
  524.             if(debug) console.log("========= TDDP PreloadManager: Boot Preloading System Music =========");
  525.             [
  526.                 $dataSystem.titleBgm,
  527.                 $dataSystem.battleBgm,
  528.                 $dataSystem.boat.bgm,
  529.                 $dataSystem.ship.bgm,
  530.                 $dataSystem.airship.bgm,
  531.             ].forEach(function(bgm) {
  532.                 PreloadManager.preloadBGM(bgm);
  533.             });
  534.             [
  535.                 $dataSystem.victoryMe,
  536.                 $dataSystem.defeatMe,
  537.                 $dataSystem.gameoverMe,
  538.             ].forEach(function(me) {
  539.                 PreloadManager.preloadME(me);
  540.             });
  541.         }
  542.         PreloadManager.start();
  543.     };
  544.  
  545.     //=============================================================================
  546.     // DataManager extensions
  547.     //=============================================================================
  548.     if (preloadOnMapLoad) {
  549.         var DataManager_loadMapData =
  550.             DataManager.loadMapData;
  551.         DataManager.loadMapData = function(mapId) {
  552.             if(debug) console.log("========= TDDP PreloadManager: Map Preload =========");
  553.             this._preloaded = false;
  554.             DataManager_loadMapData.call(this, mapId);
  555.             PreloadManager.preloadMapResources(mapId);
  556.             PreloadManager.callOnComplete(this._onPreloadDone.bind(this));
  557.         }
  558.  
  559.         DataManager._onPreloadDone = function() {
  560.             this._preloaded = true;
  561.         }
  562.  
  563.         var DataManager_isMapLoaded =
  564.             DataManager.isMapLoaded;
  565.         DataManager.isMapLoaded = function() {
  566.             return (this.isMapDataLoaded() && this._preloaded);
  567.         }
  568.  
  569.         DataManager.isMapDataLoaded = function() {
  570.             return DataManager_isMapLoaded.call(this);
  571.         }
  572.     }
  573.  
  574.     //=============================================================================
  575.     // Scene_Base extensions
  576.     //=============================================================================
  577.     var Scene_Base_prototype_isReady =
  578.         Scene_Base.prototype.isReady;
  579.     Scene_Base.prototype.isReady = function() {
  580.         if(!PreloadManager.isReady()) return false;
  581.         return Scene_Base_prototype_isReady.call(this);
  582.     }
  583.  
  584.     //=============================================================================
  585.     // Html5Audio extensions
  586.     //=============================================================================
  587.     /**
  588.      * Sets up the Html5 Audio.
  589.      *
  590.      * @static
  591.      * @method setup
  592.      * @param {String} url The url of the audio file
  593.      */
  594.     Html5Audio.setup = function (url) {
  595.         if (!this._initialized) {
  596.             this.initialize();
  597.         }
  598.         this.clear();
  599.         this._load(url); // Changed from this._url = url to call the _load func; this func is never loaded by default
  600.     };
  601.  
  602.     /**
  603.      * @static
  604.      * @method _setupEventHandlers
  605.      * @private
  606.      */
  607.     Html5Audio._setupEventHandlers = function () {
  608.         document.addEventListener('touchstart', this._onTouchStart.bind(this));
  609.         document.addEventListener('visibilitychange', this._onVisibilityChange.bind(this));
  610.         this._audioElement.addEventListener("canplaythrough", this._onLoadedData.bind(this)); // Changed from loaddata to canplaythrough, so it knows streaming is stable enough
  611.         this._audioElement.addEventListener("error", this._onError.bind(this));
  612.         this._audioElement.addEventListener("ended", this._onEnded.bind(this));
  613.     };
  614.  
  615.     /**
  616.      * @static
  617.      * @method _onLoadedData
  618.      * @private
  619.      */
  620.     Html5Audio._onLoadedData = function () {
  621.         this._buffered = true;
  622.         this._onLoad(); // I removed check for this._unlocked because that shouldn't matter
  623.     };
  624. })();
您需要登录后才可以回帖 登录 | 注册会员

本版积分规则

拿上你的纸笔,建造一个属于你的梦想世界,加入吧。
 注册会员
找回密码

站长信箱:[email protected]|手机版|小黑屋|无图版|Project1游戏制作

GMT+8, 2024-5-13 07:59

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表