File tree Expand file tree Collapse file tree 1 file changed +71
-0
lines changed Expand file tree Collapse file tree 1 file changed +71
-0
lines changed Original file line number Diff line number Diff line change 1+ // From https://github.com/TurboWarp/scratch-vm/pull/141
2+ ( function ( Scratch ) {
3+ "use strict" ;
4+
5+ class LoopsAndThings {
6+ getInfo ( ) {
7+ return {
8+ id : "loopsAndThings" ,
9+ name : "Loops and things test" ,
10+ blocks : [
11+ {
12+ opcode : "conditional" ,
13+ blockType : Scratch . BlockType . CONDITIONAL ,
14+ text : "run branch [BRANCH] of" ,
15+ arguments : {
16+ BRANCH : {
17+ type : Scratch . ArgumentType . NUMBER ,
18+ defaultValue : 1
19+ }
20+ } ,
21+ branchCount : 3
22+ } ,
23+ {
24+ opcode : "loop" ,
25+ blockType : Scratch . BlockType . LOOP ,
26+ text : "my repeat [TIMES]" ,
27+ arguments : {
28+ TIMES : {
29+ type : Scratch . ArgumentType . NUMBER ,
30+ defaultValue : 10
31+ }
32+ } ,
33+ } ,
34+ '---' ,
35+ {
36+ opcode : "testPromise" ,
37+ blockType : Scratch . BlockType . REPORTER ,
38+ text : "return [VALUE] in a Promise" ,
39+ arguments : {
40+ VALUE : {
41+ type : Scratch . ArgumentType . STRING ,
42+ defaultValue : ''
43+ }
44+ }
45+ }
46+ ]
47+ } ;
48+ }
49+
50+ conditional ( { BRANCH } , util ) {
51+ return Scratch . Cast . toNumber ( BRANCH ) ;
52+ }
53+
54+ loop ( { TIMES } , util ) {
55+ const times = Math . round ( Scratch . Cast . toNumber ( TIMES ) ) ;
56+ if ( typeof util . stackFrame . loopCounter === "undefined" ) {
57+ util . stackFrame . loopCounter = times ;
58+ }
59+ util . stackFrame . loopCounter -- ;
60+ if ( util . stackFrame . loopCounter >= 0 ) {
61+ return true ;
62+ }
63+ }
64+
65+ testPromise ( { VALUE } ) {
66+ return Promise . resolve ( VALUE ) ;
67+ }
68+ }
69+
70+ Scratch . extensions . register ( new LoopsAndThings ( ) ) ;
71+ } ) ( Scratch ) ;
You can’t perform that action at this time.
0 commit comments