From 35f166fe9a0efa5ef28879c2c7cba103547c3f74 Mon Sep 17 00:00:00 2001 From: unanmed <1319491857@qq.com> Date: Tue, 28 Feb 2023 20:09:41 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E7=83=AD=E9=87=8D=E8=BD=BD?= =?UTF-8?q?=E4=B8=8E=E6=89=93=E5=8C=85=E7=9A=84=E7=BB=86=E8=8A=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- public/libs/actions.js | 4 ++-- public/main.js | 2 +- public/server.cjs | 27 +++++++++++++++++---------- script/compress.ts | 1 - 4 files changed, 20 insertions(+), 14 deletions(-) diff --git a/public/libs/actions.js b/public/libs/actions.js index 5adc24a..d5a5375 100644 --- a/public/libs/actions.js +++ b/public/libs/actions.js @@ -731,7 +731,7 @@ actions.prototype._sys_onmove_choices = function (x, y, px, py) { actions.prototype._sys_onmove = function (x, y, px, py) { if (core.status.lockControl) return false; - if (core.status.preview.dragging) { + if (core.status.preview?.dragging) { core.setViewport( core.bigmap.offsetX - px + core.status.preview.px, core.bigmap.offsetY - py + core.status.preview.py @@ -740,7 +740,7 @@ actions.prototype._sys_onmove = function (x, y, px, py) { core.status.preview.py = py; return true; } - if (core.status.preview.prepareDragging) { + if (core.status.preview?.prepareDragging) { if ( Math.abs(px - core.status.preview.px) <= 20 && Math.abs(py - core.status.preview.py) <= 20 diff --git a/public/main.js b/public/main.js index a162e5b..de39107 100644 --- a/public/main.js +++ b/public/main.js @@ -328,7 +328,7 @@ main.prototype.init = async function (mode, callback) { core.resetSettings(); core.plugin.showMarkedEnemy.value = true; } - if (main.useCompress) { + if (main.pluginUseCompress) { await main.loadScript(`project/plugin.min.js?v=${main.version}`); } else { for await (const plugin of mainData.plugin) { diff --git a/public/server.cjs b/public/server.cjs index 1f8dd35..f0dc4dd 100644 --- a/public/server.cjs +++ b/public/server.cjs @@ -26,9 +26,6 @@ let hotReloadData = ''; /** 是否已经启动了热重载模块 */ let watched = false; -/** 是否已经启动了录像调试模块 */ -let replayed = false; - /** 监听端口 */ let port = 3000; const next = () => { @@ -41,11 +38,18 @@ const next = () => { }; next(); -let repStart; - const listenedFloors = []; const listenedPlugins = []; +const hasPlugin = (function () { + try { + fss.readdirSync('./project/plugin'); + return true; + } catch { + return false; + } +})(); + // ----- GET file /** @@ -346,10 +350,12 @@ async function watch() { }); // 插件热重载 - const plugins = await extract('project/plugin/*.js'); - plugins.forEach(v => { - watchOnePlugin(v.slice(15)); - }); + if (hasPlugin) { + const plugins = await extract('project/plugin/*.js'); + plugins.forEach(v => { + watchOnePlugin(v.slice(15)); + }); + } // 数据热重载 const datas = (await extract('project/*.js')).filter( @@ -383,6 +389,7 @@ function testWatchFloor(url) { * @param {string} url 要测试的路径 */ function testWatchPlugin(url) { + if (!hasPlugin) return; if (/project(\/|\\)plugin(\/|\\).*\.js/.test(url)) { const f = url.slice(15); if (!listenedFloors.includes(f.slice(0, -3))) { @@ -414,7 +421,7 @@ function watchOneFloor(file) { function watchOnePlugin(file) { if (!/.*\.js/.test(file)) return; const f = file.slice(0, -3); - listenedFloors.push(file.slice(0, -3)); + listenedPlugins.push(file.slice(0, -3)); fss.watchFile(`project/plugin/${file}`, { interval: 500 }, () => { const plugin = f; if (hotReloadData.includes(`@@plugin:${plugin}`)) return; diff --git a/script/compress.ts b/script/compress.ts index 8f31fa2..a06dbf5 100644 --- a/script/compress.ts +++ b/script/compress.ts @@ -39,7 +39,6 @@ import { exec } from 'child_process'; }) ); await fse.remove('./dist/maps/'); - await fse.remove('./dist/extensions/'); } catch {} // 2. 压缩字体