From 38e41529c31a467e6d5395000ce0bf922812663f Mon Sep 17 00:00:00 2001 From: Surv <135030944+SurvExe1Pc@users.noreply.github.com> Date: Sun, 30 Jul 2023 01:31:18 -0400 Subject: [PATCH] TheShovel/ShovelUtils: add delete costume and get all sprites (#796) --- 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..8533cfdb22 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 = []; + for (const target of vm.runtime.targets) { + if (target.isOriginal) sprites.push(target.sprite.name); + } + return JSON.stringify(sprites); + } + } Scratch.extensions.register(new ShovelUtils()); // @ts-ignore })(Scratch);