From 3503fc160ddab2f86a160af31c97689e6f829ffa Mon Sep 17 00:00:00 2001 From: kokofixcomputers Date: Thu, 24 Aug 2023 09:40:09 -0700 Subject: [PATCH 1/5] Update README.md --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 71b7f73a139..8f58d2425da 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,6 @@ scratch-gui modified for use in [TurboWarp](https://turbowarp.org/) then modified for use in [PenguinMod](https://penguinmod.github.io/penguinmod.github.io/) 😀 + + [![Open in Gitpod](https://gitpod.io/button/open-in-gitpod.svg)](https://gitpod.io/#https://github.com/PenguinMod/penguinmod.github.io/) ## Setup From 21364958c7f35850b75934e016ddba1ea8103d79 Mon Sep 17 00:00:00 2001 From: kokofixcomputers Date: Thu, 24 Aug 2023 10:09:21 -0700 Subject: [PATCH 2/5] Add 60fps --- src/addons/addons/60fps/userscript.js | 82 +++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 src/addons/addons/60fps/userscript.js diff --git a/src/addons/addons/60fps/userscript.js b/src/addons/addons/60fps/userscript.js new file mode 100644 index 00000000000..92fb791c864 --- /dev/null +++ b/src/addons/addons/60fps/userscript.js @@ -0,0 +1,82 @@ +export default async function ({ addon, console }) { + // TODO: test whether e.altKey is true in chromebooks when alt+clicking. + // If so, no timeout needed, similar to mute-project addon. + + let global_fps = 30; + const vm = addon.tab.traps.vm; + let mode = false; + let monitorUpdateFixed = false; + + const fastFlag = addon.self.dir + "/svg/fast-flag.svg"; + let vanillaFlag = null; + + while (true) { + let button = await addon.tab.waitForElement("[class^='green-flag_green-flag']", { + markAsSeen: true, + reduxEvents: ["scratch-gui/mode/SET_PLAYER", "fontsLoaded/SET_FONTS_LOADED", "scratch-gui/locales/SELECT_LOCALE"], + }); + + const updateFlag = () => { + if (!vanillaFlag) vanillaFlag = button.src; + button.src = mode ? fastFlag : vanillaFlag; + }; + + const changeMode = (_mode = !mode) => { + mode = _mode; + if (mode) { + setFPS(addon.settings.get("framerate")); + + // monitor updates are throttled by default + // https://github.com/scratchfoundation/scratch-gui/blob/ba76db7/src/reducers/monitors.js + if (!monitorUpdateFixed) { + const originalListener = vm.listeners("MONITORS_UPDATE").find((f) => f.name === "onMonitorsUpdate"); + if (originalListener) vm.removeListener("MONITORS_UPDATE", originalListener); + vm.on("MONITORS_UPDATE", (monitors) => + addon.tab.redux.dispatch({ + type: "scratch-gui/monitors/UPDATE_MONITORS", + monitors, + }) + ); + monitorUpdateFixed = true; + } + } else setFPS(30); + updateFlag(); + }; + const flagListener = (e) => { + if (addon.self.disabled) return; + const isAltClick = e.type === "click" && e.altKey; + const isChromebookAltClick = navigator.userAgent.includes("CrOS") && e.type === "contextmenu"; + if (isAltClick || isChromebookAltClick) { + e.cancelBubble = true; + e.preventDefault(); + changeMode(); + } + }; + button.addEventListener("click", flagListener); + button.addEventListener("contextmenu", flagListener); + + const setFPS = (fps) => { + global_fps = addon.self.disabled ? 30 : fps; + + clearInterval(vm.runtime._steppingInterval); + vm.runtime._steppingInterval = null; + vm.runtime.start(); + }; + addon.settings.addEventListener("change", () => { + if (vm.runtime._steppingInterval) { + setFPS(addon.settings.get("framerate")); + } + }); + addon.self.addEventListener("disabled", () => changeMode(false)); + vm.runtime.start = function () { + if (this._steppingInterval) return; + let interval = 1000 / global_fps; + this.currentStepTime = interval; + this._steppingInterval = setInterval(() => { + this._step(); + }, interval); + this.emit("RUNTIME_STARTED"); + }; + updateFlag(); + } +} From ce499d24d31d78e25d5b48166bc196c81a3d7eaa Mon Sep 17 00:00:00 2001 From: kokofixcomputers Date: Thu, 24 Aug 2023 10:10:35 -0700 Subject: [PATCH 3/5] Create addon.json --- src/addons/addons/60fps/addon.json | 46 ++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 src/addons/addons/60fps/addon.json diff --git a/src/addons/addons/60fps/addon.json b/src/addons/addons/60fps/addon.json new file mode 100644 index 00000000000..15c190fd803 --- /dev/null +++ b/src/addons/addons/60fps/addon.json @@ -0,0 +1,46 @@ +{ + "name": "60FPS project player mode", + "description": "Alt+Click the green flag to toggle 60FPS.", + "info": [ + { + "type": "notice", + "text": "Most projects will not behave properly when running at 60FPS, because increasing the frame rate also increases the speed at which scripts run. This should only be used on projects that support 60FPS.", + "id": "projectRunsFasterNotice" + } + ], + "credits": [ + { + "name": "Jeffalo", + "link": "https://scratch.mit.edu/users/Jeffalo/" + }, + { + "name": "TheColaber", + "link": "https://scratch.mit.edu/users/TheColaber/" + } + { + "name": "kokofixcomputers", + "link": "https://scratch.mit.edu/users/kokofixcomputers/" + } + ], + "dynamicEnable": true, + "dynamicDisable": true, + "userscripts": [ + { + "url": "userscript.js", + "matches": ["projects", "projectEmbeds"] + } + ], + "settings": [ + { + "name": "Alt+GreenFlag FPS", + "id": "framerate", + "type": "integer", + "min": 31, + "max": 240, + "default": 60 + } + ], + "tags": ["editor", "projectPlayer", "featured"], + "versionAdded": "1.1.0", + "enabledByDefault": false +} From b03f24d8dbfe6ee9a2aa207e2bcfd016f8ca16bf Mon Sep 17 00:00:00 2001 From: kokofixcomputers Date: Thu, 24 Aug 2023 10:12:32 -0700 Subject: [PATCH 4/5] Add files via upload --- src/addons/addons/60fps/svg/fast-flag.svg | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 src/addons/addons/60fps/svg/fast-flag.svg diff --git a/src/addons/addons/60fps/svg/fast-flag.svg b/src/addons/addons/60fps/svg/fast-flag.svg new file mode 100644 index 00000000000..de1d8cd8be8 --- /dev/null +++ b/src/addons/addons/60fps/svg/fast-flag.svg @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + From b8cd0bae1b511afbfca4069e968c84c78d7ac30c Mon Sep 17 00:00:00 2001 From: kokofixcomputers Date: Thu, 24 Aug 2023 10:15:06 -0700 Subject: [PATCH 5/5] Update addons.js --- src/addons/addons.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/addons/addons.js b/src/addons/addons.js index d2e8f55c047..9ec7764a636 100644 --- a/src/addons/addons.js +++ b/src/addons/addons.js @@ -75,6 +75,7 @@ const addons = [ const newAddons = [ 'vol-slider', + '60fps', 'number-pad', 'rename-broadcasts', 'sprite-properties',