Skip to content

Commit

Permalink
TheShovel/ShovelUtils: add delete costume and get all sprites (#796)
Browse files Browse the repository at this point in the history
  • Loading branch information
yuri-kiss committed Jul 30, 2023
1 parent 418e12b commit 38e4152
Showing 1 changed file with 42 additions and 2 deletions.
44 changes: 42 additions & 2 deletions extensions/TheShovel/ShovelUtils.js
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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,
Expand All @@ -162,6 +180,11 @@
}
},

{
opcode: 'getAllSprites',
blockType: Scratch.BlockType.REPORTER,
text: 'get all sprites'
},
{
opcode: 'getfps',
blockType: Scratch.BlockType.REPORTER,
Expand Down Expand Up @@ -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);

0 comments on commit 38e4152

Please sign in to comment.