mumuki-gobstones-runner 2.8.1 → 2.9.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/assets_server.rb +4 -3
- data/lib/checker.rb +1 -0
- data/lib/gobstones/compilation_mode.rb +1 -1
- data/lib/public/local-media/main-procedure.png +0 -0
- data/lib/public/local-media/program.png +0 -0
- data/lib/public/media/ShiftDown.png +0 -0
- data/lib/public/media/ShiftLeft.png +0 -0
- data/lib/public/media/ShiftRight.png +0 -0
- data/lib/public/media/ShiftUp.png +0 -0
- data/lib/render/editor/editor.css +4 -0
- data/lib/render/editor/editor.html.erb +340 -252
- data/lib/render/editor/hammer.min.js +1 -0
- data/lib/version_hook.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8649ceb9e6f82c9af3f51dcd2e043789db0c332dfc5e9527255cc62556a36df7
|
4
|
+
data.tar.gz: 1bd206f906582c08ae1f4d868d101c624acf13e75f44d5a2ff40d72586a20cc5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6e614deb4c8f6872f4e46ef40635994b43895f398f40b2c8d6a13aa5e3b88da29ba1b7ff12e7227f7993ca49b651858d57dfba7345414ab8b1bd3e6172845123
|
7
|
+
data.tar.gz: 54e15f720eca89a266dc4c6a7363c7ace0f58f02d5d7f3ead5e20cc92753779f6ed784ad39505f6fb375e5efd75747abd73d2dfb449eb08464140ab9f46a0cae
|
data/lib/assets_server.rb
CHANGED
@@ -18,8 +18,9 @@ class Mumukit::Server::App < Sinatra::Base
|
|
18
18
|
end
|
19
19
|
|
20
20
|
def self.get_media_assets(folder)
|
21
|
-
Dir.glob("lib/public/#{folder}/*").each do |path|
|
22
|
-
|
21
|
+
Dir.glob(File.join(__dir__,"../lib/public/#{folder}/*")).each do |path|
|
22
|
+
relative_media_asset_path = "#{folder}/#{File.basename path}"
|
23
|
+
get_local_asset relative_media_asset_path, "lib/public/#{relative_media_asset_path}"
|
23
24
|
end
|
24
25
|
end
|
25
26
|
|
@@ -57,6 +58,6 @@ class Mumukit::Server::App < Sinatra::Base
|
|
57
58
|
@game_framework_program = Gobstones::CompilationMode::GameFramework.program_code
|
58
59
|
@game_framework_default = Gobstones::CompilationMode::GameFramework.default_code
|
59
60
|
@assets_url = "//#{request.host_with_port}/assets"
|
60
|
-
erb File.read(File.join(
|
61
|
+
erb File.read(File.join(__dir__, 'render/editor/editor.html.erb'))
|
61
62
|
end
|
62
63
|
end
|
data/lib/checker.rb
CHANGED
@@ -113,6 +113,7 @@ module Gobstones
|
|
113
113
|
return "no_stones" if code == 'cannot-remove-stone'
|
114
114
|
return "out_of_board" if code == 'cannot-move-to'
|
115
115
|
return "unassigned_variable" if code == 'undefined-variable'
|
116
|
+
return "boom_called" if code == 'boom-called'
|
116
117
|
return "wrong_argument_type" if has_wrong_argument_type? code
|
117
118
|
return "wrong_arguments_quantity" if code.include? 'arity-mismatch'
|
118
119
|
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
@@ -4,6 +4,30 @@
|
|
4
4
|
<link href="./gobstones-code-runner.html" rel="import"/>
|
5
5
|
<script src="./hammer.min.js"></script>
|
6
6
|
|
7
|
+
<script>
|
8
|
+
Blockly.FieldImage.prototype.__setValue__ = Blockly.FieldImage.prototype.setValue;
|
9
|
+
Blockly.FieldImage.prototype.setValue = function(a) {
|
10
|
+
if (a && a.startsWith("undefined")) {
|
11
|
+
console.debug(`Ignoring unavailable image ${a}`);
|
12
|
+
} else {
|
13
|
+
this.__setValue__(a);
|
14
|
+
}
|
15
|
+
}
|
16
|
+
|
17
|
+
Blockly.FieldImage.prototype.__setTooltip__ = Blockly.FieldImage.prototype.setTooltip;
|
18
|
+
Blockly.FieldImage.prototype.setTooltip = function(a) {
|
19
|
+
try {
|
20
|
+
this.__setTooltip__(a);
|
21
|
+
} catch (_e) {
|
22
|
+
console.debug('Could not set tooltip');
|
23
|
+
}
|
24
|
+
}
|
25
|
+
|
26
|
+
function postpone(action) {
|
27
|
+
return setTimeout(action, 50);
|
28
|
+
}
|
29
|
+
</script>
|
30
|
+
|
7
31
|
<dom-module id="mu-gobstones-custom-editor">
|
8
32
|
|
9
33
|
<template>
|
@@ -20,15 +44,6 @@
|
|
20
44
|
</template>
|
21
45
|
|
22
46
|
<script>
|
23
|
-
function postpone(action) {
|
24
|
-
return setTimeout(action, 50);
|
25
|
-
}
|
26
|
-
|
27
|
-
function gbsBoardRemoveBorder(board) {
|
28
|
-
board._setBorderOff();
|
29
|
-
board.updateStyles();
|
30
|
-
}
|
31
|
-
|
32
47
|
const compilationModes = {
|
33
48
|
gameFramework: {
|
34
49
|
compile: ({ main, teacher, ...args }) => {
|
@@ -46,7 +61,9 @@
|
|
46
61
|
|
47
62
|
scrollToMainBlock: (blockly) => {
|
48
63
|
const mainBlock = blockly.getBlocksOfType('procedures_defnoreturnnoparams')[0];
|
49
|
-
|
64
|
+
if (mainBlock) {
|
65
|
+
blockly.scrollToBlock(mainBlock.id);
|
66
|
+
}
|
50
67
|
},
|
51
68
|
|
52
69
|
defaultCode: `<%= @game_framework_default %>`
|
@@ -90,184 +107,264 @@
|
|
90
107
|
}
|
91
108
|
},
|
92
109
|
|
93
|
-
|
94
|
-
const setBlocklySounds = () => {
|
95
|
-
Blockly.WorkspaceAudio.prototype.preload = () => {
|
96
|
-
for (var soundName in this.SOUNDS_) {
|
97
|
-
let sound = this.SOUNDS_[soundName];
|
98
|
-
sound.volume = 0.01;
|
99
|
-
let playPromise = sound.play();
|
100
|
-
playPromise && playPromise.then(sound.pause.bind(sound));
|
101
|
-
if (goog.userAgent.IPAD || goog.userAgent.IPHONE) break;
|
102
|
-
}
|
103
|
-
};
|
104
|
-
};
|
110
|
+
// ==== Polymer events
|
105
111
|
|
106
|
-
|
107
|
-
|
108
|
-
Blockly.HSV_VALUE = 1;
|
112
|
+
attached() {
|
113
|
+
this.$exerciseContainer = $('.mu-kids-exercise');
|
109
114
|
|
110
|
-
|
111
|
-
|
112
|
-
blue: "#5CBEFF",
|
113
|
-
yellow: "#FFC95C",
|
114
|
-
green: "#5CED71"
|
115
|
-
};
|
115
|
+
/*
|
116
|
+
https://polymer-library.polymer-project.org/1.0/docs/devguide/registering-elements#initialization-order
|
116
117
|
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
Blockly.CUSTOM_COLORS.controlStructure = this._isKindergarten() ? Blockly.MUMUKI_COLORS.green : Blockly.MUMUKI_COLORS.yellow;
|
127
|
-
|
128
|
-
// commands
|
129
|
-
Blockly.CUSTOM_COLORS.primitiveCommand = Blockly.MUMUKI_COLORS.yellow;
|
130
|
-
Blockly.CUSTOM_COLORS.primitiveProcedure = Blockly.MUMUKI_COLORS.yellow;
|
131
|
-
Blockly.CUSTOM_COLORS.procedure_call = Blockly.MUMUKI_COLORS.yellow;
|
132
|
-
Blockly.CUSTOM_COLORS.assignation = Blockly.MUMUKI_COLORS.yellow;
|
133
|
-
|
134
|
-
// expressions
|
135
|
-
Blockly.Msg.MATH_HUE = Blockly.MUMUKI_COLORS.blue;
|
136
|
-
Blockly.CUSTOM_COLORS.literalExpression = Blockly.MUMUKI_COLORS.blue;
|
137
|
-
Blockly.CUSTOM_COLORS.primitiveExpression = Blockly.MUMUKI_COLORS.blue;
|
138
|
-
Blockly.CUSTOM_COLORS.operator = Blockly.MUMUKI_COLORS.blue;
|
139
|
-
Blockly.CUSTOM_COLORS.variable = Blockly.MUMUKI_COLORS.blue;
|
140
|
-
Blockly.CUSTOM_COLORS.parameter = Blockly.MUMUKI_COLORS.blue;
|
141
|
-
Blockly.CUSTOM_COLORS.primitiveFunction = Blockly.MUMUKI_COLORS.blue;
|
142
|
-
Blockly.CUSTOM_COLORS.function_call = Blockly.MUMUKI_COLORS.blue;
|
143
|
-
|
144
|
-
setTimeout(() => {
|
145
|
-
this.getBlockly().testColors(Blockly.CUSTOM_COLORS);
|
146
|
-
});
|
147
|
-
};
|
118
|
+
There are no guarantees with regard to initialization timing between sibling elements.
|
119
|
+
This means that siblings may become ready in any order.
|
120
|
+
For accessing sibling elements when an element initializes, you can call async from inside the attached callback.
|
121
|
+
*/
|
122
|
+
this.async(() => {
|
123
|
+
this._configureBlocklyAppearance();
|
124
|
+
this._configureBlocklyBehavior();
|
125
|
+
});
|
126
|
+
},
|
148
127
|
|
149
|
-
|
150
|
-
if (typeof Blockly === 'undefined' || !Blockly.CUSTOM_COLORS) return postpone(setBlocklyCustomSettings);
|
128
|
+
// ==== Public methods (accesible from other components)
|
151
129
|
|
152
|
-
|
153
|
-
|
154
|
-
|
130
|
+
reset() {
|
131
|
+
const blockly = this._getBlockly();
|
132
|
+
blockly.workspaceXml = blockly.initialXml;
|
133
|
+
this._scrollToMainBlock();
|
134
|
+
},
|
155
135
|
|
156
|
-
|
157
|
-
|
158
|
-
|
136
|
+
/**
|
137
|
+
* Configures a custom toolbox using a toolbox url
|
138
|
+
* This method does nothing if editor is read-only, but
|
139
|
+
* assumes a gs-toolbox element is present - otherwise it would
|
140
|
+
* have no sense to have a toolboxUrl.
|
141
|
+
*/
|
142
|
+
configureCustomToolboxFromUrl(toolboxUrl) {
|
143
|
+
if (this.readOnly) return;
|
159
144
|
|
160
|
-
|
161
|
-
Blockly.utils.genUid.soup_ = Blockly.utils.genUid.soup_.replace("/", "");
|
162
|
-
};
|
145
|
+
console.debug('Configuring custom toolbox');
|
163
146
|
|
164
|
-
|
165
|
-
|
147
|
+
$.get(toolboxUrl, (toolboxXml) => {
|
148
|
+
this._initializeCustomToolboxBlocklyWorkspace(toolboxXml);
|
149
|
+
});
|
150
|
+
},
|
166
151
|
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
152
|
+
/**
|
153
|
+
* Wether a custom toolbox is required. Read only editors and gs-toolbox-less context
|
154
|
+
* don't require it
|
155
|
+
*/
|
156
|
+
hasCustomToolbox() {
|
157
|
+
return !this.readOnly && $('gs-toolbox').length;
|
158
|
+
},
|
171
159
|
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
editorExtra.value = blockly.workspaceXml;
|
176
|
-
}
|
177
|
-
}
|
160
|
+
compile(code) {
|
161
|
+
return this._compilationMode().compile(code);
|
162
|
+
},
|
178
163
|
|
179
|
-
|
180
|
-
|
181
|
-
|
164
|
+
hasInteractiveProgram() {
|
165
|
+
return this._getBlockly().initialXml.indexOf("block type=\"InteractiveProgram\"") !== -1;
|
166
|
+
},
|
182
167
|
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
};
|
168
|
+
toggleInteractiveMode() {
|
169
|
+
this.$exerciseContainer.toggleClass('play-mode');
|
170
|
+
this._triggerResize();
|
171
|
+
},
|
188
172
|
|
189
|
-
|
173
|
+
getTeacherCode() {
|
174
|
+
const extraCode = this._getExtraCode();
|
175
|
+
if (!extraCode) return;
|
176
|
+
this.$.blocklyTmp.workspaceXml = extraCode;
|
177
|
+
return this.$.blocklyTmp.generateCode();
|
178
|
+
},
|
190
179
|
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
};
|
180
|
+
getStudentCode: function () {
|
181
|
+
return this
|
182
|
+
._getBlockly()
|
183
|
+
.generateCode({withRegions: true, clearErrors: false});
|
184
|
+
},
|
197
185
|
|
198
|
-
|
186
|
+
getStudentXml: function () {
|
187
|
+
return this._getStudentSolution() || "";
|
188
|
+
},
|
199
189
|
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
setTrashPosition();
|
204
|
-
});
|
205
|
-
};
|
190
|
+
getTestCode() {
|
191
|
+
return this._getEditorTest().value;
|
192
|
+
},
|
206
193
|
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
})
|
211
|
-
};
|
194
|
+
removeBlockErrors() {
|
195
|
+
return this._getBlockly().workspace.removeBlockErrors();
|
196
|
+
},
|
212
197
|
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
};
|
198
|
+
showBlockError(region, error) {
|
199
|
+
this._getBlockly().scrollToBlock(region);
|
200
|
+
this._getBlockly().showBlockError(region, error.message);
|
201
|
+
},
|
218
202
|
|
219
|
-
|
220
|
-
|
221
|
-
|
203
|
+
highlightBlock(region) {
|
204
|
+
this._getBlockly().highlightBlock(region);
|
205
|
+
},
|
222
206
|
|
223
|
-
|
207
|
+
// ==== Private methods (only for internal usage)
|
224
208
|
|
225
|
-
|
209
|
+
_configureBlocklyAppearance() {
|
210
|
+
this._getBlockly().showCategories = !this._isKindergarten();
|
211
|
+
this._setBlocklyDisplayMode();
|
212
|
+
this._setBlocklySounds();
|
213
|
+
this._setBlocklyColors();
|
226
214
|
|
227
|
-
|
228
|
-
|
229
|
-
|
215
|
+
if (!this.readOnly) {
|
216
|
+
this._relocateTrashOnResize();
|
217
|
+
}
|
230
218
|
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
if (this.interactiveMode) this.setInteractiveLayout();
|
235
|
-
this._initializeWorkspace(blockly, () => {
|
236
|
-
localOnResize();
|
237
|
-
blockly._onresize();
|
219
|
+
// Removing "/" from the block id character set to avoid syntax errors
|
220
|
+
Blockly.utils.genUid.soup_ = Blockly.utils.genUid.soup_.replace("/", "");
|
221
|
+
},
|
238
222
|
|
239
|
-
|
240
|
-
|
223
|
+
_configureBlocklyBehavior() {
|
224
|
+
this._setTeacherActions();
|
225
|
+
this._setGameActions();
|
226
|
+
this._initializeNonCustomToolboxBlocklyWorkspace();
|
227
|
+
this._registerLayoutChangedEvent();
|
228
|
+
},
|
241
229
|
|
242
|
-
|
243
|
-
|
230
|
+
_relocateTrashOnResize() {
|
231
|
+
$('.mu-kids-context, .mu-kids-results').on('hidden.bs.modal shown.bs.modal', () => {
|
232
|
+
this._relocateTrash();
|
233
|
+
});
|
244
234
|
|
245
|
-
|
246
|
-
|
235
|
+
$(window).resize(() => this._relocateTrash());
|
236
|
+
},
|
237
|
+
|
238
|
+
|
239
|
+
/**
|
240
|
+
* Initializes a workspace using a custom toolbox.
|
241
|
+
*
|
242
|
+
* Blockly's workspace is destroyed when toolbox changes, so initialization
|
243
|
+
* is performed here
|
244
|
+
*/
|
245
|
+
_initializeCustomToolboxBlocklyWorkspace(toolboxXml) {
|
246
|
+
this._getBlockly().toolbox = { defaultToolbox: toolboxXml };
|
247
|
+
this._initializeBlocklyWorkspace();
|
248
|
+
},
|
249
|
+
|
250
|
+
/**
|
251
|
+
* Initializes a workspace using a non-custom toolbox.
|
252
|
+
*
|
253
|
+
* Blockly's workspace is destroyed when toolbox changes,
|
254
|
+
* so this method will initialize it only if a there is a custom toolbox
|
255
|
+
* that will be called later.
|
256
|
+
*/
|
257
|
+
_initializeNonCustomToolboxBlocklyWorkspace() {
|
258
|
+
if (!this.hasCustomToolbox()) {
|
259
|
+
this._initializeBlocklyWorkspace();
|
260
|
+
}
|
261
|
+
},
|
262
|
+
|
263
|
+
_initializeBlocklyWorkspace() {
|
264
|
+
console.debug('Initializing Blockly Workspace');
|
265
|
+
|
266
|
+
this._setInitialXml();
|
267
|
+
this._initializeWorkspace();
|
268
|
+
this._subscribeToWorkspace(() => this._updateSolution());
|
269
|
+
|
270
|
+
if (this.hasInteractiveProgram()) {
|
271
|
+
this._setInteractiveLayout();
|
272
|
+
}
|
273
|
+
|
274
|
+
mumuki.assetsLoadedFor('editor');
|
275
|
+
},
|
276
|
+
|
277
|
+
_relocateTrash() {
|
278
|
+
const width = $('#blocklyDiv').width() - 68;
|
279
|
+
const height = $('#blocklyDiv').height() - 210;
|
280
|
+
$('.blocklyTrash').css("transform", `translate(${width}px, ${height}px)`);
|
281
|
+
$('.blocklyTrash').css("display", "unset");
|
282
|
+
},
|
283
|
+
|
284
|
+
_updateSolution() {
|
285
|
+
const blockly = this._getBlockly();
|
286
|
+
|
287
|
+
if (this.teacherMode) {
|
288
|
+
this._setExtraCode(blockly.workspaceXml);
|
289
|
+
} else {
|
290
|
+
this._setStudentSolution(blockly.workspaceXml);
|
291
|
+
}
|
292
|
+
|
293
|
+
// TODO: this hack enables Angular two-way binding for Bibliotheca. Should be replaced with Mumuki events system
|
294
|
+
if (typeof angular !== 'undefined') {
|
295
|
+
angular.element(this._getStudentEditor()).triggerHandler("change");
|
296
|
+
angular.element(this._getEditorExtra()).triggerHandler("change");
|
297
|
+
}
|
298
|
+
|
299
|
+
this._stopExecution();
|
300
|
+
},
|
301
|
+
|
302
|
+
_setBlocklySounds() {
|
303
|
+
Blockly.WorkspaceAudio.prototype.preload = () => {
|
304
|
+
for (const soundName in this.SOUNDS_) {
|
305
|
+
const sound = this.SOUNDS_[soundName];
|
306
|
+
sound.volume = 0.01;
|
307
|
+
const playPromise = sound.play();
|
308
|
+
playPromise && playPromise.then(sound.pause.bind(sound));
|
309
|
+
if (goog.userAgent.IPAD || goog.userAgent.IPHONE) break;
|
310
|
+
}
|
247
311
|
};
|
312
|
+
},
|
313
|
+
|
314
|
+
_setBlocklyColors() {
|
315
|
+
Blockly.HSV_SATURATION = 0.64;
|
316
|
+
Blockly.HSV_VALUE = 1;
|
317
|
+
|
318
|
+
Blockly.MUMUKI_COLORS = {
|
319
|
+
pink: "#FF5C82",
|
320
|
+
blue: "#5CBEFF",
|
321
|
+
yellow: "#FFC95C",
|
322
|
+
green: "#5CED71"
|
323
|
+
};
|
324
|
+
|
325
|
+
// reserved
|
326
|
+
Blockly.CUSTOM_COLORS.program = Blockly.MUMUKI_COLORS.pink;
|
327
|
+
Blockly.CUSTOM_COLORS.interactiveProgram = Blockly.MUMUKI_COLORS.pink;
|
328
|
+
Blockly.CUSTOM_COLORS.interactiveBinding = Blockly.MUMUKI_COLORS.pink;
|
329
|
+
Blockly.CUSTOM_COLORS.procedure = Blockly.MUMUKI_COLORS.pink;
|
330
|
+
Blockly.CUSTOM_COLORS.function = Blockly.MUMUKI_COLORS.pink;
|
331
|
+
Blockly.CUSTOM_COLORS.complete = Blockly.MUMUKI_COLORS.pink;
|
332
|
+
|
333
|
+
// control structures
|
334
|
+
Blockly.CUSTOM_COLORS.controlStructure = this._isKindergarten() ? Blockly.MUMUKI_COLORS.green : Blockly.MUMUKI_COLORS.yellow;
|
335
|
+
|
336
|
+
// commands
|
337
|
+
Blockly.CUSTOM_COLORS.primitiveCommand = Blockly.MUMUKI_COLORS.yellow;
|
338
|
+
Blockly.CUSTOM_COLORS.primitiveProcedure = Blockly.MUMUKI_COLORS.yellow;
|
339
|
+
Blockly.CUSTOM_COLORS.procedure_call = Blockly.MUMUKI_COLORS.yellow;
|
340
|
+
Blockly.CUSTOM_COLORS.assignation = Blockly.MUMUKI_COLORS.yellow;
|
248
341
|
|
249
|
-
|
250
|
-
|
342
|
+
// expressions
|
343
|
+
Blockly.Msg.MATH_HUE = Blockly.MUMUKI_COLORS.blue;
|
344
|
+
Blockly.CUSTOM_COLORS.literalExpression = Blockly.MUMUKI_COLORS.blue;
|
345
|
+
Blockly.CUSTOM_COLORS.primitiveExpression = Blockly.MUMUKI_COLORS.blue;
|
346
|
+
Blockly.CUSTOM_COLORS.operator = Blockly.MUMUKI_COLORS.blue;
|
347
|
+
Blockly.CUSTOM_COLORS.variable = Blockly.MUMUKI_COLORS.blue;
|
348
|
+
Blockly.CUSTOM_COLORS.parameter = Blockly.MUMUKI_COLORS.blue;
|
349
|
+
Blockly.CUSTOM_COLORS.primitiveFunction = Blockly.MUMUKI_COLORS.blue;
|
350
|
+
Blockly.CUSTOM_COLORS.function_call = Blockly.MUMUKI_COLORS.blue;
|
251
351
|
},
|
252
352
|
|
253
|
-
|
254
|
-
this
|
255
|
-
|
353
|
+
_setBlocklyDisplayMode() {
|
354
|
+
// The display mode configuration could be monkey-patched here, like this:
|
355
|
+
Blockly.displayModes.iconic.iconSize = 64;
|
356
|
+
Blockly.displayModes.iconic.procedureDefIcon = `${this.localMediaUrl}main-procedure.png`;
|
357
|
+
|
358
|
+
Blockly.displayMode = this._isKindergarten() ? 'iconic' : 'text';
|
256
359
|
},
|
257
360
|
|
258
|
-
|
259
|
-
|
361
|
+
_triggerResize() {
|
362
|
+
const event = document.createEvent('HTMLEvents');
|
260
363
|
event.initEvent('resize', true, false);
|
261
364
|
document.dispatchEvent(event);
|
262
365
|
},
|
263
366
|
|
264
|
-
|
265
|
-
const blockly = this.getBlockly();
|
266
|
-
blockly.workspaceXml = code || blockly.initialXml;
|
267
|
-
this._scrollToMainBlock();
|
268
|
-
},
|
269
|
-
|
270
|
-
setInteractiveLayout() {
|
367
|
+
_setInteractiveLayout() {
|
271
368
|
this.$exerciseContainer.addClass('mu-kids-interactive');
|
272
369
|
$('.mu-final-state').html('<gs-keyboard/>');
|
273
370
|
$('.mu-editor').append($('<kids-interactive-submit-button/>'));
|
@@ -277,82 +374,86 @@
|
|
277
374
|
})
|
278
375
|
},
|
279
376
|
|
280
|
-
|
377
|
+
_setTeacherActions() {
|
281
378
|
const teacherCode = this.getTeacherCode();
|
282
|
-
if (teacherCode) {
|
283
|
-
|
284
|
-
const actions = new Parser().getActionsFromSource(teacherCode);
|
285
|
-
|
286
|
-
blockly.primitiveProcedures = this._withDefaultIcons(actions, 'procedureDeclarations');
|
287
|
-
blockly.primitiveFunctions = this._withDefaultIcons(actions, 'functionDeclarations');
|
288
|
-
});
|
379
|
+
if (!teacherCode) {
|
380
|
+
return;
|
289
381
|
}
|
382
|
+
|
383
|
+
const blockly = this._getBlockly();
|
384
|
+
const actions = new Parser().getActionsFromSource(teacherCode);
|
385
|
+
blockly.primitiveProcedures = this._withDefaultIcons(actions, 'procedureDeclarations');
|
386
|
+
blockly.primitiveFunctions = this._withDefaultIcons(actions, 'functionDeclarations');
|
290
387
|
},
|
291
388
|
|
292
|
-
|
389
|
+
_setGameActions() {
|
390
|
+
const blockly = this._getBlockly();
|
293
391
|
if (this._isGame()) {
|
294
392
|
blockly.primitiveProcedures = blockly.primitiveProcedures || [];
|
295
393
|
blockly.primitiveProcedures = blockly.primitiveProcedures.concat([
|
296
|
-
this.
|
297
|
-
this.
|
298
|
-
this.
|
299
|
-
this.
|
394
|
+
this._gamePrimitive('ShiftUp'),
|
395
|
+
this._gamePrimitive('ShiftDown'),
|
396
|
+
this._gamePrimitive('ShiftLeft'),
|
397
|
+
this._gamePrimitive('ShiftRight')
|
300
398
|
]);
|
301
399
|
}
|
302
400
|
},
|
303
401
|
|
304
|
-
|
305
|
-
return { alias: 'procedureDeclaration', name
|
402
|
+
_gamePrimitive(name) {
|
403
|
+
return { alias: 'procedureDeclaration', name, attributes: {block_icon: `<%= @assets_url %>/media/${name}.png`} };
|
306
404
|
},
|
307
405
|
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
} else {
|
312
|
-
return postpone(this.enableContextButton.bind(this));
|
313
|
-
}
|
406
|
+
_getBlockly() {
|
407
|
+
return this.$.blocklyElement;
|
408
|
+
},
|
314
409
|
|
410
|
+
_getStudentSolution() {
|
411
|
+
return this._getStudentEditor().value;
|
315
412
|
},
|
316
413
|
|
317
|
-
|
318
|
-
|
414
|
+
/**
|
415
|
+
* Sets the student solution xml, which corresponds
|
416
|
+
* to user content in laboratory, and default content in bibliotheca
|
417
|
+
*/
|
418
|
+
_setStudentSolution(code) {
|
419
|
+
console.debug(`Setting student ${code}`)
|
420
|
+
this._getStudentEditor().value = code;
|
319
421
|
},
|
320
422
|
|
321
|
-
|
322
|
-
return this
|
323
|
-
.getBlockly()
|
324
|
-
.generateCode({withRegions: true, clearErrors: false});
|
423
|
+
_getDefaultCode() {
|
424
|
+
return this._getEditorDefaultValue().value;
|
325
425
|
},
|
326
426
|
|
327
|
-
|
328
|
-
return this.
|
427
|
+
_getExtraCode() {
|
428
|
+
return this._getEditorExtra().value;
|
329
429
|
},
|
330
430
|
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
this.$.blocklyTmp.workspaceXml = teacherXml.value;
|
335
|
-
return this.$.blocklyTmp.generateCode();
|
431
|
+
_setExtraCode(code) {
|
432
|
+
console.debug(`Setting extra ${code}`)
|
433
|
+
this._getEditorExtra().value = code;
|
336
434
|
},
|
337
435
|
|
338
|
-
|
339
|
-
return $("#mu-custom-editor-
|
436
|
+
_getEditorExtra: function() {
|
437
|
+
return $("#mu-custom-editor-extra")[0] || {};
|
340
438
|
},
|
341
439
|
|
342
|
-
|
343
|
-
return $("#mu-custom-editor-
|
440
|
+
_getEditorTest: function() {
|
441
|
+
return $("#mu-custom-editor-test")[0];
|
344
442
|
},
|
345
443
|
|
346
|
-
|
347
|
-
return $("#mu-custom-editor-
|
444
|
+
_getStudentEditor: function() {
|
445
|
+
return $("#mu-custom-editor-value")[0] || {};
|
348
446
|
},
|
349
447
|
|
350
|
-
|
351
|
-
return $("#mu-custom-editor-
|
448
|
+
_getEditorDefaultValue: function() {
|
449
|
+
return $("#mu-custom-editor-default-value")[0] || {};
|
352
450
|
},
|
353
451
|
|
354
|
-
|
355
|
-
|
452
|
+
_stopExecution() {
|
453
|
+
const submit = $("kids-submit-button")[0];
|
454
|
+
if (submit && submit.$.runner.isRunning) {
|
455
|
+
submit.$.runner.stop();
|
456
|
+
}
|
356
457
|
},
|
357
458
|
|
358
459
|
_registerLayoutChangedEvent() {
|
@@ -361,12 +462,13 @@
|
|
361
462
|
}
|
362
463
|
|
363
464
|
mumuki.events.on('layoutChanged', () => {
|
364
|
-
|
465
|
+
console.debug('layout changed');
|
466
|
+
this._setStudentSolution(this._compilationMode().defaultCode);
|
365
467
|
});
|
366
468
|
},
|
367
469
|
|
368
470
|
_scrollToMainBlock() {
|
369
|
-
this._compilationMode().scrollToMainBlock(this.
|
471
|
+
this._compilationMode().scrollToMainBlock(this._getBlockly());
|
370
472
|
},
|
371
473
|
|
372
474
|
_withDefaultIcons(actions, type) {
|
@@ -400,35 +502,31 @@
|
|
400
502
|
return this._isGame() ? compilationModes.gameFramework : compilationModes.classic;
|
401
503
|
},
|
402
504
|
|
403
|
-
_setInitialXml: function (
|
404
|
-
const
|
405
|
-
|
406
|
-
|
505
|
+
_setInitialXml: function () {
|
506
|
+
const blockly = this._getBlockly();
|
507
|
+
const defaultCode = this._getDefaultCode();
|
508
|
+
if (defaultCode) {
|
509
|
+
blockly.initialXml = defaultCode;
|
407
510
|
} else {
|
408
511
|
blockly.initialXml = blockly.workspaceXml;
|
409
512
|
}
|
410
513
|
},
|
411
514
|
|
412
|
-
_initializeWorkspace
|
413
|
-
|
414
|
-
|
515
|
+
_initializeWorkspace() {
|
516
|
+
const blockly = this._getBlockly();
|
517
|
+
const value = this._getStudentSolution();
|
415
518
|
|
416
|
-
|
417
|
-
|
418
|
-
|
419
|
-
|
420
|
-
|
421
|
-
this._scrollToMainBlock();
|
519
|
+
blockly.workspaceXml = value || (
|
520
|
+
this.teacherMode
|
521
|
+
? "<xml></xml>"
|
522
|
+
: blockly.initialXml
|
523
|
+
);
|
422
524
|
|
423
|
-
|
424
|
-
});
|
525
|
+
this._scrollToMainBlock();
|
425
526
|
},
|
426
527
|
|
427
|
-
_subscribeToWorkspace: function(
|
428
|
-
|
429
|
-
blockly.workspace.addChangeListener(action);
|
430
|
-
action();
|
431
|
-
});
|
528
|
+
_subscribeToWorkspace: function(action) {
|
529
|
+
this._getBlockly().workspace.addChangeListener(action);
|
432
530
|
}
|
433
531
|
});
|
434
532
|
</script>
|
@@ -796,16 +894,21 @@
|
|
796
894
|
finalBoard.update(table, head);
|
797
895
|
}
|
798
896
|
|
799
|
-
|
897
|
+
this._removeBorder(finalBoard);
|
898
|
+
},
|
899
|
+
|
900
|
+
_removeBorder(board) {
|
901
|
+
board._setBorderOff();
|
902
|
+
board.updateStyles();
|
800
903
|
},
|
801
904
|
|
802
905
|
_highlight: function (region) {
|
803
|
-
this.
|
906
|
+
this.$editor.highlightBlock(region);
|
804
907
|
},
|
805
908
|
|
806
909
|
_showError: function (region, error) {
|
807
910
|
const expectsTimeout = /expect_endless_while *: *true/.test(
|
808
|
-
this.$editor.
|
911
|
+
this.$editor.getTestCode()
|
809
912
|
);
|
810
913
|
|
811
914
|
const isExpectedTimeout = (
|
@@ -815,8 +918,7 @@
|
|
815
918
|
|
816
919
|
if (isExpectedTimeout) return;
|
817
920
|
|
818
|
-
this.
|
819
|
-
this._getBlockly().showBlockError(region, error.message);
|
921
|
+
this.$editor.showBlockError(region, error);
|
820
922
|
},
|
821
923
|
|
822
924
|
_cleanState: function () {
|
@@ -830,8 +932,8 @@
|
|
830
932
|
finalBoard.boom = false;
|
831
933
|
},
|
832
934
|
|
833
|
-
_removeBlockErrors
|
834
|
-
this.
|
935
|
+
_removeBlockErrors() {
|
936
|
+
this.$editor.removeBlockErrors();
|
835
937
|
},
|
836
938
|
|
837
939
|
_getLastRegion: function (context = {}) {
|
@@ -839,10 +941,6 @@
|
|
839
941
|
return regionStack && regionStack.filter(it => it).slice(-1)[0];
|
840
942
|
},
|
841
943
|
|
842
|
-
_getBlockly: function () {
|
843
|
-
return this.$editor.getBlockly();
|
844
|
-
},
|
845
|
-
|
846
944
|
_getInitialBoards: function () {
|
847
945
|
return $(".mu-initial-state gs-board");
|
848
946
|
},
|
@@ -869,7 +967,7 @@
|
|
869
967
|
},
|
870
968
|
|
871
969
|
_onResetState: function () {
|
872
|
-
this.
|
970
|
+
this._removeBlockErrors();
|
873
971
|
this._resetBoards();
|
874
972
|
this._toggleInitialState();
|
875
973
|
this.multipleScenarios.resetIndicators();
|
@@ -891,32 +989,22 @@
|
|
891
989
|
is: 'gs-toolbox',
|
892
990
|
properties: {
|
893
991
|
toolboxUrl: Object,
|
894
|
-
observer: '
|
992
|
+
observer: '_setEditorToolbox'
|
895
993
|
},
|
896
994
|
|
897
995
|
attached: function () {
|
898
|
-
this.
|
899
|
-
|
900
|
-
_toolboxChanged: function () {
|
901
|
-
this._setToolbox();
|
902
|
-
},
|
903
|
-
_setToolbox: function () {
|
904
|
-
const editor = $("mu-gobstones-custom-editor")[0];
|
905
|
-
const blockly = editor.getBlockly();
|
906
|
-
if(blockly.readOnly) return;
|
907
|
-
const previousCode = editor.getEditorValue().value;
|
908
|
-
$.get(this.toolboxUrl, function (toolboxXml) {
|
909
|
-
blockly.toolbox = { defaultToolbox: toolboxXml };
|
910
|
-
editor.setTeacherActions(blockly);
|
911
|
-
editor.setGameActions(blockly);
|
912
|
-
// @faloi - I couldn't figure out why the workspace gets replaced with a generic code,
|
913
|
-
// so here I force a reset with the code previously saved. Sorry not sorry.
|
914
|
-
postpone(() => {
|
915
|
-
editor.reset(previousCode);
|
916
|
-
});
|
917
|
-
}).always(function () {
|
918
|
-
editor.enableContextButton();
|
996
|
+
this.async(() => {
|
997
|
+
this._setEditorToolbox();
|
919
998
|
});
|
999
|
+
},
|
1000
|
+
|
1001
|
+
_setEditorToolbox: function () {
|
1002
|
+
const $editor = $("mu-gobstones-custom-editor")[0];
|
1003
|
+
|
1004
|
+
// there is no editor to configure
|
1005
|
+
if (!$editor) return;
|
1006
|
+
|
1007
|
+
$editor.configureCustomToolboxFromUrl(this.toolboxUrl);
|
920
1008
|
}
|
921
1009
|
});
|
922
1010
|
</script>
|
data/lib/version_hook.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mumuki-gobstones-runner
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.9.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rodrigo Alfonso
|
8
|
+
- Federico Aloi
|
8
9
|
autorequire:
|
9
10
|
bindir: bin
|
10
11
|
cert_chain: []
|
11
|
-
date: 2020-
|
12
|
+
date: 2020-10-28 00:00:00.000000000 Z
|
12
13
|
dependencies:
|
13
14
|
- !ruby/object:Gem::Dependency
|
14
15
|
name: gobstones-board
|
@@ -173,6 +174,7 @@ dependencies:
|
|
173
174
|
description:
|
174
175
|
email:
|
175
176
|
- rodri042@gmail.com
|
177
|
+
- federico.aloi@gmail.com
|
176
178
|
executables: []
|
177
179
|
extensions: []
|
178
180
|
extra_rdoc_files: []
|