-
Notifications
You must be signed in to change notification settings - Fork 238
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a6fddd8
commit 615d78d
Showing
7 changed files
with
250 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
extensions/docs-examples/unsandboxed/when-key-pressed-restart.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
(function(Scratch) { | ||
'use strict'; | ||
|
||
if (!Scratch.extensions.unsandboxed) { | ||
throw new Error('This example must run unsandboxed'); | ||
} | ||
|
||
class WhenKeyPressed { | ||
getInfo() { | ||
return { | ||
id: 'restartexampleunsandboxed', | ||
name: 'Restart Threads Example', | ||
blocks: [ | ||
{ | ||
blockType: Scratch.BlockType.EVENT, | ||
opcode: 'whenPressed', | ||
text: 'when [KEY] key pressed', | ||
isEdgeActivated: false, | ||
// highlight-next-line | ||
shouldRestartExistingThreads: true, | ||
arguments: { | ||
KEY: { | ||
type: Scratch.ArgumentType.STRING, | ||
menu: 'key' | ||
} | ||
} | ||
} | ||
], | ||
menus: { | ||
key: { | ||
acceptReporters: false, | ||
items: [ | ||
{ | ||
text: 'space', | ||
value: ' ' | ||
}, | ||
'a', | ||
'b', | ||
'c', | ||
// ... | ||
] | ||
} | ||
} | ||
}; | ||
} | ||
} | ||
|
||
document.addEventListener('keydown', (e) => { | ||
Scratch.vm.runtime.startHats('restartexampleunsandboxed_whenPressed', { | ||
KEY: e.key | ||
}); | ||
}); | ||
|
||
Scratch.extensions.register(new WhenKeyPressed()); | ||
})(Scratch); |
54 changes: 54 additions & 0 deletions
54
extensions/docs-examples/unsandboxed/when-key-pressed-stage.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
(function(Scratch) { | ||
'use strict'; | ||
|
||
if (!Scratch.extensions.unsandboxed) { | ||
throw new Error('This example must run unsandboxed'); | ||
} | ||
|
||
class WhenKeyPressedInStage { | ||
getInfo() { | ||
return { | ||
id: 'eventexample3unsandboxed', | ||
name: 'Event Block Example 3', | ||
blocks: [ | ||
{ | ||
blockType: Scratch.BlockType.EVENT, | ||
opcode: 'whenPressed', | ||
text: 'when [KEY] key pressed', | ||
isEdgeActivated: false, | ||
arguments: { | ||
KEY: { | ||
type: Scratch.ArgumentType.STRING, | ||
menu: 'key' | ||
} | ||
} | ||
} | ||
], | ||
menus: { | ||
key: { | ||
acceptReporters: false, | ||
items: [ | ||
{ | ||
text: 'space', | ||
value: ' ' | ||
}, | ||
'a', | ||
'b', | ||
'c', | ||
// ... | ||
] | ||
} | ||
} | ||
}; | ||
} | ||
} | ||
|
||
document.addEventListener('keydown', (e) => { | ||
Scratch.vm.runtime.startHats('eventexample3unsandboxed_whenPressed', { | ||
KEY: e.key | ||
// highlight-next-line | ||
}, Scratch.vm.runtime.getTargetForStage()); | ||
}); | ||
|
||
Scratch.extensions.register(new WhenKeyPressedInStage()); | ||
})(Scratch); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
(function(Scratch) { | ||
'use strict'; | ||
|
||
if (!Scratch.extensions.unsandboxed) { | ||
throw new Error('This example must run unsandboxed'); | ||
} | ||
|
||
class WhenKeyPressed { | ||
getInfo() { | ||
return { | ||
id: 'eventexample2unsandboxed', | ||
name: 'Event Block Example 2', | ||
blocks: [ | ||
{ | ||
blockType: Scratch.BlockType.EVENT, | ||
opcode: 'whenPressed', | ||
text: 'when [KEY] key pressed', | ||
isEdgeActivated: false, // required boilerplate | ||
// highlight-start | ||
arguments: { | ||
KEY: { | ||
type: Scratch.ArgumentType.STRING, | ||
menu: 'key' | ||
} | ||
} | ||
// highlight-end | ||
} | ||
], | ||
menus: { | ||
key: { | ||
acceptReporters: false, | ||
items: [ | ||
{ | ||
// startHats filters by *value*, not by text | ||
text: 'space', | ||
value: ' ' | ||
}, | ||
'a', | ||
'b', | ||
'c', | ||
// ... | ||
] | ||
} | ||
} | ||
}; | ||
} | ||
} | ||
|
||
document.addEventListener('keydown', (e) => { | ||
// highlight-start | ||
Scratch.vm.runtime.startHats('eventexample2unsandboxed_whenPressed', { | ||
KEY: e.key | ||
}); | ||
// highlight-end | ||
}); | ||
|
||
Scratch.extensions.register(new WhenKeyPressed()); | ||
})(Scratch); |
37 changes: 37 additions & 0 deletions
37
extensions/docs-examples/unsandboxed/when-space-key-pressed.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
(function(Scratch) { | ||
'use strict'; | ||
|
||
if (!Scratch.extensions.unsandboxed) { | ||
throw new Error('This example must run unsandboxed'); | ||
} | ||
|
||
class WhenSpaceKeyPressed { | ||
getInfo() { | ||
return { | ||
id: 'eventexampleunsandboxed', | ||
name: 'Event Block Example', | ||
blocks: [ | ||
// highlight-start | ||
{ | ||
blockType: Scratch.BlockType.EVENT, | ||
opcode: 'whenSpacePressed', | ||
text: 'when space key pressed', | ||
isEdgeActivated: false // required boilerplate | ||
} | ||
// highlight-end | ||
] | ||
}; | ||
} | ||
// Notice: whenSpacePressed does not have a function defined! | ||
} | ||
|
||
// highlight-start | ||
document.addEventListener('keydown', (e) => { | ||
if (e.key === ' ') { | ||
Scratch.vm.runtime.startHats('eventexampleunsandboxed_whenSpacePressed'); | ||
} | ||
}); | ||
// highlight-end | ||
|
||
Scratch.extensions.register(new WhenSpaceKeyPressed()); | ||
})(Scratch); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
(function(Scratch) { | ||
'use strict'; | ||
|
||
if (!Scratch.extensions.unsandboxed) { | ||
throw new Error('This example must run unsandboxed'); | ||
} | ||
|
||
class When { | ||
getInfo() { | ||
return { | ||
id: 'whenunsandboxed', | ||
name: 'When', | ||
blocks: [ | ||
{ | ||
// highlight-start | ||
blockType: Scratch.BlockType.HAT, | ||
opcode: 'when', | ||
text: 'when [CONDITION]', | ||
isEdgeActivated: false, // required boilerplate | ||
arguments: { | ||
CONDITION: { | ||
type: Scratch.BlockType.BOOLEAN | ||
} | ||
} | ||
// highlight-end | ||
} | ||
] | ||
}; | ||
} | ||
// highlight-start | ||
when(args) { | ||
return Scratch.Cast.toBoolean(args.CONDITION); | ||
} | ||
// highlight-end | ||
} | ||
|
||
// highlight-start | ||
Scratch.vm.runtime.on('BEFORE_EXECUTE', () => { | ||
// startHats is the same as before! | ||
Scratch.vm.runtime.startHats('whenunsandboxed_when'); | ||
}); | ||
// highlight-end | ||
|
||
Scratch.extensions.register(new When()); | ||
})(Scratch); |