Skip to content

Commit

Permalink
updated code to match latest blockly version
Browse files Browse the repository at this point in the history
  • Loading branch information
bgon committed Jun 8, 2016
1 parent 74cfa47 commit e3fac76
Show file tree
Hide file tree
Showing 11 changed files with 64 additions and 65 deletions.
Empty file modified src/main/js/www/README.md
100755 → 100644
Empty file.
Empty file modified src/main/js/www/build.xml
100755 → 100644
Empty file.
69 changes: 34 additions & 35 deletions src/main/js/www/code.js
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ Code.workspace = null;
* @param {string} defaultValue Value to return if paramater not found.
* @return {string} The parameter value or the default value if not found.
*/
Code.getStringParamFromUrl = function(name, defaultValue) {
Code.getStringParamFromUrl = function (name, defaultValue) {
var val = location.search.match(new RegExp('[?&]' + name + '=([^&]+)'));
return val ? decodeURIComponent(val[1].replace(/\+/g, '%20')) : defaultValue;
};
Expand All @@ -65,7 +65,7 @@ Code.getStringParamFromUrl = function(name, defaultValue) {
* Get the language of this user from the URL.
* @return {string} User's language.
*/
Code.getLang = function() {
Code.getLang = function () {
var lang = Code.getStringParamFromUrl('lang', '');
if (Code.LANGUAGE_NAME[lang] === undefined) {
// Default to English.
Expand All @@ -78,36 +78,34 @@ Code.getLang = function() {
* Is the current language (Code.LANG) an RTL language?
* @return {boolean} True if RTL, false if LTR.
*/
Code.isRtl = function() {
Code.isRtl = function () {
return Code.LANGUAGE_RTL.indexOf(Code.LANG) != -1;
};

/**
* Load blocks saved on App Engine Storage or in session/local storage.
* @param {string} defaultXml Text representation of default blocks.
*/
Code.loadBlocks = function(defaultXml) {
var loadOnce;
var xml;
Code.loadBlocks = function (defaultXml) {
try {
loadOnce = window.sessionStorage.loadOnceBlocks;
var loadOnce = window.sessionStorage.loadOnceBlocks;
} catch (e) {
// Firefox sometimes throws a SecurityError when accessing sessionStorage.
// Restarting Firefox fixes this, so it looks like a bug.
loadOnce = null;
var loadOnce = null;
}
if ('BlocklyStorage' in window && window.location.hash.length > 1) {
// An href with #key trigers an AJAX call to retrieve saved blocks.
BlocklyStorage.retrieveXml(window.location.hash.substring(1));
} else if (loadOnce) {
// Language switching stores the blocks during the reload.
delete window.sessionStorage.loadOnceBlocks;
xml = Blockly.Xml.textToDom(loadOnce);
Blockly.Xml.domToWorkspace(Code.workspace, xml);
var xml = Blockly.Xml.textToDom(loadOnce);
Blockly.Xml.domToWorkspace(xml, Code.workspace);
} else if (defaultXml) {
// Load the editor with default starting blocks.
xml = Blockly.Xml.textToDom(defaultXml);
Blockly.Xml.domToWorkspace(Code.workspace, xml);
var xml = Blockly.Xml.textToDom(defaultXml);
Blockly.Xml.domToWorkspace(xml, Code.workspace);
} else if ('BlocklyStorage' in window) {
// Restore saved blocks in a separate thread so that subsequent
// initialization is not affected from a failed load.
Expand All @@ -118,7 +116,7 @@ Code.loadBlocks = function(defaultXml) {
/**
* Save the blocks and reload with a different language.
*/
Code.changeLanguage = function() {
Code.changeLanguage = function () {
// Store the blocks for the duration of the reload.
// This should be skipped for the index page, which has no blocks and does
// not load Blockly.
Expand Down Expand Up @@ -151,7 +149,7 @@ Code.changeLanguage = function() {
* @param {!Element|string} el Button element or ID thereof.
* @param {!Function} func Event handler to bind.
*/
Code.bindClick = function(el, func) {
Code.bindClick = function (el, func) {
if (typeof el == 'string') {
el = document.getElementById(el);
}
Expand All @@ -163,7 +161,7 @@ Code.bindClick = function(el, func) {
/**
* Load the Prettify CSS and JavaScript.
*/
Code.importPrettify = function() {
Code.importPrettify = function () {
//<link rel="stylesheet" href="../prettify.css">
//<script src="../prettify.js"></script>
var link = document.createElement('link');
Expand All @@ -181,7 +179,7 @@ Code.importPrettify = function() {
* @return {!Object} Contains height, width, x, and y properties.
* @private
*/
Code.getBBox_ = function(element) {
Code.getBBox_ = function (element) {
var height = element.offsetHeight;
var width = element.offsetWidth;
var x = 0;
Expand Down Expand Up @@ -217,7 +215,7 @@ Code.selected = 'blocks';
* Switch the visible pane when a tab is clicked.
* @param {string} clickedName Name of tab clicked.
*/
Code.tabClick = function(clickedName) {
Code.tabClick = function (clickedName) {
// If the XML tab was open, save and render the content.
if (document.getElementById('tab_xml').className == 'tabon') {
var xmlTextarea = document.getElementById('content_xml');
Expand All @@ -235,7 +233,7 @@ Code.tabClick = function(clickedName) {
}
if (xmlDom) {
Code.workspace.clear();
Blockly.Xml.domToWorkspace(Code.workspace, xmlDom);
Blockly.Xml.domToWorkspace(xmlDom, Code.workspace);
}
}

Expand All @@ -259,13 +257,13 @@ Code.tabClick = function(clickedName) {
if (clickedName == 'blocks') {
Code.workspace.setVisible(true);
}
Blockly.fireUiEvent(window, 'resize');
Blockly.svgResize(Code.workspace);
};

/**
* Populate the currently selected pane with content generated from the blocks.
*/
Code.renderContent = function() {
Code.renderContent = function () {
var code;
var content = document.getElementById('content_' + Code.selected);
// Initialize the pane.
Expand Down Expand Up @@ -313,12 +311,12 @@ Code.renderContent = function() {
/**
* Initialize Blockly. Called on page load.
*/
Code.init = function() {
Code.init = function () {
Code.initLanguage();

var rtl = Code.isRtl();
var container = document.getElementById('content_area');
var onresize = function(e) {
var onresize = function (e) {
var bBox = Code.getBBox_(container);
for (var i = 0; i < Code.TABS_.length; i++) {
var el = document.getElementById('content_' + Code.TABS_[i]);
Expand All @@ -338,7 +336,7 @@ Code.init = function() {
// Account for the 19 pixel margin and on each side.
}
};
onresize();

window.addEventListener('resize', onresize, false);

var toolbox = document.getElementById('toolbox');
Expand Down Expand Up @@ -372,13 +370,13 @@ Code.init = function() {
Code.tabClick(Code.selected);

Code.bindClick('trashButton',
function() {
function () {
Code.discard();
Code.renderContent();
});

Code.bindClick('deployButton', function() {
var jscode = Blockly.JavaScript.workspaceToCode();
Code.bindClick('deployButton', function () {
var jscode = Blockly.JavaScript.workspaceToCode(Code.workspace);
var titleRegexp = /command. '(.+)',/;
var fname = titleRegexp.exec(jscode); //extract the name of the command
if (fname === null) {
Expand All @@ -392,7 +390,7 @@ Code.init = function() {
// code for IE6, IE5
xhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xhttp.onreadystatechange = function() {
xhttp.onreadystatechange = function () {
if (xhttp.readyState == 4 && xhttp.status == 200) {
alert(Blockly.Msg.DEPLOY_SUCCESS);
}
Expand All @@ -409,7 +407,7 @@ Code.init = function() {
BlocklyStorage.HASH_ERROR = MSG.hashError;
BlocklyStorage.XML_ERROR = MSG.xmlError;
Code.bindClick(linkButton,
function() {
function () {
BlocklyStorage.link(Code.workspace);
});
} else if (linkButton) {
Expand All @@ -419,13 +417,14 @@ Code.init = function() {
for (var i = 0; i < Code.TABS_.length; i++) {
var name = Code.TABS_[i];
Code.bindClick('tab_' + name,
function(name_) {
return function() {
function (name_) {
return function () {
Code.tabClick(name_);
};
}(name));
} (name));
}

onresize();
Blockly.svgResize(Code.workspace);
// Lazy-load the syntax-highlighting.
window.setTimeout(Code.importPrettify, 1);
};
Expand All @@ -434,7 +433,7 @@ Code.init = function() {
/**
* Initialize the page language.
*/
Code.initLanguage = function() {
Code.initLanguage = function () {
// Set the HTML's language and direction.
var lang;
var rtl = Code.isRtl();
Expand All @@ -446,7 +445,7 @@ Code.initLanguage = function() {
for (lang in Code.LANGUAGE_NAME) {
languages.push([Code.LANGUAGE_NAME[lang], lang]);
}
var comp = function(a, b) {
var comp = function (a, b) {
// Sort based on first argument ('English', 'Русский', '简体字', etc).
if (a[0] > b[0]) return 1;
if (a[0] < b[0]) return -1;
Expand Down Expand Up @@ -495,7 +494,7 @@ Code.initLanguage = function() {
/**
* Discard all blocks from the workspace.
*/
Code.discard = function() {
Code.discard = function () {
var count = Code.workspace.getAllBlocks().length;
if (count < 2 ||
window.confirm(Blockly.Msg.DELETE_ALL_BLOCKS.replace('%1', count))) {
Expand Down
24 changes: 12 additions & 12 deletions src/main/js/www/customblocks-javascript-generator.js
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Contains the generator for the javascript used in scriptcraft
***/

Blockly.JavaScript['drone'] = function(block) {
Blockly.JavaScript['drone'] = function (block) {
var fname = block.getFieldValue('param');
var statements_statements = Blockly.JavaScript.statementToCode(block, 'statements');
var code = "command( '" + fname + "', function ( parameters, player ) {\nvar theDrone = new Drone(player);\ntheDrone.up();\ntheDrone.chkpt('start');\n";
Expand All @@ -16,25 +16,25 @@ Blockly.JavaScript['drone'] = function(block) {
return code;
};

Blockly.JavaScript['drone_move'] = function(block) {
Blockly.JavaScript['drone_move'] = function (block) {
var dropdown_direction = block.getFieldValue('direction');
var code = "theDrone." + dropdown_direction + ";\n";
return code;
};

Blockly.JavaScript['materials'] = function(block) {
Blockly.JavaScript['materials'] = function (block) {
var dropdown_material = block.getFieldValue('material');
var code = "theDrone." + 'box(' + dropdown_material + ');\n';
return code;
};

Blockly.JavaScript['animals'] = function(block) {
Blockly.JavaScript['animals'] = function (block) {
var dropdown_animal = block.getFieldValue('animal');
var code = "if (__plugin.bukkit) {\n theDrone.getLocation().world.spawnEntity(theDrone.getLocation(), org.bukkit.entity.EntityType." + dropdown_animal + ");\n }\n if (__plugin.canary) {\n var Canary = Packages.net.canarymod.Canary,\n entityInstance = Canary.factory().entityFactory.newEntity('" + dropdown_animal + "', theDrone.getLocation());\n entityInstance.spawn();\n }";
return code;
};

Blockly.JavaScript['rectangle'] = function(block) {
Blockly.JavaScript['rectangle'] = function (block) {
var value_width = Blockly.JavaScript.valueToCode(block, 'width', Blockly.JavaScript.ORDER_ATOMIC);
var value_lenght = Blockly.JavaScript.valueToCode(block, 'lenght', Blockly.JavaScript.ORDER_ATOMIC);
var dropdown_material = block.getFieldValue('material');
Expand All @@ -43,23 +43,23 @@ Blockly.JavaScript['rectangle'] = function(block) {
return code;
};

Blockly.JavaScript['circle'] = function(block) {
Blockly.JavaScript['circle'] = function (block) {
var value_radius = Blockly.JavaScript.valueToCode(block, 'radius', Blockly.JavaScript.ORDER_ATOMIC);
var dropdown_material = block.getFieldValue('material');
var dropdown_fill = block.getFieldValue('fill');
var code = "theDrone.cylinder" + dropdown_fill + "(" + dropdown_material + "," + value_radius + ",1);\n";
return code;
};

Blockly.JavaScript['delete'] = function(block) {
Blockly.JavaScript['delete'] = function (block) {
var value_width = Blockly.JavaScript.valueToCode(block, 'width', Blockly.JavaScript.ORDER_ATOMIC);
var value_height = Blockly.JavaScript.valueToCode(block, 'height', Blockly.JavaScript.ORDER_ATOMIC);
var value_lenght = Blockly.JavaScript.valueToCode(block, 'lenght', Blockly.JavaScript.ORDER_ATOMIC);
var code = "theDrone.box(0," + value_width + "," + value_height + "," + value_lenght + ");\n";
return code;
};

Blockly.JavaScript['inventory'] = function(block) {
Blockly.JavaScript['inventory'] = function (block) {
var fname = block.getFieldValue('param');
var statements_statements = Blockly.JavaScript.statementToCode(block, 'statements');
var code = "var inventory = require('inventory');\nvar items = require('items');\ncommand( '" + fname + "', function ( parameters, player ) {\nvar theInventory = new inventory(player);\n";
Expand All @@ -69,26 +69,26 @@ Blockly.JavaScript['inventory'] = function(block) {
return code;
};

Blockly.JavaScript['weapons_armor'] = function(block) {
Blockly.JavaScript['weapons_armor'] = function (block) {
var dropdown_item = block.getFieldValue('item');
var code = "theInventory.add(items." + dropdown_item + "(1))" + ";\n";
return code;
};


Blockly.JavaScript['tools'] = function(block) {
Blockly.JavaScript['tools'] = function (block) {
var dropdown_item = block.getFieldValue('item');
var code = "theInventory.add(items." + dropdown_item + "(1))" + ";\n";
return code;
};

Blockly.JavaScript['food'] = function(block) {
Blockly.JavaScript['food'] = function (block) {
var dropdown_item = block.getFieldValue('item');
var code = "theInventory.add(items." + dropdown_item + "(1))" + ";\n";
return code;
};

Blockly.JavaScript['transportation'] = function(block) {
Blockly.JavaScript['transportation'] = function (block) {
var dropdown_item = block.getFieldValue('item');
var code = "theInventory.add(items." + dropdown_item + "(1))" + ";\n";
return code;
Expand Down
Empty file modified src/main/js/www/customblocks.js
100755 → 100644
Empty file.
Empty file modified src/main/js/www/favicon.ico
100755 → 100644
Empty file.
Empty file modified src/main/js/www/index.html
100755 → 100644
Empty file.
8 changes: 4 additions & 4 deletions src/main/js/www/msg/js/en.js
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,9 @@ Blockly.Msg.OBJNAMES[39] = "mushroom brown";
Blockly.Msg.OBJNAMES[40] = "mushroom red";
Blockly.Msg.OBJNAMES[41] = "gold";
Blockly.Msg.OBJNAMES[42] = "iron";
Blockly.Msg.OBJNAMES[43] = "double slab stone";
Blockly.Msg.OBJNAMES[44] = "slab stone";
Blockly.Msg.OBJNAMES[45] = "brick red";
Blockly.Msg.OBJNAMES[46] = "tnt";
Blockly.Msg.OBJNAMES[47] = "bookshelf";
Blockly.Msg.OBJNAMES[48] = "moss stone";
Expand Down Expand Up @@ -200,6 +203,7 @@ Blockly.Msg.OBJNAMES[74] = "redstone ore glowing";
Blockly.Msg.OBJNAMES[75] = "torch redstone";
Blockly.Msg.OBJNAMES[76] = "torch redstone active";
Blockly.Msg.OBJNAMES[77] = "stone button";
Blockly.Msg.OBJNAMES[78] = "slab snow";
Blockly.Msg.OBJNAMES[79] = "ice";
Blockly.Msg.OBJNAMES[80] = "snow";
Blockly.Msg.OBJNAMES[81] = "cactus";
Expand All @@ -220,7 +224,6 @@ Blockly.Msg.OBJNAMES[95] = "stained glass white";
Blockly.Msg.OBJNAMES[96] = "trapdoor";
Blockly.Msg.OBJNAMES[97] = "monster egg";
Blockly.Msg.OBJNAMES[98] = "brick stone";
Blockly.Msg.OBJNAMES[45] = "brick red";
Blockly.Msg.OBJNAMES[99] = "mushroom brown huge";
Blockly.Msg.OBJNAMES[100] = "mushroom red huge";
Blockly.Msg.OBJNAMES[101] = "iron bars";
Expand All @@ -244,9 +247,6 @@ Blockly.Msg.OBJNAMES[121] = "endstone";
Blockly.Msg.OBJNAMES[122] = "dragon egg";
Blockly.Msg.OBJNAMES[123] = "redstone lamp";
Blockly.Msg.OBJNAMES[124] = "redstone lamp active";
Blockly.Msg.OBJNAMES[43] = "double slab stone";
Blockly.Msg.OBJNAMES[78] = "slab snow";
Blockly.Msg.OBJNAMES[44] = "slab stone";
Blockly.Msg.OBJNAMES[126] = "slab oak";
Blockly.Msg.OBJNAMES[127] = "cocoa";
Blockly.Msg.OBJNAMES[129] = "emerald ore";
Expand Down
Loading

0 comments on commit e3fac76

Please sign in to comment.