From f77464d6129d256264c6f939323f47b01419f37f Mon Sep 17 00:00:00 2001 From: SimonShiki Date: Mon, 5 Feb 2024 02:08:23 +0000 Subject: [PATCH] :wrench: chore: fix export sprite & add getLanguage Signed-off-by: SimonShiki --- src/injector/inject.ts | 45 +++++++++++++++++++++++++++++------------- src/loader/make-ctx.ts | 7 +++++++ 2 files changed, 38 insertions(+), 14 deletions(-) diff --git a/src/injector/inject.ts b/src/injector/inject.ts index 2087203..5b05159 100644 --- a/src/injector/inject.ts +++ b/src/injector/inject.ts @@ -238,9 +238,37 @@ export function inject (vm: EurekaCompatibleVM) { obj.extensionEnvs = Object.assign({}, obj.extensionEnvs, envs); if (window.eureka.settings.convertProcCall) { - for (const target of obj.targets) { - for (const blockId in target.blocks) { - const block = target.blocks[blockId]; + if ('targets' in obj) { + for (const target of obj.targets) { + for (const blockId in target.blocks) { + const block = target.blocks[blockId]; + if (!block.opcode) continue; + const extensionId = getExtensionIdForOpcode(block.opcode); + if (!extensionId) continue; + if (sideloadIds.includes(extensionId)) { + if (!('mutation' in block)) block.mutation = {}; + block.mutation.proccode = `[📎 Sideload] ${block.opcode}`; + block.mutation.children = []; + block.mutation.tagName = 'mutation'; + + block.opcode = 'procedures_call'; + } + } + } + for (const i in obj.monitors) { + const monitor = obj.monitors[i]; + if (!monitor.opcode) continue; + const extensionId = getExtensionIdForOpcode(monitor.opcode); + if (!extensionId) continue; + if (sideloadIds.includes(extensionId)) { + if (!('sideloadMonitors' in obj)) obj.sideloadMonitors = []; + obj.sideloadMonitors.push(monitor); + obj.monitors.splice(i, 1); + } + } + } else { + for (const blockId in obj.blocks) { + const block = obj.blocks[blockId]; if (!block.opcode) continue; const extensionId = getExtensionIdForOpcode(block.opcode); if (!extensionId) continue; @@ -254,17 +282,6 @@ export function inject (vm: EurekaCompatibleVM) { } } } - for (const i in obj.monitors) { - const monitor = obj.monitors[i]; - if (!monitor.opcode) continue; - const extensionId = getExtensionIdForOpcode(monitor.opcode); - if (!extensionId) continue; - if (sideloadIds.includes(extensionId)) { - if (!('sideloadMonitors' in obj)) obj.sideloadMonitors = []; - obj.sideloadMonitors.push(monitor); - obj.monitors.splice(i, 1); - } - } } return JSON.stringify(obj); }; diff --git a/src/loader/make-ctx.ts b/src/loader/make-ctx.ts index 77860e3..d00d425 100644 --- a/src/loader/make-ctx.ts +++ b/src/loader/make-ctx.ts @@ -90,6 +90,13 @@ function createTranslate (vm?: VM) { }); } + // TurboWarp/scratch-vm@24b6036 + Object.defineProperty(translate, 'language', { + configurable: true, + enumerable: true, + get: () => getLocale() + }); + return translate; }