查看: 814|回复: 0

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

[复制链接]
梦石
0
星屑
362
在线时间
102 小时
注册时间
2021-7-1
回帖
15
发表于 2023-10-9 16:14:18 | 显示全部楼层 |阅读模式

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

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

×
有点不会用...

  1. //=============================================================================
  2. // TDDP_PreloadManager.js
  3. // Version: 1.1.1
  4. //=============================================================================

  5. var Imported = Imported || {};
  6. Imported.TDDP_PreloadManager = "1.1.1";

  7. var TDDP = TDDP || {};
  8. TDDP.PreloadManager = TDDP.PreloadManager || {};
  9. //=============================================================================
  10. /*:
  11. * @plugindesc 1.1.1 Preload resources on scene/map load as well as game startup for a smoother gameplay experience.          id:TDDP_PreloadManager
  12. *
  13. * @author Tor Damian Design / Galenmereth
  14. *
  15. * @param Preload On Map Load
  16. * @desc If you want to preload all assets found on a map upon loading the map, set this to true.
  17. * @default true
  18. *
  19. * @param Preload System Music
  20. * @desc If you want to preload all the Music specified in the Database System tab on startup, set this to true.
  21. * @default false
  22. *
  23. * @param Preload System SFX
  24. * @desc If you want to preload all the SFX specified in the Database System tab on startup, set this to true.
  25. * @default false
  26. *
  27. * @param Print Debug to Console
  28. * @desc If you want to see debug information in the console (F8) set this to true.
  29. * @default false
  30. *
  31. * @help =~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
  32. * Introduction / Table of contents
  33. * =~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
  34. * TDDP PreloadManager lets you preload resources on both startup (before the
  35. * game title screen displays) and on map load (in between map transfers) to
  36. * ensure resources such as pictures, music and sound effects are preloaded
  37. * before called.
  38. *
  39. * By default MV will stream the resources as they are required. This plugin
  40. * serves as an alternative for a smoother gameplay experience at the cost of
  41. * more bandwidth.
  42. *
  43. * This Plugin will load all resources in all event pages on the map,
  44. * regardless of if they will be triggered by the player at any time or not.
  45. * Since page conditions cannot be predicted as they are dependent on player
  46. * interaction, this is a necessity to ensure the right files are ready and
  47. * preloaded.
  48. *
  49. * For updates and easy to use documentation, please go to the plugin's website:
  50. * [url]http://mvplugins.tordamian.com/?p=29[/url]
  51. *
  52. * There you can also download a PDF of the documentation for offline use, and
  53. * having the documentation in one cleanly presented place means you can always
  54. * be sure it's the most recent available.
  55. *
  56. * Table of contents
  57. * -----------------
  58. * 1. Installation
  59. * 2. Advanced Configuration
  60. * 3. Terms & Conditions
  61. *
  62. * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  63. * 1. Installation
  64. * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  65. * Drag and drop plugin .js file into your project's js/plugins folder, then
  66. * enable it in the editor interface.
  67. *
  68. * Make sure this plugin is placed at the top for maximum compatibility.
  69. *
  70. * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  71. * 2. Advanced Configuration
  72. * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  73. * There is an advanced configuration section if you open the plugin .js file
  74. * in a text editor. Look for BOOT PRELOAD CONFIG -- ADVANCED USERS. This lets
  75. * you define resources to preload on boot manually.
  76. *
  77. * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  78. * 3. Terms & Conditions
  79. * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  80. * This plugin is free for both non-commercial and commercial use.
  81. *
  82. * A big thank you to Degica for making this plugin free for commercial use for
  83. * everyone!
  84. *
  85. * MIT License
  86. *
  87. * Copyright (c) 2019 Tor Damian Design
  88. *
  89. * Permission is hereby granted, free of charge, to any person obtaining a copy
  90. * of this software and associated documentation files (the "Software"), to deal
  91. * in the Software without restriction, including without limitation the rights
  92. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  93. * copies of the Software, and to permit persons to whom the Software is
  94. * furnished to do so, subject to the following conditions:
  95. *
  96. * The above copyright notice and this permission notice shall be included in all
  97. * copies or substantial portions of the Software.
  98. *
  99. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  100. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  101. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  102. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  103. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  104. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  105. * SOFTWARE.
  106. */
  107. /*
  108. * =============================================================================
  109. * BOOT PRELOAD CONFIG -- ADVANCED USERS
  110. * =============================================================================
  111. *
  112. * Tip: You can omit the filename, it will assume .png since this is what MV
  113. * prefers.
  114. *
  115. * -----------------------------------------------------------------------------
  116. * Image files to load on boot:
  117. * -----------------------------------------------------------------------------
  118. * Keys:
  119. *   animation
  120. *   battleback1
  121. *   battleback2
  122. *   character
  123. *   enemy
  124. *   face
  125. *   parallax
  126. *   picture
  127. *   svActor
  128. *   svEnemy
  129. *   system
  130. *   tileset
  131. *   title1
  132. *   title2
  133. *
  134. * If you have subfolders in any of these folders, just prepend that to the
  135. * filename, like this example, where the picture "arrow" is in the "cursors"
  136. * subfolder within the system folder:
  137. *
  138. * system: [
  139. *   "balloon",
  140. *   "cursors/arrow"
  141. * ]
  142. */
  143. TDDP.bootPreloadImages = {
  144.     /* Example
  145.     face: [
  146.         "Actor3"
  147.     ],
  148.     system: [
  149.       "myFile",
  150.       "subfolder/myOtherFile"
  151.     ]
  152.     */
  153. }
  154. /*
  155. *
  156. * -----------------------------------------------------------------------------
  157. * BGM files to load on boot
  158. * -----------------------------------------------------------------------------
  159. */
  160. TDDP.bootPreloadBGM = [
  161.     // "Town1"
  162. ]
  163. /*
  164. *
  165. * -----------------------------------------------------------------------------
  166. * BGS files to load on boot
  167. * -----------------------------------------------------------------------------
  168. */
  169. TDDP.bootPreloadBGS = [
  170.     // "Quake"
  171. ]
  172. /*
  173. *
  174. * -----------------------------------------------------------------------------
  175. * SFX files to load on boot.
  176. * -----------------------------------------------------------------------------
  177. */
  178. TDDP.bootPreloadSE = [
  179.     // "Open2"
  180. ]
  181. /*
  182. *
  183. * -----------------------------------------------------------------------------
  184. * ME files to load on boot.
  185. * -----------------------------------------------------------------------------
  186. */
  187. TDDP.bootPreloadME = [
  188.     // "Shock1"
  189. ]
  190. //=============================================================================
  191. // END OF BOOT PRELOAD CONFIG
  192. //=============================================================================
  193. var PreloadManager;
  194. (function() {
  195.     "use strict";
  196.     // Skip preloading if event test
  197.     if (DataManager.isEventTest()) return;
  198.     //=============================================================================
  199.     // Setting up parameters
  200.     //=============================================================================
  201.     var parameters         = $plugins.filter(function(p){return p.description.contains("id:TDDP_PreloadManager")})[0].parameters;
  202.     var preloadOnMapLoad   = Boolean(parameters['Preload On Map Load']       === 'true' || false);
  203.     var preloadSystemMusic = Boolean(parameters['Preload System Music']      === 'true' || false);
  204.     var preloadSystemSFX   = Boolean(parameters['Preload System SFX']        === 'true' || false);
  205.     var debug              = Boolean(parameters['Print Debug to Console']    === 'true' || false);
  206.     if(debug) console.log("========= TDDP PreloadManager: Debug mode on =========")

  207.     PreloadManager = function() {
  208.         throw new Error('This is a static class');
  209.     };

  210.     PreloadManager._callOnComplete = false;
  211.     PreloadManager._filesLoaded = 0;
  212.     PreloadManager._filesTotal = 0;
  213.     PreloadManager._ready = false;
  214.     PreloadManager._preloadedMaps = [];
  215.     PreloadManager._preloadedAudio = [];
  216.     PreloadManager._sessionRequestedImages = [];

  217.     PreloadManager.callOnComplete = function(func) {
  218.         this._callOnComplete = func;
  219.     };

  220.     PreloadManager.start = function() {
  221.         this._ready = true;
  222.         this._sessionRequestedImages = [];
  223.         this.controlIfReady(true);
  224.     };

  225.     PreloadManager._projectPath = function() {
  226.         var path = window.location.pathname.replace(/\/[^\/]*$/, "/");
  227.         if (path.match(/^\/([A-Z]\:)/)) {
  228.             path = path.slice(1);
  229.         }
  230.         return decodeURIComponent(path);
  231.     };

  232.     PreloadManager.controlAudioFileExistence = function(folder, filename) {
  233.         this.controlFileExistence("audio/" + folder + "/", filename, [".m4a", ".ogg"]);
  234.     };

  235.     PreloadManager.controlFileExistence = function(folder, filename, extensions) {
  236.         if (StorageManager.isLocalMode() && Utils.isOptionValid('test')) {
  237.             var fs = require("fs");
  238.             var path = this._projectPath() + folder + filename;
  239.             for (var i=0, max=extensions.length; i < max; i++) {
  240.                 if (fs.existsSync(path + extensions[i])) return true;
  241.             }
  242.             throw new Error("PreloadManager: File " + folder + filename + " could not be found. Does it exist?")
  243.         }
  244.     };

  245.     PreloadManager.preloadImages = function(type, filename, hue) {
  246.         if(filename.constructor === Array) {
  247.             for(var i = 0; i < filename.length; i++) {
  248.                 this.preloadImages(type, filename[i], hue);
  249.             }
  250.         } else {
  251.             if(filename.length > 0) {
  252.                 if (this._isImageRequested(type, filename)) return;
  253.                 var func = "load" + type.charAt(0).toUpperCase() + type.substr(1).toLowerCase();
  254.                 if(typeof ImageManager[func] === 'undefined') {
  255.                     e = "PreloadManager: " + type + " is not a valid image load key. Check your configuration.";
  256.                     Graphics.printError(e);
  257.                     throw new Error(e);
  258.                 }
  259.                 this._increaseFileNums();
  260.                 ImageManager[func](filename, hue).addLoadListener(this.onFileLoaded.bind(this, "(" + type + ") " + filename));
  261.                 this._registerRequestedImage(type, filename);
  262.             }
  263.         }
  264.     };

  265.     PreloadManager.preloadBGM = function(audioObject) {
  266.         this.preloadAudio("bgm", audioObject);
  267.     };

  268.     PreloadManager.preloadBGS = function(audioObject) {
  269.         this.preloadAudio("bgs", audioObject);
  270.     };

  271.     PreloadManager.preloadSE = function(audioObject) {
  272.         this.preloadAudio("se", audioObject);
  273.     }

  274.     PreloadManager.preloadME = function(audioObject) {
  275.         this.preloadAudio("me", audioObject);
  276.     }

  277.     PreloadManager.preloadAudio = function(type, audioObject) {
  278.         if (!audioObject) return;
  279.         if(audioObject.constructor === Array) {
  280.             for(var i = 0, max = audioObject.length; i < max; i++) {
  281.                 this.preloadAudio(type, audioObject[i]);
  282.             }
  283.         } else {
  284.             if(audioObject.name.length <= 0) return;
  285.             if(this.isAudioCached(type, audioObject.name)) {
  286.                 if(debug) console.log(type + "/" + audioObject.name + " already preloaded; skipping.");
  287.                 return;
  288.             }
  289.             this._increaseFileNums();
  290.             this.controlAudioFileExistence(type, audioObject.name);
  291.             var bufferObject = AudioManager.createBuffer(type, audioObject.name);
  292.             bufferObject.addLoadListener(this.onAudioFileLoaded.bind(this, type, audioObject.name));
  293.         }
  294.     }

  295.     PreloadManager.preloadAnimation = function(animationId) {
  296.         var animation = $dataAnimations[animationId];
  297.         this.preloadImages('animation', [animation.animation1Name, animation.animation2Name]);
  298.         for(var i=0, max=animation.timings.length; i<max; i++) {
  299.             var se = animation.timings[i].se;
  300.             this.preloadSE(se);
  301.         }
  302.     }

  303.     PreloadManager.preloadMapResources = function(mapId) {
  304.         this._ready = false;
  305.         // Wait and ensure map is loaded
  306.         if(!DataManager.isMapDataLoaded()) return setTimeout(this.preloadMapResources.bind(this, mapId), 100);
  307.         var mapDebugName = mapId + " (" + $dataMapInfos[mapId].name + ")";
  308.         if(this._preloadedMaps.indexOf(mapId) > -1) {
  309.             if(debug) console.log("Map " + mapDebugName + " already preloaded, skipping.");
  310.         } else {
  311.             if(debug) console.log("Map " + mapDebugName + " preload starting.");
  312.             // Map is loaded, preload resources now
  313.             this.preloadBGM($dataMap.bgm);
  314.             this.preloadBGS($dataMap.bgs);
  315.             this.preloadImages('battleback1', $dataMap.battleback1Name);
  316.             this.preloadImages('battleback2', $dataMap.battleback2Name);
  317.             this.preloadImages('parallax', $dataMap.parallaxName);
  318.             // Cycle events and load appropriate resources
  319.             for(var i = 0, max = $dataMap.events.length; i < max; i++) {
  320.                 var event = $dataMap.events[i];
  321.                 if(!event) continue;
  322.                 for(var p = 0, pMax = event.pages.length; p < pMax; p++) {
  323.                     var page = event.pages[p];
  324.                     // Preload character graphic for page
  325.                     this.preloadImages('character', page.image.characterName);
  326.                     for(var l = 0, lMax = page.list.length; l < lMax; l++) {
  327.                         var listEntry = page.list[l];
  328.                         this.preloadEventListEntry(listEntry);
  329.                     }
  330.                 }
  331.             };
  332.             this._preloadedMaps.push(mapId);
  333.         }
  334.         this.start(true);
  335.     };

  336.     PreloadManager.preloadEventListEntry = function(listEntry) {
  337.         var code = listEntry.code;
  338.         var parameters = listEntry.parameters;
  339.         switch(code) {
  340.             // Show Picture
  341.             case 231:
  342.                 this.preloadImages('picture', parameters[1]);
  343.                 break;
  344.             // Play BGM
  345.             case 241:
  346.                 this.preloadBGM(parameters[0]);
  347.                 break;
  348.             // Play BGS
  349.             case 245:
  350.                 this.preloadBGS(parameters[0]);
  351.                 break;
  352.             // Play ME
  353.             case 249:
  354.                 this.preloadME(parameters[0]);
  355.                 break;
  356.             // Play SE
  357.             case 250:
  358.                 this.preloadSE(parameters[0]);
  359.                 break;
  360.             // Change Parallax
  361.             case 284:
  362.                 this.preloadImages('parallax', parameters[0]);
  363.                 break;
  364.             // Show Text
  365.             case 101:
  366.                 this.preloadImages('face', parameters[0]);
  367.                 break;
  368.             // Show Animation
  369.             case 212:
  370.                 this.preloadAnimation(parameters[1]);
  371.                 break;
  372.         }
  373.     };

  374.     PreloadManager.onFileLoaded = function(filename) {
  375.         this._filesLoaded += 1;
  376.         if(debug) console.log("Loaded file: " + filename + "(" + this._filesLoaded + "/" + this._filesTotal + ")");
  377.         this.controlIfReady();
  378.     };

  379.     PreloadManager.onAudioFileLoaded = function(type, filename) {
  380.         this._cacheAudio(type, filename);
  381.         this.onFileLoaded("(" + type + ") " + filename);
  382.     };

  383.     PreloadManager.controlIfReady = function(manual) {
  384.         if(this.isReady()) {
  385.             if(debug && !manual) console.log("All files loaded (" + this._filesLoaded + "/" + this._filesTotal + ")");
  386.             this._filesTotal = this._filesLoaded = 0;
  387.             if(this._callOnComplete) {
  388.                 this._callOnComplete.call();
  389.             }
  390.         }
  391.     }

  392.     PreloadManager._cacheAudio = function(path, filename) {
  393.         this._preloadedAudio.push(path + filename);
  394.     };

  395.     PreloadManager._registerRequestedImage = function(type, filename) {
  396.         this._sessionRequestedImages.push(type + filename);
  397.     };

  398.     PreloadManager._isImageRequested = function(type, filename) {
  399.         return this._sessionRequestedImages.indexOf(type + filename) > -1;
  400.     }

  401.     PreloadManager.isAudioCached = function(path, filename) {
  402.         return this._preloadedAudio.indexOf(path + filename) > -1;
  403.     }

  404.     PreloadManager._increaseFileNums = function() {
  405.         this._ready = false;
  406.         this._filesTotal +=1;
  407.     };

  408.     PreloadManager.isReady = function() {
  409.         if(this._filesLoaded >= this._filesTotal) {
  410.             if(this._ready || this._filesTotal == 0) {
  411.                 return true;
  412.             }
  413.         }
  414.         return false;
  415.     };

  416.     var _isDatabaseLoaded = function() {
  417.         DataManager.checkError();
  418.         for (var i = 0; i < DataManager._databaseFiles.length; i++) {
  419.             if (!window[DataManager._databaseFiles[i].name]) {
  420.                 return false;
  421.             }
  422.         }
  423.         return true;
  424.     }

  425.     //=============================================================================
  426.     // Scene_Boot extensions
  427.     //=============================================================================
  428.     var Scene_Boot_prototype_create =
  429.         Scene_Boot.prototype.create;
  430.     Scene_Boot.prototype.create = function() {
  431.         Scene_Boot_prototype_create.call(this);
  432.         this._performPreload();
  433.     };

  434.     Scene_Boot.prototype._performPreload = function() {
  435.         if(!_isDatabaseLoaded()) return setTimeout(this._performPreload.bind(this), 5);
  436.         if(debug) console.log("========= TDDP PreloadManager: Boot Preload =========");
  437.         // Preload bootPreloadImages resources
  438.         if(TDDP.bootPreloadImages) {
  439.             for(var key in TDDP.bootPreloadImages) {
  440.                 if(TDDP.bootPreloadImages.hasOwnProperty(key)) {
  441.                     PreloadManager.preloadImages(key, TDDP.bootPreloadImages[key]);
  442.                 }
  443.             }
  444.         }
  445.         // Preload bootPreloadBGM resources
  446.         if(TDDP.bootPreloadBGM && TDDP.bootPreloadBGM.length > 0) {
  447.             for(var i = 0, max = TDDP.bootPreloadBGM.length; i < max; i++) {
  448.                 PreloadManager.preloadBGM({
  449.                     name: TDDP.bootPreloadBGM[i],
  450.                     volume: 90,
  451.                     pitch: 100
  452.                 });
  453.             }
  454.         }
  455.         // Preload bootPreloadBGS resources
  456.         if(TDDP.bootPreloadBGS && TDDP.bootPreloadBGS.length > 0) {
  457.             for(var i = 0, max = TDDP.bootPreloadBGS.length; i < max; i++) {
  458.                 PreloadManager.preloadBGS({
  459.                     name: TDDP.bootPreloadBGS[i],
  460.                     volume: 90,
  461.                     pitch: 100
  462.                 });
  463.             }
  464.         }
  465.         // Preload bootPreloadSE resources
  466.         if(TDDP.bootPreloadSE && TDDP.bootPreloadSE.length > 0) {
  467.             for(var i = 0, max = TDDP.bootPreloadSE.length; i < max; i++) {
  468.                 PreloadManager.preloadSE({
  469.                     name: TDDP.bootPreloadSE[i],
  470.                     volume: 90,
  471.                     pitch: 100
  472.                 });
  473.             }
  474.         }
  475.         // Preload bootPreloadME resources
  476.         if(TDDP.bootPreloadME && TDDP.bootPreloadME.length > 0) {
  477.             for(var i = 0, max = TDDP.bootPreloadME.length; i < max; i++) {
  478.                 PreloadManager.preloadME({
  479.                     name: TDDP.bootPreloadME[i],
  480.                     volume: 90,
  481.                     pitch: 100
  482.                 });
  483.             }
  484.         }
  485.         // Preload system SFX if set
  486.         if(preloadSystemSFX) {
  487.             if(debug) console.log("========= TDDP PreloadManager: Boot Preloading System SFX =========");
  488.             for(var i = 0, max = $dataSystem.sounds.length; i < max; i++) {
  489.                 PreloadManager.preloadSE($dataSystem.sounds[i]);
  490.             }
  491.         }
  492.         // Preload system BGM and ME if set
  493.         if(preloadSystemMusic) {
  494.             if(debug) console.log("========= TDDP PreloadManager: Boot Preloading System Music =========");
  495.             [
  496.                 $dataSystem.titleBgm,
  497.                 $dataSystem.battleBgm,
  498.                 $dataSystem.boat.bgm,
  499.                 $dataSystem.ship.bgm,
  500.                 $dataSystem.airship.bgm,
  501.             ].forEach(function(bgm) {
  502.                 PreloadManager.preloadBGM(bgm);
  503.             });
  504.             [
  505.                 $dataSystem.victoryMe,
  506.                 $dataSystem.defeatMe,
  507.                 $dataSystem.gameoverMe,
  508.             ].forEach(function(me) {
  509.                 PreloadManager.preloadME(me);
  510.             });
  511.         }
  512.         PreloadManager.start();
  513.     };

  514.     //=============================================================================
  515.     // DataManager extensions
  516.     //=============================================================================
  517.     if (preloadOnMapLoad) {
  518.         var DataManager_loadMapData =
  519.             DataManager.loadMapData;
  520.         DataManager.loadMapData = function(mapId) {
  521.             if(debug) console.log("========= TDDP PreloadManager: Map Preload =========");
  522.             this._preloaded = false;
  523.             DataManager_loadMapData.call(this, mapId);
  524.             PreloadManager.preloadMapResources(mapId);
  525.             PreloadManager.callOnComplete(this._onPreloadDone.bind(this));
  526.         }

  527.         DataManager._onPreloadDone = function() {
  528.             this._preloaded = true;
  529.         }

  530.         var DataManager_isMapLoaded =
  531.             DataManager.isMapLoaded;
  532.         DataManager.isMapLoaded = function() {
  533.             return (this.isMapDataLoaded() && this._preloaded);
  534.         }

  535.         DataManager.isMapDataLoaded = function() {
  536.             return DataManager_isMapLoaded.call(this);
  537.         }
  538.     }

  539.     //=============================================================================
  540.     // Scene_Base extensions
  541.     //=============================================================================
  542.     var Scene_Base_prototype_isReady =
  543.         Scene_Base.prototype.isReady;
  544.     Scene_Base.prototype.isReady = function() {
  545.         if(!PreloadManager.isReady()) return false;
  546.         return Scene_Base_prototype_isReady.call(this);
  547.     }

  548.     //=============================================================================
  549.     // Html5Audio extensions
  550.     //=============================================================================
  551.     /**
  552.      * Sets up the Html5 Audio.
  553.      *
  554.      * @static
  555.      * @method setup
  556.      * @param {String} url The url of the audio file
  557.      */
  558.     Html5Audio.setup = function (url) {
  559.         if (!this._initialized) {
  560.             this.initialize();
  561.         }
  562.         this.clear();
  563.         this._load(url); // Changed from this._url = url to call the _load func; this func is never loaded by default
  564.     };

  565.     /**
  566.      * @static
  567.      * @method _setupEventHandlers
  568.      * @private
  569.      */
  570.     Html5Audio._setupEventHandlers = function () {
  571.         document.addEventListener('touchstart', this._onTouchStart.bind(this));
  572.         document.addEventListener('visibilitychange', this._onVisibilityChange.bind(this));
  573.         this._audioElement.addEventListener("canplaythrough", this._onLoadedData.bind(this)); // Changed from loaddata to canplaythrough, so it knows streaming is stable enough
  574.         this._audioElement.addEventListener("error", this._onError.bind(this));
  575.         this._audioElement.addEventListener("ended", this._onEnded.bind(this));
  576.     };

  577.     /**
  578.      * @static
  579.      * @method _onLoadedData
  580.      * @private
  581.      */
  582.     Html5Audio._onLoadedData = function () {
  583.         this._buffered = true;
  584.         this._onLoad(); // I removed check for this._unlocked because that shouldn't matter
  585.     };
  586. })();
复制代码
您需要登录后才可以回帖 登录 | 注册会员

本版积分规则

Powered by Discuz! X5.0 © 2001-2026 Discuz! Team.

在本版发帖返回顶部