From bbd6dfd59c271d0f37996cd902dce39539bb368d Mon Sep 17 00:00:00 2001 From: PYC5635 <3653161641@qq.com> Date: Wed, 18 Nov 2026 20:57:30 +0800 Subject: [PATCH 1/3] feat(settings): add skip-asset-loading setting (ignore costumes when loading projects) --- .../tw-settings-modal/settings-modal.jsx | 24 +++++++++++++++ src/containers/tw-settings-modal.jsx | 11 +++++++ src/lib/mw-skip-asset-loading.js | 30 +++++++++++++++++++ 3 files changed, 65 insertions(+) create mode 100644 src/lib/mw-skip-asset-loading.js diff --git a/src/components/tw-settings-modal/settings-modal.jsx b/src/components/tw-settings-modal/settings-modal.jsx index 02d88706bf2..6a6ca646339 100644 --- a/src/components/tw-settings-modal/settings-modal.jsx +++ b/src/components/tw-settings-modal/settings-modal.jsx @@ -499,6 +499,20 @@ const settingDefinitions = { id: 'mw.settingsModal.embedGitOnSaveHelp' } }, + skipAssetLoading: { + label: { + defaultMessage: 'Ignore Costumes When Loading Projects', + description: 'Skip loading project assets so the project opens immediately', + id: 'mw.settingsModal.skipAssetLoading' + }, + help: { + defaultMessage: 'Opens a project right away without waiting for its costumes and ' + + 'sounds, then loads them gradually in the background. Sprites stay ' + + 'invisible until their costumes arrive.', + description: 'Ignore Costumes When Loading Projects setting help', + id: 'mw.settingsModal.skipAssetLoadingHelp' + } + }, squareStageCorners: { label: { defaultMessage: 'Square Stage Corners', @@ -678,6 +692,7 @@ const RealLayerIndexes = createBooleanSetting('RealLayerIndexes', settingDefinit const EnableStageResize = createBooleanSetting('EnableStageResize', settingDefinitions.enableStageResize); const WindowAnimation = createBooleanSetting('WindowAnimation', settingDefinitions.windowAnimation); const ScriptLazyLoading = createBooleanSetting('ScriptLazyLoading', settingDefinitions.scriptLazyLoading); +const SkipAssetLoading = createBooleanSetting('SkipAssetLoading', settingDefinitions.skipAssetLoading); const EmbedGitOnSave = createBooleanSetting('EmbedGitOnSave', settingDefinitions.embedGitOnSave); const SquareStageCorners = createBooleanSetting('SquareStageCorners', settingDefinitions.squareStageCorners); const HideDeleteButton = createBooleanSetting('HideDeleteButton', settingDefinitions.hideDeleteButton); @@ -1372,6 +1387,13 @@ const pageConfigurations = { onChange: props.onScriptLazyLoadingChange }) }, + { + component: SkipAssetLoading, + props: props => ({ + value: props.skipAssetLoading, + onChange: props.onSkipAssetLoadingChange + }) + }, { component: EmbedGitOnSave, props: props => ({ @@ -1762,6 +1784,8 @@ SettingsModalComponent.propTypes = { windowAnimation: PropTypes.bool, onWindowAnimationChange: PropTypes.func, scriptLazyLoading: PropTypes.bool, + skipAssetLoading: PropTypes.bool, + onSkipAssetLoadingChange: PropTypes.func, onScriptLazyLoadingChange: PropTypes.func, embedGitOnSave: PropTypes.bool, onEmbedGitOnSaveChange: PropTypes.func diff --git a/src/containers/tw-settings-modal.jsx b/src/containers/tw-settings-modal.jsx index 130e937018b..7df7534d236 100644 --- a/src/containers/tw-settings-modal.jsx +++ b/src/containers/tw-settings-modal.jsx @@ -20,6 +20,7 @@ import {getVanillaPalette, setVanillaPalette} from '../lib/mw-vanilla-palette'; import {getEmbedGitOnSave, setEmbedGitOnSave} from '../lib/mw-embed-git-on-save'; import {getDisableCloudVariables, setDisableCloudVariables} from '../lib/mw-editor-defaults.js'; import LazyScratchBlocks from '../lib/tw-lazy-scratch-blocks'; +import {getSkipAssetLoading, setSkipAssetLoading} from '../lib/mw-skip-asset-loading'; import AddonHooks from '../addons/hooks.js'; import WindowManager from '../addons/window-system/window-manager'; @@ -81,6 +82,7 @@ class UsernameModal extends React.Component { enableStageResize: safeGetItem('mw:enable-stage-resize') !== 'false', windowAnimation: safeGetItem('mw:window-animation') !== 'false', scriptLazyLoading: LazyScratchBlocks.isScriptLazyLoadingEnabled(), + skipAssetLoading: getSkipAssetLoading(), hideOperatorArrows: getHideOperatorArrows(), vanillaPalette: getVanillaPalette(), embedGitOnSave: getEmbedGitOnSave(), @@ -118,6 +120,7 @@ class UsernameModal extends React.Component { 'handleCloudVariableServerChange', 'handleWindowAnimationChange', 'handleScriptLazyLoadingChange', + 'handleSkipAssetLoadingChange', 'handleHideOperatorArrowsChange', 'handleVanillaPaletteChange', 'handleEmbedGitOnSaveChange', @@ -348,6 +351,12 @@ class UsernameModal extends React.Component { } } + handleSkipAssetLoadingChange (e) { + const enabled = e.target.checked; + this.setState({skipAssetLoading: enabled}); + setSkipAssetLoading(this.props.vm, enabled); + } + handleHideOperatorArrowsChange (e) { this.setState({hideOperatorArrows: e.target.checked}); setHideOperatorArrows(e.target.checked); @@ -451,6 +460,8 @@ class UsernameModal extends React.Component { onWindowAnimationChange={this.handleWindowAnimationChange} scriptLazyLoading={this.state.scriptLazyLoading} onScriptLazyLoadingChange={this.handleScriptLazyLoadingChange} + skipAssetLoading={this.state.skipAssetLoading} + onSkipAssetLoadingChange={this.handleSkipAssetLoadingChange} onHideOperatorArrowsChange={this.handleHideOperatorArrowsChange} hideOperatorArrows={this.state.hideOperatorArrows} onVanillaPaletteChange={this.handleVanillaPaletteChange} diff --git a/src/lib/mw-skip-asset-loading.js b/src/lib/mw-skip-asset-loading.js new file mode 100644 index 00000000000..b18b69fe193 --- /dev/null +++ b/src/lib/mw-skip-asset-loading.js @@ -0,0 +1,30 @@ +const STORAGE_KEY = 'mw:skip-asset-loading'; + +const getSkipAssetLoading = () => { + try { + return localStorage.getItem(STORAGE_KEY) === 'true'; + } catch (err) { + return false; + } +}; + +const applySkipAssetLoading = vm => { + if (vm && typeof vm.setLoadAssetsLazily === 'function') { + vm.setLoadAssetsLazily(getSkipAssetLoading()); + } +}; + +const setSkipAssetLoading = (vm, enabled) => { + try { + localStorage.setItem(STORAGE_KEY, enabled ? 'true' : 'false'); + } catch (err) { + // ignore + } + applySkipAssetLoading(vm); +}; + +export { + getSkipAssetLoading, + applySkipAssetLoading, + setSkipAssetLoading +}; \ No newline at end of file From d552b8a023a2f7eb195da8fb34361e3237bcabde Mon Sep 17 00:00:00 2001 From: PYC5635 <3653161641@qq.com> Date: Sun, 22 Nov 2026 14:17:59 +0800 Subject: [PATCH 2/3] i18n: add zh-cn translations for skip-asset-loading settings --- src/lib/tw-translations/local-messages.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/lib/tw-translations/local-messages.js b/src/lib/tw-translations/local-messages.js index 5a8db60da6f..5e050f95797 100644 --- a/src/lib/tw-translations/local-messages.js +++ b/src/lib/tw-translations/local-messages.js @@ -462,6 +462,10 @@ const localMessages = { 'tw.browserModal.webglDesktop': '你也可以试试在桌面端设置里打开「硬件加速」选项:', 'tw.browserModal.webglBrowser': '请使用较新版本的 Chrome、Firefox 或 Safari,并确保显卡驱动已更新。你也可以试试在浏览器设置里打开「图形加速」或「硬件加速」选项。', + // 设置窗口:加载作品时忽略造型 + 'mw.settingsModal.skipAssetLoading': '加载作品时忽略造型', + 'mw.settingsModal.skipAssetLoadingHelp': '打开作品时跳过造型和声音的加载,直接进入编辑器,素材随后在后台逐步加载。素材加载完成前,角色会暂时不可见。', + // 字体兜底分类 'tw.fonts.fallback.sansSerif': '无衬线体', 'tw.fonts.fallback.serif': '衬线体', From 558a6a2f40aa798a14bbbc013efa16f76c2a048b Mon Sep 17 00:00:00 2001 From: PYC5635 <3653161641@qq.com> Date: Sun, 22 Nov 2026 15:06:11 +0800 Subject: [PATCH 3/3] fix: apply persisted skip-asset-loading on mount + real lazy install via runtime flag --- src/containers/tw-settings-modal.jsx | 10 ++++++++-- src/lib/mw-skip-asset-loading.js | 28 +++++++++++++++++++++++++--- 2 files changed, 33 insertions(+), 5 deletions(-) diff --git a/src/containers/tw-settings-modal.jsx b/src/containers/tw-settings-modal.jsx index 7df7534d236..890da88cbaa 100644 --- a/src/containers/tw-settings-modal.jsx +++ b/src/containers/tw-settings-modal.jsx @@ -20,7 +20,7 @@ import {getVanillaPalette, setVanillaPalette} from '../lib/mw-vanilla-palette'; import {getEmbedGitOnSave, setEmbedGitOnSave} from '../lib/mw-embed-git-on-save'; import {getDisableCloudVariables, setDisableCloudVariables} from '../lib/mw-editor-defaults.js'; import LazyScratchBlocks from '../lib/tw-lazy-scratch-blocks'; -import {getSkipAssetLoading, setSkipAssetLoading} from '../lib/mw-skip-asset-loading'; +import {getSkipAssetLoading, setSkipAssetLoading, applySkipAssetLoading} from '../lib/mw-skip-asset-loading'; import AddonHooks from '../addons/hooks.js'; import WindowManager from '../addons/window-system/window-manager'; @@ -131,11 +131,17 @@ class UsernameModal extends React.Component { 'handleHideBackpackChange', 'handleTabStyleChange', - 'handleTabLooksChange', + 'handleLooksChange', 'handleWindowStyleChange' ]); } + componentDidMount () { + // 持久化设置在编辑器重启后也要生效:state 初始化只读取了值, + // 必须在此把设置真正应用到 VM(否则开关形同虚设) + applySkipAssetLoading(this.props.vm); + } + handleFramerateChange (e) { this.props.vm.setFramerate(e.target.checked ? 60 : 30); } diff --git a/src/lib/mw-skip-asset-loading.js b/src/lib/mw-skip-asset-loading.js index b18b69fe193..fdb5b89a4a7 100644 --- a/src/lib/mw-skip-asset-loading.js +++ b/src/lib/mw-skip-asset-loading.js @@ -1,3 +1,13 @@ +/** + * 「加载作品时忽略造型」核心逻辑 + * + * 两级实现(按 VM 能力自动选择): + * 1. PineWarp fork VM:原生 vm.setLoadAssetsLazily(enabled) + * 2. Bilup VM(含 JIT 编译器的上游):配合 scratch-vm PR + * 「runtime.lazyAssetInstall flag」——设置标志后,sb3 解析器走 + * installWithCurrentCostume 快速路径:作品打开只等当前造型就绪, + * 其余造型/声音后台装载,到达后经 requestTargetsUpdate 刷新 GUI。 + */ const STORAGE_KEY = 'mw:skip-asset-loading'; const getSkipAssetLoading = () => { @@ -9,8 +19,20 @@ const getSkipAssetLoading = () => { }; const applySkipAssetLoading = vm => { - if (vm && typeof vm.setLoadAssetsLazily === 'function') { - vm.setLoadAssetsLazily(getSkipAssetLoading()); + if (!vm) return; + const enabled = getSkipAssetLoading(); + // 1) PineWarp fork VM 的原生 API + if (typeof vm.setLoadAssetsLazily === 'function') { + vm.setLoadAssetsLazily(enabled); + return; + } + // 2) Bilup VM:lazyAssetInstall 标志(需要配套的 scratch-vm PR) + try { + if (vm.runtime) { + vm.runtime.lazyAssetInstall = enabled; + } + } catch (err) { + // ignore } }; @@ -27,4 +49,4 @@ export { getSkipAssetLoading, applySkipAssetLoading, setSkipAssetLoading -}; \ No newline at end of file +};