diff --git a/extensions/src/common/utils.ts b/extensions/src/common/utils.ts index 61ac1f9f3..45728c662 100644 --- a/extensions/src/common/utils.ts +++ b/extensions/src/common/utils.ts @@ -1,4 +1,4 @@ -import { MenuItem, Primitive, RGBObject } from "./types" +import { MenuItem, Primitive, RGBObject, BlockUtilityWithID } from "./types"; type FetchParams = { request: Parameters[0], @@ -303,3 +303,14 @@ export const uuidv4 = () => 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx' v = c == 'x' ? r : (r & 0x3 | 0x8); return v.toString(16); }); + +export const checkContext = (blockInstance: BlockUtilityWithID, target: string) => { + const topBlock = blockInstance.thread.topBlock; + const blocks = blockInstance.thread.blockContainer._blocks; + const topOpcode = blocks[topBlock].opcode; + const methodName = topOpcode.split("_")[1]; + if (methodName == target) { + return true; + } + return false; +} diff --git a/extensions/src/simple_example/index.ts b/extensions/src/simple_example/index.ts index 932207f4b..491335c87 100644 --- a/extensions/src/simple_example/index.ts +++ b/extensions/src/simple_example/index.ts @@ -85,10 +85,30 @@ export default class SimpleTypescript extends extension(details, "ui", "customSa imageBlock(jibo: "inline image") { } + @(scratch.command`Test hat 2`) + testing() { + this.value = 5; + } + @(scratch.reporter`${{ type: "number", defaultValue: 1 }} + ${{ type: "image", uri: five, alt: "golden five" }} - ${"number"}`) - addFive(lhs: number, five: "inline image", rhs: number, { blockID }: BlockUtilityWithID) { - console.log(blockID); + addFive(lhs: number, five: "inline image", rhs: number, blockInstance: BlockUtilityWithID) { + console.log(blockInstance); + console.log(blockInstance.blockID); + setTimeout(() => { + console.log(blockInstance.blockID); + }, 500) + // topBlock return lhs + 5 - rhs; } + + @(scratch.hat`Test hat`) + testHat() { + return this.value == 5; + } + + @(scratch.event`Test`) + testEvent() { + return this.value == 5; + } } diff --git a/scratch-packages/scratch-gui b/scratch-packages/scratch-gui index 91c188acf..638e31019 160000 --- a/scratch-packages/scratch-gui +++ b/scratch-packages/scratch-gui @@ -1 +1 @@ -Subproject commit 91c188acf6f2f1a9e267c8a5a61e196fb18bcc39 +Subproject commit 638e31019590c369b51badc2b0a8c07dfe52782b diff --git a/scratch-packages/scratch-vm b/scratch-packages/scratch-vm index 8aca21fd7..b7786b45e 160000 --- a/scratch-packages/scratch-vm +++ b/scratch-packages/scratch-vm @@ -1 +1 @@ -Subproject commit 8aca21fd7b82334d39c804f89d02096121242551 +Subproject commit b7786b45eb42735aeef024d496e40903457b7486