Skip to content

Commit a839438

Browse files
committed
Constantize a bunch of things
- Fix when right / left
1 parent 1e56dad commit a839438

File tree

1 file changed

+18
-12
lines changed

1 file changed

+18
-12
lines changed

blockly/src/voxel/voxel.js

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,14 @@ var skin;
4444
BlocklyApps.CHECK_FOR_EMPTY_BLOCKS = false;
4545
BlocklyApps.NUM_REQUIRED_BLOCKS_TO_FLAG = 1;
4646

47-
var CANVAS_HEIGHT = 400;
48-
var CANVAS_WIDTH = 400;
47+
Voxel.APP_SHORTNAME = 'voxel';
48+
Voxel.DASHBOARD_APP_SHORTNAME = 'Voxel';
49+
Voxel.WIN_SOUND_KEY = 'win';
50+
Voxel.START_SOUND_KEY = 'start';
51+
Voxel.FAILURE_SOUND_KEY = 'failure';
52+
Voxel.WHEN_RUN_BLOCK_KEY = 'when_run';
53+
Voxel.WHEN_RIGHT_CLICK_BLOCK_KEY = 'voxel_whenRightClick';
54+
Voxel.WHEN_LEFT_CLICK_BLOCK_KEY = 'voxel_whenLeftClick';
4955

5056
/**
5157
* Initialize Blockly and the Voxel. Called on page load.
@@ -57,7 +63,7 @@ Voxel.init = function(config) {
5763
level = config.level;
5864

5965
config.grayOutUndeletableBlocks = true;
60-
config.forceInsertTopBlock = 'when_run';
66+
config.forceInsertTopBlock = Voxel.WHEN_RUN_BLOCK_KEY;
6167
config.enableShowCode = false;
6268

6369
config.html = page({
@@ -76,9 +82,9 @@ Voxel.init = function(config) {
7682
});
7783

7884
config.loadAudio = function() {
79-
BlocklyApps.loadAudio(skin.winSound, 'win');
80-
BlocklyApps.loadAudio(skin.startSound, 'start');
81-
BlocklyApps.loadAudio(skin.failureSound, 'failure');
85+
BlocklyApps.loadAudio(skin.winSound, Voxel.WIN_SOUND_KEY);
86+
BlocklyApps.loadAudio(skin.startSound, Voxel.START_SOUND_KEY);
87+
BlocklyApps.loadAudio(skin.failureSound, Voxel.FAILURE_SOUND_KEY);
8288
};
8389

8490
config.afterInject = function() {
@@ -106,7 +112,7 @@ Voxel.init = function(config) {
106112

107113
window.game.plugins.get('voxel-reach').on('use', Voxel.generateEventBlockCodeRunner('voxel_whenRightClick'));
108114
//window.game.plugins.get('voxel-reach').on('start mining', function(target) { Voxel.handleWhenLeftClick(target);});
109-
window.game.on('fire', Voxel.generateEventBlockCodeRunner('voxel_whenRightClick'));
115+
window.game.on('fire', Voxel.generateEventBlockCodeRunner('voxel_whenLeftClick'));
110116
};
111117

112118
BlocklyApps.init(config);
@@ -206,17 +212,17 @@ Voxel.endAttempt = function() {
206212
}
207213

208214
if (Voxel.testResults >= BlocklyApps.TestResults.FREE_PLAY) {
209-
BlocklyApps.playAudio('win');
215+
BlocklyApps.playAudio(Voxel.WIN_SOUND_KEY);
210216
} else {
211-
BlocklyApps.playAudio('failure');
217+
BlocklyApps.playAudio(Voxel.FAILURE_SOUND_KEY);
212218
}
213219

214220
var xml = Blockly.Xml.blockSpaceToDom(Blockly.mainBlockSpace);
215221
var textBlocks = Blockly.Xml.domToText(xml);
216222

217223
// Report result to server.
218224
BlocklyApps.report({
219-
app: 'voxel',
225+
app: Voxel.APP_SHORTNAME,
220226
level: level.id,
221227
result: Voxel.result === BlocklyApps.ResultType.SUCCESS,
222228
testResult: Voxel.testResults,
@@ -231,7 +237,7 @@ Voxel.endAttempt = function() {
231237
*/
232238
var displayFeedback = function(response) {
233239
BlocklyApps.displayFeedback({
234-
app: 'Voxel',
240+
app: Voxel.DASHBOARD_APP_SHORTNAME,
235241
skin: skin.id,
236242
feedbackType: Voxel.testResults,
237243
response: response,
@@ -246,7 +252,7 @@ var displayFeedback = function(response) {
246252

247253
/**
248254
* Function to be called when the service report call is complete
249-
* @param {object} JSON response (if available)
255+
* @param {object} response JSON response (if available)
250256
*/
251257
Voxel.onReportComplete = function(response) {
252258
Voxel.response = response;

0 commit comments

Comments
 (0)