Skip to content

Lily/MoreEvents: added "whenProjectPaused" and "whenProjectUnPause" #2040

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 59 additions & 0 deletions extensions/Lily/MoreEvents.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// ID: lmsMoreEvents
// Description: Start your scripts in new ways.
// By: LilyMakesThings <https://scratch.mit.edu/users/LilyMakesThings/>
// By: Fath11 <https://scratch.mit.edu/users/fath11/>
// License: MIT AND LGPL-3.0

(function (Scratch) {
Expand All @@ -13,6 +14,12 @@
const stopIcon =
"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADIAAAAyCAMAAAAp4XiDAAAAQlBMVEUAAAC/UFC8Q0OzTU24SEi4SEi3SEi4R0e4SEi4SEi4SEi4SEi7SUm8SUnMTk7MT0/OT0/PT0/gVVXiVVXsWVn///+CoOd2AAAAC3RSTlMAEBMUu7zLz9D8/dIXnJwAAAABYktHRBXl2PmjAAAAxklEQVRIx+3WwRKDIBAD0JWqVEOtWv7/W3twOqKwELzW3N9wYhORMMYiztgZUZMUAKxqmh5Kno/MG256nzI59Z2mB+BWH+XzUt5RhWoyQjFZkTQFkTBFERlCnAwlDoYUgaHFblpaeL86AK0MvNjMIABmT2cGIAAWniw3ucm/k9ovduEjXzgXtUfJmtrTt9VZzYH9FSB/xvfKZMsiLFmuko61zBTfucjL9RpXf6nEU2MhPxXS86J+kORmjz6V6seViOnG8oT7ApMcjsYZwhXCAAAAAElFTkSuQmCC";

const pauseIcon =
"data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIGhlaWdodD0iMTgiIHdpZHRoPSIxOCI+PHBhdGggZD0iTTIzMS40MjkgMTg4LjkyOVYxNzEuMDdoNC4yODV2MTcuODU4em0xMi4xNDIgMFYxNzEuMDdoNC4yODZ2MTcuODU4eiIgdHJhbnNmb3JtPSJtYXRyaXgoMS4wMzMwOSAwIDAgLjk1NDI3IC0yMzguNTczIC0xNjIuNzY5KSIgZGF0YS1wYXBlci1kYXRhPSJ7JnF1b3Q7aXNQYWludGluZ0xheWVyJnF1b3Q7OnRydWV9IiBmaWxsPSIjZmZhZTAwIiBzdHJva2U9IiNkODk0MDAiIHN0cm9rZS1taXRlcmxpbWl0PSIxMCIgc3R5bGU9Im1peC1ibGVuZC1tb2RlOm5vcm1hbCIvPjwvc3ZnPg==";

const continueIcon =
"data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIGhlaWdodD0iMTgiIHdpZHRoPSIxOCI+PHBhdGggZD0ibTI0Ni4wNTUgMTgwLTEyLjExIDEyLjExdi0yNC4yMnoiIHRyYW5zZm9ybT0ibWF0cml4KDEuMTM5NDkgMCAwIC42Nzk0MyAtMjY0LjU5NSAtMTEzLjI5OCkiIHN0cm9rZS1taXRlcmxpbWl0PSIxMCIgc3Ryb2tlPSIjZDg5NDAwIiBmaWxsPSIjZmZhZTAwIiBkYXRhLXBhcGVyLWRhdGE9InsmcXVvdDtpc1BhaW50aW5nTGF5ZXImcXVvdDs6dHJ1ZX0iLz48L3N2Zz4=";

// Source:
// https://github.com/TurboWarp/scratch-vm/blob/develop/src/io/keyboard.js
// https://github.com/TurboWarp/scratch-blocks/blob/develop/blocks_vertical/event.js
Expand Down Expand Up @@ -205,6 +212,32 @@
runtime.shouldExecuteStopClicked = false;
originalGreenFlag.call(this);
};

let pauseHandler = () => {
runtime.allScriptsByOpcodeDo(
"lmsMoreEvents_whenProjectPaused",
(script, target) => {
const topBlockId = script.blockId;
for (let j = 0; j < runtime.threads.length; j++) {
if (
runtime.threads[j].topBlock === topBlockId &&
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This does not account for clones properly. The script is only going to run in one of the clones at a time since theyll have the same top block ID

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i am not quite sure how to fix this..

runtime.threads[j].status !== 4
) {
return;
}
}
runtime._pushThread(topBlockId, target);
}
);
};

runtime.on("RUNTIME_PAUSED", () => {
runtime.once("BEFORE_EXECUTE", pauseHandler);
});

runtime.on("RUNTIME_UNPAUSED", () => {
runtime.once("BEFORE_EXECUTE", () => { runtime.startHats("lmsMoreEvents_whenProjectUnPaused") });
});
}

getInfo() {
Expand All @@ -228,6 +261,32 @@
},
extensions: ["colours_event"],
},
{
opcode: "whenProjectPaused",
blockType: Scratch.BlockType.EVENT,
text: Scratch.translate("when [PAUSE] clicked"),
isEdgeActivated: false,
arguments: {
PAUSE: {
type: Scratch.ArgumentType.IMAGE,
dataURI: pauseIcon,
},
},
extensions: ["colours_event"],
},
{
opcode: "whenProjectUnPaused",
blockType: Scratch.BlockType.EVENT,
text: Scratch.translate("when [UNPAUSE] clicked"),
isEdgeActivated: false,
arguments: {
UNPAUSE: {
type: Scratch.ArgumentType.IMAGE,
dataURI: continueIcon,
},
},
extensions: ["colours_event"],
},
{
opcode: "forever",
blockType: Scratch.BlockType.EVENT,
Expand Down
Loading