diff --git a/.prettierignore b/.prettierignore index 4a9dabf..4548b2d 100644 --- a/.prettierignore +++ b/.prettierignore @@ -9,4 +9,5 @@ script/**/*.js public/editor.html keyCodes.ts *.md -setting.ts \ No newline at end of file +setting.ts +dist/project/data.js \ No newline at end of file diff --git a/public/libs/control.js b/public/libs/control.js index 731bd1e..d4ab42a 100644 --- a/public/libs/control.js +++ b/public/libs/control.js @@ -3394,58 +3394,74 @@ control.prototype.screenFlash = function ( control.prototype.playBgm = function (bgm, startTime) { bgm = core.getMappedName(bgm); if (main.mode !== 'play') return; - Mota.require('var', 'bgm').changeTo(bgm, startTime); + Mota.r(() => { + Mota.require('var', 'bgm').changeTo(bgm, startTime); + }); }; ////// 暂停背景音乐的播放 ////// control.prototype.pauseBgm = function () { if (main.mode !== 'play') return; - Mota.require('var', 'bgm').pause(); + Mota.r(() => { + Mota.require('var', 'bgm').pause(); + }); }; ////// 恢复背景音乐的播放 ////// control.prototype.resumeBgm = function (resumeTime) { if (main.mode !== 'play') return; - Mota.require('var', 'bgm').resume(); + Mota.r(() => { + Mota.require('var', 'bgm').resume(); + }); }; ////// 更改背景音乐的播放 ////// control.prototype.triggerBgm = function () { if (main.mode !== 'play') return; - const bgm = Mota.require('var', 'bgm'); - bgm.disable = !bgm.disable; + Mota.r(() => { + const bgm = Mota.require('var', 'bgm'); + bgm.disable = !bgm.disable; - if (!bgm.disable) this.resumeBgm(); - else this.pauseBgm(); + if (!bgm.disable) this.resumeBgm(); + else this.pauseBgm(); + }); }; // todo: deprecate playSound, stopSound, getPlayingSounds ////// 播放音频 ////// control.prototype.playSound = function (sound, pitch, callback) { - sound = core.getMappedName(sound); - Mota.require('var', 'sound').play(sound, callback); + Mota.r(() => { + sound = core.getMappedName(sound); + Mota.require('var', 'sound').play(sound, callback); + }); }; ////// 停止所有音频 ////// control.prototype.stopSound = function (id) { - if (typeof id === 'number') Mota.require('var', 'sound').stop(id); - else Mota.require('var', 'sound').stopAll(); + Mota.r(() => { + if (typeof id === 'number') Mota.require('var', 'sound').stop(id); + else Mota.require('var', 'sound').stopAll(); + }); }; ////// 获得当前正在播放的所有(指定)音效的id列表 ////// control.prototype.getPlayingSounds = function (name) { - name = core.getMappedName(name); - return Mota.require('var', 'sound').getPlaying(name); + Mota.r(() => { + name = core.getMappedName(name); + return Mota.require('var', 'sound').getPlaying(name); + }); }; ////// 检查bgm状态 ////// control.prototype.checkBgm = function () { - const bgm = Mota.require('var', 'bgm'); - if (bgm.disable) { - bgm.pause(); - } else if (!bgm.playing) { - bgm.changeTo(bgm.now ?? main.startBgm); - } + Mota.r(() => { + const bgm = Mota.require('var', 'bgm'); + if (bgm.disable) { + bgm.pause(); + } else if (!bgm.playing) { + bgm.changeTo(bgm.now ?? main.startBgm); + } + }); }; ///// 设置屏幕放缩 ////// diff --git a/public/libs/core.js b/public/libs/core.js index c1ad8b0..9d0e34b 100644 --- a/public/libs/core.js +++ b/public/libs/core.js @@ -306,6 +306,7 @@ core.prototype.initSync = function (coreData, callback) { this._forwardFuncs(); for (var key in coreData) core[key] = coreData[key]; this._loadGameProcessSync(); + this._loadPluginSync(); this._init_flags(); this._init_platform(); this._init_others(); @@ -319,6 +320,18 @@ core.prototype._loadPluginAsync = async function () { if (!main.useCompress) { await main.loadScript(`project/plugins.js?v=${main.version}`); } + this._initPlugins(); +}; + +core.prototype._loadPluginSync = function () { + if (main.useCompress) main.loadMod('project', 'project', () => 0); + else { + main.pureData.forEach(v => main.loadMod('project', v, () => 0)); + } + this._initPlugins(); +}; + +core.prototype._initPlugins = function () { for (const [key, value] of Object.entries( plugins_bb40132b_638b_4a9f_b028_d3fe47acc8d1 )) { @@ -331,10 +344,6 @@ core.prototype._loadPluginAsync = async function () { } }; -core.prototype._loadPluginSync = function () { - main.loadMod('project', 'plugins', () => 0); -}; - core.prototype._loadGameProcess = async function () { // 加载游戏进程代码 if (main.pluginUseCompress && main.replayChecking) { diff --git a/public/libs/loader.js b/public/libs/loader.js index 4a47318..491e687 100644 --- a/public/libs/loader.js +++ b/public/libs/loader.js @@ -486,7 +486,9 @@ loader.prototype._loadMusic_sync = function () { core.loader.loadOneSound(t); }); // 直接开始播放 - core.playBgm(main.startBgm); + Mota.r(() => { + core.playBgm(main.startBgm); + }); }; loader.prototype._loadMusic_async = function (onprogress, onfinished) { @@ -525,12 +527,14 @@ loader.prototype.loadOneMusic = function (name) { music.loop = 'loop'; core.material.bgms[name] = music; } else { - if (!main.renderLoaded) { - Mota.require('var', 'hook').once('renderLoaded', () => { - Mota.require('var', 'bgm').add(`bgms.${name}`, music); - }); - } - Mota.require('var', 'bgm').add(`bgms.${name}`, music); + Mota.r(() => { + if (!main.renderLoaded) { + Mota.require('var', 'hook').once('renderLoaded', () => { + Mota.require('var', 'bgm').add(`bgms.${name}`, music); + }); + } + Mota.require('var', 'bgm').add(`bgms.${name}`, music); + }); } }; @@ -543,15 +547,17 @@ loader.prototype.loadOneSound = function (name) { if (main.mode === 'editor') { core.loader._loadOneSound_decodeData(name, data); } else { - if (!main.renderLoaded) { - Mota.require('var', 'hook').once('renderLoaded', () => { + Mota.r(() => { + if (!main.renderLoaded) { + Mota.require('var', 'hook').once('renderLoaded', () => { + const sound = Mota.require('var', 'sound'); + sound.add(`sounds.${name}`, data); + }); + } else { const sound = Mota.require('var', 'sound'); sound.add(`sounds.${name}`, data); - }); - } else { - const sound = Mota.require('var', 'sound'); - sound.add(`sounds.${name}`, data); - } + } + }); } }, function (e) { diff --git a/public/main.js b/public/main.js index 8415057..121df39 100644 --- a/public/main.js +++ b/public/main.js @@ -298,10 +298,15 @@ main.prototype.loadSync = function (mode, callback) { }); core.initSync(coreData, callback); + main.loading.emit('coreLoaded'); + main.loading.emit('coreInit'); + core.initStatus.maps = core.maps._initMaps(); core.resize(); main.core = core; core.completeAchievement = () => 0; + + core.plugin = { drawLight: 0 }; }; main.prototype.loadAsync = async function (mode, callback) { diff --git a/src/game/game.ts b/src/game/game.ts index 4ff3a47..a2ed03f 100644 --- a/src/game/game.ts +++ b/src/game/game.ts @@ -114,7 +114,7 @@ class GameListener extends EventEmitter { constructor() { super(); - + if (main.replayChecking) return; if (!!window.core) { this.init(); } else { diff --git a/src/plugin/game/fx/itemDetail.ts b/src/plugin/game/fx/itemDetail.ts index 52b7481..ea0a5d7 100644 --- a/src/plugin/game/fx/itemDetail.ts +++ b/src/plugin/game/fx/itemDetail.ts @@ -31,10 +31,11 @@ export function init() { floor.enemy.calMapDamage(); core.status.damage.data = []; - floor.enemy.render(true); - - getItemDetail(floorId, onMap); // 宝石血瓶详细信息 - this.drawDamage(ctx, floorId); + Mota.r(() => { + floor.enemy.render(true); + getItemDetail(floorId, onMap); // 宝石血瓶详细信息 + this.drawDamage(ctx, floorId); + }); }; }