diff --git a/hacky-file-getter.js b/hacky-file-getter.js index f508f23..926c99a 100644 --- a/hacky-file-getter.js +++ b/hacky-file-getter.js @@ -104,6 +104,7 @@ function downloadAsHTML(projectSrc, { log = console.log, monitorColour = null, cloudServer = false, + specialCloud = false, projectId = null, noVM = false, width = 480, @@ -230,8 +231,14 @@ function downloadAsHTML(projectSrc, { if (stretch) template = removePercentSection(template, 'fit'); else template = removePercentSection(template, 'stretch'); if (!noCursor) template = removePercentSection(template, 'no-cursor'); + if (!specialCloud) { + template = removePercentSection(template, 'special-cloud'); + } if (cloudServer) { - template = removePercentSection(template, 'cloud-localstorage') + if (!specialCloud) { + template = removePercentSection(template, 'cloud-localstorage'); + } + template = removePercentSection(template, 'cloud-localstorage-provider') .replace(/\{CLOUD_HOST\}/g, () => JSON.stringify(cloudServer)); } else { template = removePercentSection(template, 'cloud-ws'); diff --git a/index.html b/index.html index b37ae1c..2199e42 100644 --- a/index.html +++ b/index.html @@ -78,6 +78,7 @@

Convert a Scratch project to HTML

Cloud variable source

1

+

4

E羊icques (modded) options @@ -94,6 +95,7 @@

Convert a Scratch project to HTML

1You may have to deal with privacy laws around cookies outside of Scratch.

2Compatibility mode forces projects to run at 30 FPS, like in Scratch 2.0. Turning this off allows the project to run at a higher framerate (usually 60 FPS, depending on the computer screen's refresh rate).

3I think the implementation of this is poor. Maybe instead of setting mouse x/y, it can set a cloud variable with a certain name. You can leave feedback and suggestions on my profile.

+

4If a cloud variable with the name "☁ eval" is set, it'll run the variable value as JavaScript and store it in a cloud variable named "☁ eval output"; if there is an error, it'll be stored in "☁ eval error." If you're using a custom cloud server, then cloud variables whose names start with "☁ local storage" will store their values in localStorage instead of in the server.

Update history

See the code and previous versions on Github.

2020-05-01

@@ -188,6 +190,7 @@

2019-02-09

const pointerLock = document.getElementById('pointer-lock'); const stretch = document.getElementById('stretch'); const noCursor = document.getElementById('no-cursor'); +const specialCloud = document.getElementById('special-cloud'); let scroll = false function log(text, style) { const entry = document.createElement('div') @@ -226,7 +229,8 @@

2019-02-09

noLimits: noLimits.checked, pointerLock: pointerLock.checked, stretch: stretch.checked, - noCursor: noCursor.checked + noCursor: noCursor.checked, + specialCloud: specialCloud.checked }) .then(html => { log('Attempting to download HTML file...', 'status') diff --git a/template.html b/template.html index 4f0fc92..01d5809 100644 --- a/template.html +++ b/template.html @@ -450,6 +450,8 @@ const Scratch = window.Scratch = window.Scratch || {}; +const CLOUD_PREFIX = '\u2601 '; + const runBenchmark = async function () { const vm = new window.NotVirtualMachine(% custom-ratio % WIDTH, HEIGHT % /custom-ratio %); Scratch.vm = vm; @@ -497,25 +499,6 @@ vm.setVideoProvider(videoProvider); const noop = () => null; - let cloudProvider; - - % cloud-localstorage % - cloudProvider = { - updateVariable(name, value) { - try { - localStorage.setItem('[s3] ' + name, value); - } catch (e) { - console.error('Cannot use localStorage?', e); - } - }, - createVariable: noop, - renameVariable: noop, - deleteVariable: noop, - requestCloseConnection: noop - }; - % /cloud-localstorage % - - % cloud-ws % let ws; function openConnection() { try { @@ -528,7 +511,6 @@ ws.onopen = onOpen; ws.onclose = onClose; } - openConnection(); function onMessage(e) { e.data.split('\n').forEach(message => { if (message) { @@ -550,21 +532,61 @@ function onClose() { setTimeout(openConnection, 500); } - cloudProvider = { + const cloudProvider = { updateVariable(name, value) { - sendData({method: 'set', name, value}); + % special-cloud % + if (name === CLOUD_PREFIX + 'eval') { + try { + vm.postIOData('cloud', { + varUpdate: { + name: CLOUD_PREFIX + 'eval output', + value: eval(value) + } + }); + } catch (err) { + vm.postIOData('cloud', { + varUpdate: { + name: CLOUD_PREFIX + 'eval error', + value: err.toString() + } + }); + } + } else % cloud-ws % if (name.startsWith(CLOUD_PREFIX + 'local storage')) % /cloud-ws % { + % /special-cloud % + % cloud-localstorage % + try { + localStorage.setItem('[s3] ' + name, value); + } catch (e) { + console.error('Cannot use localStorage?', e); + } + % /cloud-localstorage % + % special-cloud % + % cloud-ws % + } else { + % /cloud-ws % + % /special-cloud % + % cloud-ws % + sendData({method: 'set', name, value}); + % /cloud-ws % + % special-cloud % + } + % /special-cloud % }, createVariable: noop, renameVariable: noop, deleteVariable: noop, + % cloud-ws % requestCloseConnection() { if (ws && ws.readyState !== WebSocket.CLOSING && ws.readyState !== WebSocket.CLOSED) { ws.onclose = noop; ws.close(); } } + % /cloud-ws % + % cloud-localstorage-provider % + requestCloseConnection: noop + % /cloud-localstorage-provider % }; - % /cloud-ws % vm.setCompatibilityMode(COMPAT); vm.setTurboMode(TURBO); @@ -910,11 +932,16 @@ } % /loading-image % - if (cloudProvider) vm.setCloudProvider(cloudProvider); + vm.setCloudProvider(cloudProvider); % cloud-localstorage % const stageVariables = vm.runtime.getTargetForStage().variables; for (const { name, isCloud } of Object.values(stageVariables)) { if (isCloud) { + % special-cloud % + % cloud-ws % + if (!name.startsWith(CLOUD_PREFIX + 'local storage')) continue; + % /cloud-ws % + % /special-cloud % const value = localStorage.getItem('[s3] ' + name); if (value === null) continue; vm.postIOData('cloud', { varUpdate: { name, value } }); @@ -922,15 +949,24 @@ } window.addEventListener('storage', e => { if (e.storageArea === localStorage && e.key.slice(0, 5) === '[s3] ') { + const name = e.key.slice(5); + % special-cloud % + % cloud-ws % + if (!name.startsWith(`[s3] ${CLOUD_PREFIX}local storage`)) return; + % /cloud-ws % + % /special-cloud % vm.postIOData('cloud', { varUpdate: { - name: e.key.slice(5), + name, value: e.newValue } }); } }); % /cloud-localstorage % + % cloud-ws % + openConnection(); + % /cloud-ws % vm.greenFlag(); };