forked from BlueDome77/Turbowarp-Extension-List
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Custom Reporter.js
123 lines (123 loc) · 3.39 KB
/
Custom Reporter.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
(function(Scratch) {
'use strict';
let outputVar = {};
let CRmenu = ['1', '2', '3', '4', '5']
class Broadcast2 {
getInfo() {
return {
id: 'broadcast2example',
name: 'Broadcast Example 2',
blocks: [
{
opcode: 'addCR',
blockType: Scratch.BlockType.BUTTON,
text: 'Add custom reporter',
func: 'addCR',
disableMonitor: true,
},
{
opcode: 'removeCR',
blockType: Scratch.BlockType.BUTTON,
text: 'Remove custom reporter',
func: 'removeCR',
disableMonitor: true,
},
{
opcode: 'whenReceived',
blockType: Scratch.BlockType.HAT,
text: 'when I receive [EVENT_OPTION]',
isEdgeActivated: false,
arguments: {
EVENT_OPTION: {
type: Scratch.ArgumentType.STRING,
menu: 'EVENT_FIELD'
}
}
},
{
opcode: 'broadcast',
blockType: Scratch.BlockType.REPORTER,
text: 'broadcast [EVENT] [INPUT] and wait [TIME]',
arguments: {
EVENT: {
type: Scratch.ArgumentType.STRING,
menu: 'EVENT_FIELD'
},
INPUT: {
type: Scratch.ArgumentType.STRING
},
TIME: {
type: Scratch.ArgumentType.NUMBER
}
}
},
{
opcode: 'getinput',
blockType: Scratch.BlockType.REPORTER,
text: 'get [EVENT]',
arguments: {
EVENT: {
type: Scratch.ArgumentType.STRING,
menu: 'EVENT_FIELD'
}
}
},
{
opcode: 'setinput',
blockType: Scratch.BlockType.COMMAND,
text: 'set [EVENT] to [INPUT]',
arguments: {
EVENT: {
type: Scratch.ArgumentType.STRING,
menu: 'EVENT_FIELD'
},
INPUT: {
type: Scratch.ArgumentType.STRING
}
}
},
],
menus: {
EVENT_FIELD: {
acceptReporters: false,
items: CRmenu
}
}
};
}
broadcast({ EVENT, INPUT, TIME }, util) {
const wait = (args) => {
return new Promise((resolve, reject) => {
const timeInMilliseconds = TIME * 1000;
setTimeout(() => {
resolve();
}, timeInMilliseconds);
});
};
util.startHats('broadcast2example_whenReceived', {
EVENT_OPTION: EVENT,
});
outputVar[EVENT] = INPUT;
return wait({ TIME: 5 }).then(() => {
return outputVar[EVENT];
});
}
getinput({EVENT}) {
return outputVar[EVENT];
}
setinput({EVENT, INPUT}) {
outputVar[EVENT] = INPUT
}
addCR() {
const newReporterName = prompt("Enter the name of the custom reporter");
CRmenu.push(newReporterName);
console.log(CRmenu);
}
removeCR() {
const reporterNameToRemove = prompt("Enter the name of the custom reporter");
CRmenu = CRmenu.filter(item => item !== reporterNameToRemove);
console.log(CRmenu);
}
}
Scratch.extensions.register(new Broadcast2());
}(Scratch));