Skip to content

Commit

Permalink
get clones of target
Browse files Browse the repository at this point in the history
  • Loading branch information
jwklong committed Dec 1, 2024
1 parent 0e524ab commit 343ae96
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/extensions/jwArray/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ class Extension {
"---",
{
opcode: 'get',
text: 'get [ARRAY] at [INDEX]',
text: 'get [INDEX] in [ARRAY]',
blockType: BlockType.REPORTER,
arguments: {
ARRAY: jwArray.Argument,
Expand All @@ -211,7 +211,7 @@ class Extension {
"---",
{
opcode: 'set',
text: 'set [ARRAY] at [INDEX] to [VALUE]',
text: 'set [INDEX] in [ARRAY] to [VALUE]',
arguments: {
ARRAY: jwArray.Argument,
INDEX: {
Expand Down
29 changes: 28 additions & 1 deletion src/extensions/jwTargets/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ class TargetType {
this.targetId = targetId
}

static toTarget(x) {
if (x instanceof TargetType) return x
if (typeof x == "string") return new TargetType(x)
return new TargetType("")
}

jwArrayHandler() {
return 'Target'
}
Expand All @@ -33,7 +39,7 @@ class TargetType {

toReporterContent() {
try {
let target = vm.runtime.getTargetById(this.targetId)
let target = this.target
let name = target.sprite.name
let isClone = !target.isOriginal
let costumeURI = target.getCostumes()[target.currentCostume].asset.encodeDataURI()
Expand All @@ -56,6 +62,10 @@ class TargetType {
return span("Unknown")
}
}

get target() {
return vm.runtime.getTargetById(this.targetId)
}
}

const Target = {
Expand Down Expand Up @@ -106,6 +116,15 @@ class Extension {
...Target.Block
},
'---',
{
opcode: 'clones',
text: 'clones of [TARGET]',
arguments: {
TARGET: Target.Argument
},
...jwArray.Block
},
'---',
{
blockType: BlockType.XML,
xml: `<block type="control_run_as_sprite" />`
Expand All @@ -121,6 +140,14 @@ class Extension {
stage() {
return new Target.Type(vm.runtime._stageTarget.id)
}

clones({TARGET}) {
TARGET = Target.Type.toTarget(TARGET)
if (TARGET.target) {
return jwArray.Type(TARGET.target.sprite.clones.filter(v => !v.isOriginal))
}
return jwArray.Type()
}
}

module.exports = Extension

0 comments on commit 343ae96

Please sign in to comment.