forked from NetsBlox/Snap--Build-Your-Own-Blocks
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathobjects-ext.js
More file actions
269 lines (223 loc) · 7.72 KB
/
objects-ext.js
File metadata and controls
269 lines (223 loc) · 7.72 KB
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
/* global SpriteMorph, StageMorph, Color, MorphicPreferences, Morph,
Point, ScrollFrameMorph, MenuMorph, SyntaxElementMorph, IDE_Morph,
localize, BlockEditorMorph, BlockDialogMorph, TextMorph, PushButtonMorph,
MessageFrame, BlockMorph, ToggleMorph, MessageCreatorMorph,
VariableDialogMorph, SnapCloud, contains, List, CommandBlockMorph,
MessageType, isNil, RingMorph, SnapActions, RoomEditorMorph, NetsBloxMorph,
SnapUndo, newCanvas, ReplayControls, WatcherMorph */
// Add network, custom categories
SpriteMorph.prototype.categories.splice(8, 0, 'network');
SpriteMorph.prototype.categories.splice(9, 0, 'custom');
SpriteMorph.prototype.blockColor.network = new Color(217, 77, 17);
SpriteMorph.prototype.blockColor.custom = new Color(120, 120, 120);
// Additional block definitions
// RPC's
SpriteMorph.prototype._initBlocks = SpriteMorph.prototype.initBlocks;
SpriteMorph.prototype.initBlocks = function () {
SpriteMorph.prototype._initBlocks(); // super
SpriteMorph.prototype.blocks.getJSFromRPC = { // primitive JSON response
type: 'reporter',
category: 'network',
spec: 'call %s with %s',
defaults: ['PublicRoles'],
deprecated: true // deprecated blocks are not shown when searching for blocks
};
SpriteMorph.prototype.blocks.getJSFromRPCDropdown = { // primitive JSON response
type: 'reporter',
category: 'network',
spec: 'call %rpcNames / %rpcActions with %s',
defaults: ['PublicRoles'],
deprecated: true
};
SpriteMorph.prototype.blocks.getJSFromRPCStruct = {
type: 'reporter',
category: 'network',
spec: 'call %rpcNames / %rpcMethod',
defaults: ['PublicRoles']
};
SpriteMorph.prototype.blocks.doRunRPC = {
type: 'command',
category: 'network',
spec: 'run %rpcNames / %rpcMethod',
defaults: ['PublicRoles']
};
SpriteMorph.prototype.blocks.getCostumeFromRPC = {
type: 'reporter',
category: 'network',
spec: 'costume from %rpcNames / %rpcActions with %s',
defaults: ['PublicRoles', ''],
deprecated: true
};
SpriteMorph.prototype.blocks.reportRPCError = {
type: 'reporter',
category: 'network',
spec: 'error'
};
// Network Messages
// request reply
SpriteMorph.prototype.blocks.doSocketRequest = {
type: 'reporter',
category: 'network',
spec: 'send msg %msgInput to %roles and wait'
};
SpriteMorph.prototype.blocks.doSocketResponse = {
type: 'command',
category: 'network',
spec: 'send response %s'
};
SpriteMorph.prototype.blocks.doSocketMessage = {
type: 'command',
category: 'network',
spec: 'send msg %msgInput to %roles'
};
SpriteMorph.prototype.blocks.receiveSocketMessage = {
type: 'hat',
category: 'network',
spec: 'when I receive %msgOutput'
};
// Role Reporters
SpriteMorph.prototype.blocks.getProjectId = {
type: 'reporter',
category: 'network',
spec: 'role name'
};
SpriteMorph.prototype.blocks.getProjectIds = {
type: 'reporter',
category: 'network',
spec: 'all role names'
};
// Geo
SpriteMorph.prototype.blocks.reportLatitude = {
type: 'reporter',
category: 'sensing',
spec: 'my latitude'
};
SpriteMorph.prototype.blocks.reportLongitude = {
type: 'reporter',
category: 'sensing',
spec: 'my longitude'
};
// Stage info
SpriteMorph.prototype.blocks.reportStageWidth = {
type: 'reporter',
category: 'sensing',
spec: 'stage width'
};
SpriteMorph.prototype.blocks.reportStageHeight = {
type: 'reporter',
category: 'sensing',
spec: 'stage height'
};
SpriteMorph.prototype.blocks.reportUsername = {
type: 'reporter',
category: 'sensing',
spec: 'username'
};
};
SpriteMorph.prototype.initBlocks();
// SpriteMorph project/sead id(s)
SpriteMorph.prototype.getProjectId = function () {
var ide = this.parentThatIsA(IDE_Morph);
return ide.projectName;
};
SpriteMorph.prototype.getProjectIds = function () {
var ide = this.parentThatIsA(IDE_Morph),
roles = ide.room.getRoleNames();
return new List(roles);
};
StageMorph.prototype.getProjectId =
SpriteMorph.prototype.getProjectId;
StageMorph.prototype.getProjectIds =
SpriteMorph.prototype.getProjectIds;
// SpriteMorph non-variable watchers
SpriteMorph.prototype.reportUsername = function () {
return SnapCloud.username || '';
};
StageMorph.prototype.reportUsername =
SpriteMorph.prototype.reportUsername;
SpriteMorph.prototype._blockForSelector = SpriteMorph.prototype.blockForSelector; // super
SpriteMorph.prototype.blockForSelector = function(selector, setDefaults) {
var block = this._blockForSelector(selector, setDefaults);
if (selector === 'receiveSocketMessage') { // this hat block is executable (it "unpacks" the msg)
block.blockSequence = CommandBlockMorph.prototype.blockSequence;
}
return block;
};
// Palette
SpriteMorph.prototype.deletableMessageNames = function() {
var stage = this.parentThatIsA(StageMorph);
return stage.deletableMessageNames();
};
StageMorph.prototype.deletableMessageNames = function() {
return this.messageTypes.names().filter(function(name) {
return name !== 'message';
});
};
SpriteMorph.prototype.deleteMessageType = function(name) {
var ide = this.parentThatIsA(IDE_Morph),
stage = ide.stage,
cat = 'network';
stage.messageTypes.deleteMsgType(name);
// Refresh message palette if possible in case the user is already on the 'Room' tab
try {
ide.room.parentThatIsA(RoomEditorMorph).updateRoom();
if (ide && ide.currentTab === 'room') {
ide.spriteBar.tabBar.tabTo('room');
}
} catch(e) {
//do nothing
}
ide.flushBlocksCache(cat); // b/c of inheritance
ide.refreshPalette();
};
StageMorph.prototype.deleteMessageType =
SpriteMorph.prototype.deleteMessageType;
// StageMorph Overrides
StageMorph.prototype._init = StageMorph.prototype.init;
StageMorph.prototype.init = function (globals) {
this.messageTypes = new MessageFrame();
this.addMessageType({ // Add initial message type
name: 'message',
fields: ['msg']
});
this._init(globals);
};
StageMorph.prototype.addMessageType = function (messageType) {
var msgType,
name,
fields;
name = messageType.name;
fields = messageType.fields;
msgType = new MessageType(name, fields);
this.messageTypes.addMsgType(msgType);
// Refresh message palette if possible in case the user is already on the 'Room' tab
try {
var ide = this.parentThatIsA(NetsBloxMorph);
ide.room.parentThatIsA(RoomEditorMorph).updateRoom();
if (ide && ide.currentTab === 'room') {
ide.spriteBar.tabBar.tabTo('room');
}
} catch(e) {
// do nothing
}
};
ReplayControls.prototype._applyEvent = ReplayControls.prototype.applyEvent;
ReplayControls.prototype.applyEvent = function(event, next) {
if (event.type !== 'openProject') {
return ReplayControls.prototype._applyEvent.apply(this, arguments);
} else {
return next();
}
};
SpriteMorph.prototype.reportRPCError = function () {
return this.parentThatIsA(StageMorph).rpcError;
};
StageMorph.prototype.reportRPCError = function () {
return this.rpcError;
};
WatcherMorph.prototype._isGlobal =
WatcherMorph.prototype.isGlobal;
WatcherMorph.prototype.isGlobal = function (selector) {
return selector === 'reportRPCError' ||
WatcherMorph.prototype._isGlobal.call(this, selector);
};