From 7563776d7e874fee433019c049c2968e302060e9 Mon Sep 17 00:00:00 2001 From: Surv <135030944+SurvExe1Pc@users.noreply.github.com> Date: Fri, 28 Jul 2023 15:57:35 -0400 Subject: [PATCH 1/3] ShovelUtils Update. Added a "get all sprites" reporter, and a "delete image named [name] in sprite [sprite]" block Other changes. Changed the version number to v1.4, Added a unsandboxed error. --- extensions/TheShovel/ShovelUtils.js | 44 +++++++++++++++++++++++++++-- 1 file changed, 42 insertions(+), 2 deletions(-) diff --git a/extensions/TheShovel/ShovelUtils.js b/extensions/TheShovel/ShovelUtils.js index bbbba655e0..c09516cf80 100644 --- a/extensions/TheShovel/ShovelUtils.js +++ b/extensions/TheShovel/ShovelUtils.js @@ -1,6 +1,9 @@ (function (Scratch) { 'use strict'; - console.log("ShovelUtils v1.3"); + if (!Scratch.extensions.unsandboxed) { + throw new Error('ShovelUtils must be run unsandboxed'); + } + console.log("ShovelUtils v1.4"); const vm = Scratch.vm; // Based on from https://www.growingwiththeweb.com/2017/12/fast-simple-js-fps-counter.html @@ -138,6 +141,21 @@ } } }, + { + opcode: 'deleteImage', + blockType: Scratch.BlockType.COMMAND, + text: 'Delete costume [COSNAME] in [SPRITE]', + arguments: { + COSNAME: { + type: Scratch.ArgumentType.STRING, + defaultValue: 'costume1' + }, + SPRITE: { + type: Scratch.ArgumentType.STRING, + defaultValue: 'Sprite1' + } + } + }, { opcode: 'setedtarget', blockType: Scratch.BlockType.COMMAND, @@ -162,6 +180,11 @@ } }, + { + opcode: 'getAllSprites', + blockType: Scratch.BlockType.REPORTER, + text: 'get all sprites' + }, { opcode: 'getfps', blockType: Scratch.BlockType.REPORTER, @@ -328,8 +351,25 @@ getfps(){ return fps; } - } + deleteImage({ SPRITE, COSNAME }){ + //0znzw, since shovel did not add it yet. + const target = vm.runtime.getSpriteTargetByName(SPRITE); + if (!target) { + return; + } + target.deleteCostume(target.getCostumeIndexByName(COSNAME)); + } + + getAllSprites(){ + //0znzw, since shovel did not add it yet. + let sprites = new Object([]), target = ""; + for (target in vm.runtime.targets) { + sprites.push(vm.runtime.targets[target].sprite.name); + } + return JSON.stringify(sprites); + } + } Scratch.extensions.register(new ShovelUtils()); // @ts-ignore })(Scratch); From bd8c452f16da5e8f6bb9ad7494c1e77dbf5e35b0 Mon Sep 17 00:00:00 2001 From: Surv <135030944+SurvExe1Pc@users.noreply.github.com> Date: Sat, 29 Jul 2023 04:07:29 -0400 Subject: [PATCH 2/3] added isOriginal check prevents also listing clones --- extensions/TheShovel/ShovelUtils.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/extensions/TheShovel/ShovelUtils.js b/extensions/TheShovel/ShovelUtils.js index c09516cf80..5bc6b3abe2 100644 --- a/extensions/TheShovel/ShovelUtils.js +++ b/extensions/TheShovel/ShovelUtils.js @@ -365,7 +365,8 @@ //0znzw, since shovel did not add it yet. let sprites = new Object([]), target = ""; for (target in vm.runtime.targets) { - sprites.push(vm.runtime.targets[target].sprite.name); + target = vm.runtime.targets[target]; + if (target.isOriginal) sprites.push(target.sprite.name); } return JSON.stringify(sprites); } From 0b6f0077eb400e377c9dd976fd80d5ad364aeae0 Mon Sep 17 00:00:00 2001 From: Muffin Date: Sun, 30 Jul 2023 00:30:00 -0500 Subject: [PATCH 3/3] simplify --- extensions/TheShovel/ShovelUtils.js | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/extensions/TheShovel/ShovelUtils.js b/extensions/TheShovel/ShovelUtils.js index 5bc6b3abe2..8533cfdb22 100644 --- a/extensions/TheShovel/ShovelUtils.js +++ b/extensions/TheShovel/ShovelUtils.js @@ -353,7 +353,7 @@ } deleteImage({ SPRITE, COSNAME }){ - //0znzw, since shovel did not add it yet. + // 0znzw, since shovel did not add it yet. const target = vm.runtime.getSpriteTargetByName(SPRITE); if (!target) { return; @@ -362,10 +362,9 @@ } getAllSprites(){ - //0znzw, since shovel did not add it yet. - let sprites = new Object([]), target = ""; - for (target in vm.runtime.targets) { - target = vm.runtime.targets[target]; + // 0znzw, since shovel did not add it yet. + let sprites = []; + for (const target of vm.runtime.targets) { if (target.isOriginal) sprites.push(target.sprite.name); } return JSON.stringify(sprites);