From e028046dd254032b0a8cc240d0fdd76fa67d4d08 Mon Sep 17 00:00:00 2001 From: SmallMain Date: Wed, 30 Oct 2024 17:39:35 +0800 Subject: [PATCH] =?UTF-8?q?[common]=20=E8=AE=BE=E7=BD=AE=E9=9D=A2=E6=9D=BF?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=20CC=5FWORKER=5FAUDIO=5FSYSTEM=5FSYNC=5FINTE?= =?UTF-8?q?RVAL=20=E9=80=89=E9=A1=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- extension/main.js | 27 +++++++++++++++++++++------ extension/panel/index.js | 23 +++++++++++++++++++++-- 2 files changed, 42 insertions(+), 8 deletions(-) diff --git a/extension/main.js b/extension/main.js index 7e57ee2c..a14d0af7 100644 --- a/extension/main.js +++ b/extension/main.js @@ -44,6 +44,7 @@ function getSettings() { CC_WORKER_ASSET_PIPELINE: getMacroBooleanValue(content, "CC_WORKER_ASSET_PIPELINE"), CC_WORKER_AUDIO_SYSTEM: getMacroBooleanValue(content, "CC_WORKER_AUDIO_SYSTEM"), CC_WORKER_SCHEDULER: getMacroBooleanValue(content, "CC_WORKER_SCHEDULER"), + CC_WORKER_AUDIO_SYSTEM_SYNC_INTERVAL: getMacroIntegerValue(content, "CC_WORKER_AUDIO_SYSTEM_SYNC_INTERVAL"), }; } } @@ -55,7 +56,7 @@ function syncSettingsToSubWorker() { for (const key in result) { if (key !== "code") { - content = setMacroBooleanValue(content, key, result[key]); + content = setMacroValue(content, key, result[key]); } } @@ -66,7 +67,7 @@ function syncSettingsToSubWorker() { function setSettings(macro, value) { { const content = fs.readFileSync(engineWechatMinigameWorkerMainMacroPath, { encoding: "utf-8" }); - fs.writeFileSync(engineWechatMinigameWorkerMainMacroPath, setMacroBooleanValue(content, macro, value)); + fs.writeFileSync(engineWechatMinigameWorkerMainMacroPath, setMacroValue(content, macro, value)); } checkAndModifyWorkerFiles(); @@ -79,10 +80,24 @@ function getMacroBooleanValue(text, macro) { return match ? match[1] === 'true' : null; } -function setMacroBooleanValue(text, macro, value) { - const regex = new RegExp(`globalThis\\.${macro}\\s*=\\s*(true|false);`); - const replacement = `globalThis.${macro} = ${value};`; - return text.replace(regex, replacement); +function getMacroIntegerValue(text, macro) { + const regex = new RegExp(`globalThis\\.${macro}\\s*=\\s*(\\d+);`); + const match = text.match(regex); + return match ? parseInt(match[1]) : null; +} + +function setMacroValue(text, macro, value) { + if (typeof value === "number") { + const regex = new RegExp(`globalThis\\.${macro}\\s*=\\s*(\\d+);`); + const replacement = `globalThis.${macro} = ${value};`; + return text.replace(regex, replacement); + } else if (typeof value === "boolean") { + const regex = new RegExp(`globalThis\\.${macro}\\s*=\\s*(true|false);`); + const replacement = `globalThis.${macro} = ${value};`; + return text.replace(regex, replacement); + } else { + Editor.error(`setMacroValue: unknown value: ${value}`); + } } function checkAndModifyWorkerFiles() { diff --git a/extension/panel/index.js b/extension/panel/index.js index 791a324c..72463d9e 100644 --- a/extension/panel/index.js +++ b/extension/panel/index.js @@ -24,8 +24,13 @@ Editor.Panel.extend({ - + +
+ + + +
@@ -44,6 +49,8 @@ Editor.Panel.extend({ thread_asset_pipeline_checkbox: '#tapc', thread_audio_system: '#fs', thread_audio_system_checkbox: '#fsc', + thread_audio_system_interval: '#fsi', + thread_audio_system_interval_input: '#fsii', thread_scheduler: '#ts', thread_scheduler_checkbox: '#tsc', }, @@ -63,6 +70,7 @@ Editor.Panel.extend({ this.$thread_debug_checkbox.checked = data.CC_WORKER_DEBUG; this.$thread_asset_pipeline_checkbox.checked = data.CC_WORKER_ASSET_PIPELINE; this.$thread_audio_system_checkbox.checked = data.CC_WORKER_AUDIO_SYSTEM; + this.$thread_audio_system_interval_input.value = data.CC_WORKER_AUDIO_SYSTEM_SYNC_INTERVAL; this.$thread_scheduler_checkbox.checked = data.CC_WORKER_SCHEDULER; this.$thread_debug_checkbox.addEventListener('change', () => { @@ -73,8 +81,19 @@ Editor.Panel.extend({ this.setSettings("CC_WORKER_ASSET_PIPELINE", this.$thread_asset_pipeline_checkbox.checked); }); + const onAudioSystemEnableChange = (enabled) => { + this.$thread_audio_system_interval_input.disabled = !enabled; + }; + onAudioSystemEnableChange(this.$thread_asset_pipeline_checkbox.checked); + this.$thread_audio_system_checkbox.addEventListener('change', () => { - this.setSettings("CC_WORKER_AUDIO_SYSTEM", this.$thread_audio_system_checkbox.checked); + const enabled = this.$thread_audio_system_checkbox.checked; + onAudioSystemEnableChange(enabled); + this.setSettings("CC_WORKER_AUDIO_SYSTEM", enabled); + }); + + this.$thread_audio_system_interval_input.addEventListener('confirm', () => { + this.setSettings("CC_WORKER_AUDIO_SYSTEM_SYNC_INTERVAL", this.$thread_audio_system_interval_input.value); }); this.$thread_scheduler_checkbox.addEventListener('change', () => {