Skip to content
Open
Show file tree
Hide file tree
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
13 changes: 12 additions & 1 deletion extensions/src/common/utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { MenuItem, Primitive, RGBObject } from "./types"
import { MenuItem, Primitive, RGBObject, BlockUtilityWithID } from "./types";

type FetchParams = {
request: Parameters<typeof fetch>[0],
Expand Down Expand Up @@ -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;
}
24 changes: 22 additions & 2 deletions extensions/src/simple_example/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

Loading