diff --git a/TestProject/turtle example 1.ccp b/TestProject/turtle example 1.ccp
index 5e5bd04..1d25584 100644
--- a/TestProject/turtle example 1.ccp
+++ b/TestProject/turtle example 1.ccp
@@ -1 +1 @@
-{"usedlibrary":["IDE"],"content":{"blocks":{"languageVersion":0,"blocks":[{"type":"sys_start","id":"o[Cw/cGpoIP_gX=[qr#;","x":330,"y":210,"inputs":{"DO":{"block":{"type":"ide_addcode","id":"4rulxmAG~hzUkD5l(5yF","inputs":{"CODE":{"block":{"type":"text","id":"(o[.P`~(.T7p_[l_^Hl#","fields":{"TEXT":"turtle.refuel()"}}}},"next":{"block":{"type":"ide_addcode","id":"/5%!yEWtyS/E=wR/m*Xm","inputs":{"CODE":{"block":{"type":"text","id":"%wbX8A-7RhI2ZgV=lFhV","fields":{"TEXT":"turtle.digDown()"}}}},"next":{"block":{"type":"ide_addcode","id":"*(^6fQ{j/V.kg,ho=|:N","inputs":{"CODE":{"block":{"type":"text","id":"7hY96DknnQ/t#Xq?Q`dz","fields":{"TEXT":"turtle.down()"}}}},"next":{"block":{"type":"controls_repeat_ext","id":"$%Y?,,|7H1k$t+Jn)I}r","inputs":{"TIMES":{"shadow":{"type":"math_number","id":"s.U14p%aW!FTHv{Re%tn","fields":{"NUM":10}}},"DO":{"block":{"type":"ide_addcode","id":"]{qn$;Fr@4:nCTC%VK@d","inputs":{"CODE":{"block":{"type":"text","id":"*h}KRP|Z|Z8~bz+}Lb|S","fields":{"TEXT":"turtle.forward()"}}}},"next":{"block":{"type":"ide_addcode","id":"4*u|eIRv$3l8gVAe-#G6","inputs":{"CODE":{"block":{"type":"text","id":"vJr{;31CY5XLpno1G1l`","fields":{"TEXT":"turtle.dig()"}}}}}}}}},"next":{"block":{"type":"ide_addcode","id":"MYaWPpTW,*Sbr$qHdP;X","inputs":{"CODE":{"block":{"type":"text","id":"4yq!yCVpT7zAkbgx|e}?","fields":{"TEXT":"turtle.up()"}}}},"next":{"block":{"type":"ide_addcode","id":"}oNps@eRjo{j6Mt*y[M(","inputs":{"CODE":{"block":{"type":"text","id":"Pp6jDe[JkcY^`5J3FtzJ","fields":{"TEXT":"turtle.forward()"}}}},"next":{"block":{"type":"ide_addcode","id":"GBsH+H_G).Or7Jg#Z/HM","inputs":{"CODE":{"block":{"type":"text","id":"I39UB3G^1g|#PXmIK~/8","fields":{"TEXT":"turtle.forward()"}}}}}}}}}}}}}}}}}}}}]},"variables":[{"name":"fuellevel","id":"v3Vu$~B8ol()F*#n?^)B"}]}}
\ No newline at end of file
+{"usedlibrary":["IDE"],"content":{"blocks":{"languageVersion":0,"blocks":[{"type":"ide_start","id":"o[Cw/cGpoIP_gX=[qr#;","x":330,"y":210,"inputs":{"DO":{"block":{"type":"ide_addcode","id":"4rulxmAG~hzUkD5l(5yF","inputs":{"CODE":{"block":{"type":"text","id":"(o[.P`~(.T7p_[l_^Hl#","fields":{"TEXT":"turtle.refuel()"}}}},"next":{"block":{"type":"ide_addcode","id":"/5%!yEWtyS/E=wR/m*Xm","inputs":{"CODE":{"block":{"type":"text","id":"%wbX8A-7RhI2ZgV=lFhV","fields":{"TEXT":"turtle.digDown(\"left\")"}}}},"next":{"block":{"type":"ide_addcode","id":"*(^6fQ{j/V.kg,ho=|:N","inputs":{"CODE":{"block":{"type":"text","id":"7hY96DknnQ/t#Xq?Q`dz","fields":{"TEXT":"turtle.down()"}}}},"next":{"block":{"type":"controls_repeat_ext","id":"$%Y?,,|7H1k$t+Jn)I}r","inputs":{"TIMES":{"shadow":{"type":"math_number","id":"s.U14p%aW!FTHv{Re%tn","fields":{"NUM":10}}},"DO":{"block":{"type":"ide_addcode","id":"]{qn$;Fr@4:nCTC%VK@d","inputs":{"CODE":{"block":{"type":"text","id":"*h}KRP|Z|Z8~bz+}Lb|S","fields":{"TEXT":"turtle.forward()"}}}},"next":{"block":{"type":"ide_addcode","id":"4*u|eIRv$3l8gVAe-#G6","inputs":{"CODE":{"block":{"type":"text","id":"vJr{;31CY5XLpno1G1l`","fields":{"TEXT":"turtle.dig(\"left\")"}}}}}}}}},"next":{"block":{"type":"ide_addcode","id":"MYaWPpTW,*Sbr$qHdP;X","inputs":{"CODE":{"block":{"type":"text","id":"4yq!yCVpT7zAkbgx|e}?","fields":{"TEXT":"turtle.up()"}}}},"next":{"block":{"type":"ide_addcode","id":"}oNps@eRjo{j6Mt*y[M(","inputs":{"CODE":{"block":{"type":"text","id":"Pp6jDe[JkcY^`5J3FtzJ","fields":{"TEXT":"turtle.forward()"}}}},"next":{"block":{"type":"ide_addcode","id":"GBsH+H_G).Or7Jg#Z/HM","inputs":{"CODE":{"block":{"type":"text","id":"I39UB3G^1g|#PXmIK~/8","fields":{"TEXT":"turtle.forward()"}}}}}}}}}}}}}}}}}}}}]},"variables":[{"name":"fuellevel","id":"v3Vu$~B8ol()F*#n?^)B"}]}}
\ No newline at end of file
diff --git a/blocks/CCTurtle/block_design.json b/blocks/CCTurtle/block_design.json
new file mode 100644
index 0000000..00a3a49
--- /dev/null
+++ b/blocks/CCTurtle/block_design.json
@@ -0,0 +1,383 @@
+{
+ "turtle_move_operation": {
+ "message0": "Move %1 for %2 blocks",
+ "args0": [
+ {
+ "type": "field_dropdown",
+ "name": "OPERATION",
+ "options": [
+ ["Forward", "FORWARD"],
+ ["Back", "BACK"],
+ ["Up", "UP"],
+ ["Down", "DOWN"]
+ ]
+ },
+ {
+ "type": "input_value",
+ "name": "FOR",
+ "check": "Number"
+ }
+ ],
+ "inputsInline": true,
+ "previousStatement": null,
+ "nextStatement": null,
+ "colour": 215,
+ "tooltip": "Move the turtle."
+ },
+ "turtle_turn_operation": {
+ "message0": "Turn %1 for %2 round",
+ "args0": [
+ {
+ "type": "field_dropdown",
+ "name": "OPERATION",
+ "options": [
+ ["Left", "LEFT"],
+ ["Right", "RIGHT"]
+ ]
+ },
+ {
+ "type": "input_value",
+ "name": "ROUND",
+ "check": "Number"
+ }
+ ],
+ "inputsInline": true,
+ "previousStatement": null,
+ "nextStatement": null,
+ "colour": 215,
+ "tooltip": "Turn the turtle."
+ },
+ "turtle_dig_operation": {
+ "message0": "Dig in %1 of turtle with %2 side",
+ "args0": [
+ {
+ "type": "field_dropdown",
+ "name": "OPERATION",
+ "options": [
+ ["Front", "FRONT"],
+ ["Up", "UP"],
+ ["Down", "DOWN"]
+ ]
+ },
+ {
+ "type": "field_dropdown",
+ "name": "SIDE",
+ "options": [
+ ["Left", "LEFT"],
+ ["Right", "RIGHT"]
+ ]
+ }
+ ],
+ "inputsInline": true,
+ "previousStatement": null,
+ "nextStatement": null,
+ "colour": 215,
+ "tooltip": "Attempt to break the block in direction of the turtle."
+ },
+ "turtle_attack_operation": {
+ "message0": "Attack in %1 of turtle with %2 side",
+ "args0": [
+ {
+ "type": "field_dropdown",
+ "name": "OPERATION",
+ "options": [
+ ["Front", "FRONT"],
+ ["Up", "UP"],
+ ["Down", "DOWN"]
+ ]
+ },
+ {
+ "type": "field_dropdown",
+ "name": "SIDE",
+ "options": [
+ ["Left", "LEFT"],
+ ["Right", "RIGHT"]
+ ]
+ }
+ ],
+ "inputsInline": true,
+ "previousStatement": null,
+ "nextStatement": null,
+ "colour": 215,
+ "tooltip": "Attack the entity in direction of the turtle."
+ },
+ "turtle_place_operation": {
+ "message0": "Use/Place in %1 of turtle",
+ "args0": [
+ {
+ "type": "field_dropdown",
+ "name": "OPERATION",
+ "options": [
+ ["Front", "FRONT"],
+ ["Up", "UP"],
+ ["Down", "DOWN"]
+ ]
+ }
+ ],
+ "inputsInline": true,
+ "previousStatement": null,
+ "nextStatement": null,
+ "colour": 215,
+ "tooltip": "Place a block or item into the world in direction of the turtle."
+ },
+ "turtle_drop_operation": {
+ "message0": "Drop item in %1 of turtle for %2 items",
+ "args0": [
+ {
+ "type": "field_dropdown",
+ "name": "OPERATION",
+ "options": [
+ ["Front", "FRONT"],
+ ["Up", "UP"],
+ ["Down", "DOWN"]
+ ]
+ },
+ {
+ "type": "input_value",
+ "name": "COUNT",
+ "check": "Number"
+ }
+ ],
+ "inputsInline": true,
+ "previousStatement": null,
+ "nextStatement": null,
+ "colour": 215,
+ "tooltip": "Drop the currently selected stack into the inventory in the turtle, or as an item into the world if there is no inventory."
+ },
+ "turtle_select_item": {
+ "message0": "Select item in slot %1",
+ "args0": [
+ {
+ "type": "input_value",
+ "name": "SLOT",
+ "check": "Number"
+ }
+ ],
+ "inputsInline": true,
+ "previousStatement": null,
+ "nextStatement": null,
+ "colour": 215,
+ "tooltip": "Change the currently selected slot."
+ },
+ "turtle_get_item_count": {
+ "message0": "Get item count in slot %1",
+ "args0": [
+ {
+ "type": "input_value",
+ "name": "SLOT",
+ "check": "Number"
+ }
+ ],
+ "inputsInline": true,
+ "output": "Number",
+ "colour": 215,
+ "tooltip": "Get the number of items in the given slot."
+ },
+ "turtle_get_slot_free": {
+ "message0": "Get free space in slot %1",
+ "args0": [
+ {
+ "type": "input_value",
+ "name": "SLOT",
+ "check": "Number"
+ }
+ ],
+ "inputsInline": true,
+ "output": "Number",
+ "colour": 215,
+ "tooltip": "Get the remaining number of items which may be stored in this stack."
+ },
+ "turtle_detect_block": {
+ "message0": "Detect solid block in %1 of turtle",
+ "args0": [
+ {
+ "type": "field_dropdown",
+ "name": "OPERATION",
+ "options": [
+ ["Front", "FRONT"],
+ ["Up", "UP"],
+ ["Down", "DOWN"]
+ ]
+ }
+ ],
+ "inputsInline": true,
+ "output": "Boolean",
+ "colour": 215,
+ "tooltip": "Check if there is a solid block in direction of the turtle."
+ },
+ "turtle_compare_item": {
+ "message0": "Compare block in %1 of turtle is equal current item slot",
+ "args0": [
+ {
+ "type": "field_dropdown",
+ "name": "OPERATION",
+ "options": [
+ ["Front", "FRONT"],
+ ["Up", "UP"],
+ ["Down", "DOWN"]
+ ]
+ }
+ ],
+ "inputsInline": true,
+ "output": "Boolean",
+ "colour": 215,
+ "tooltip": "Check if the block in direction of the turtle is equal to the item in the currently selected slot."
+ },
+ "turtle_collect_item": {
+ "message0": "Collect %1 items in %2 of turtle",
+ "args0": [
+ {
+ "type": "input_value",
+ "name": "COUNT",
+ "check": "Number"
+ },
+ {
+ "type": "field_dropdown",
+ "name": "OPERATION",
+ "options": [
+ ["Front", "FRONT"],
+ ["Up", "UP"],
+ ["Down", "DOWN"]
+ ]
+ }
+ ],
+ "inputsInline": true,
+ "previousStatement": null,
+ "nextStatement": null,
+ "colour": 215,
+ "tooltip": "Collect an item from the inventory in direction of the turtle, or from an item floating in the world. If count is 0 it collect all item."
+ },
+ "turtle_get_fuel_level": {
+ "message0": "Get current fuel level",
+ "inputsInline": true,
+ "output": "Number",
+ "colour": 215,
+ "tooltip": "Get the maximum amount of fuel this turtle currently holds."
+ },
+ "turtle_refuel": {
+ "message0": "Refuel turtle for %1",
+ "args0": [
+ {
+ "type": "input_value",
+ "name": "COUNT",
+ "check": "Number"
+ }
+ ],
+ "inputsInline": true,
+ "previousStatement": null,
+ "nextStatement": null,
+ "colour": 215,
+ "tooltip": "Refuel this turtle. If 0 it refuel unlimit from current item."
+ },
+ "turtle_compare_to": {
+ "message0": "Compare item to slot %1",
+ "args0": [
+ {
+ "type": "input_value",
+ "name": "SLOT",
+ "check": "Number"
+ }
+ ],
+ "inputsInline": true,
+ "output": "Boolean",
+ "colour": 215,
+ "tooltip": "Compare the item in the currently selected slot to the item in another slot."
+ },
+ "turtle_transfer_to": {
+ "message0": "Transfer item to slot %1 for %2 items",
+ "args0": [
+ {
+ "type": "input_value",
+ "name": "SLOT",
+ "check": "Number"
+ },
+ {
+ "type": "input_value",
+ "name": "COUNT",
+ "check": "Number"
+ }
+ ],
+ "inputsInline": true,
+ "previousStatement": null,
+ "nextStatement": null,
+ "colour": 215,
+ "tooltip": "Move an item from the selected slot to another one."
+ },
+ "turtle_get_selected_slot": {
+ "message0": "Get current selected slot",
+ "inputsInline": true,
+ "output": "Number",
+ "colour": 215,
+ "tooltip": "Get the currently selected slot."
+ },
+ "turtle_get_fuel_limit": {
+ "message0": "Get fuel limit",
+ "inputsInline": true,
+ "output": "Number",
+ "colour": 215,
+ "tooltip": "Get the maximum amount of fuel this turtle can hold."
+ },
+ "turtle_equip": {
+ "message0": "Equip item on %1 side",
+ "args0": [
+ {
+ "type": "field_dropdown",
+ "name": "SIDE",
+ "options": [
+ ["Left", "LEFT"],
+ ["Right", "RIGHT"]
+ ]
+ }
+ ],
+ "inputsInline": true,
+ "output": "Multiple",
+ "colour": 215,
+ "tooltip": "Equip (or unequip) an item on the side of this turtle."
+ },
+ "turtle_inspect": {
+ "message0": "Inspect block on %1 side",
+ "args0": [
+ {
+ "type": "field_dropdown",
+ "name": "OPERATION",
+ "options": [
+ ["Front", "FRONT"],
+ ["Up", "UP"],
+ ["Down", "DOWN"]
+ ]
+ }
+ ],
+ "inputsInline": true,
+ "output": "Multiple",
+ "colour": 215,
+ "tooltip": "Get information about the block in direction of the turtle."
+ },
+ "turtle_get_item_detail": {
+ "message0": "Get Item detail in slot %1",
+ "args0": [
+ {
+ "type": "input_value",
+ "name": "SLOT",
+ "check": "Number"
+ }
+ ],
+ "inputsInline": true,
+ "output": "Array",
+ "colour": 215,
+ "tooltip": "Get detailed information about the items in the given slot."
+ },
+ "turtle_craft": {
+ "message0": "Craft Item with limit %1",
+ "args0": [
+ {
+ "type": "input_value",
+ "name": "LIMIT",
+ "check": "Number"
+ }
+ ],
+ "inputsInline": true,
+ "output": "Multiple",
+ "colour": 215,
+ "tooltip": "Craft a recipe based on the turtle's inventory."
+ }
+}
\ No newline at end of file
diff --git a/blocks/CCTurtle/generator.js b/blocks/CCTurtle/generator.js
new file mode 100644
index 0000000..6cfab87
--- /dev/null
+++ b/blocks/CCTurtle/generator.js
@@ -0,0 +1,58 @@
+const { luaGenerator } = require('blockly/lua');
+
+// Check if luaGenerator.forBlock is defined and initialize if necessary
+if (!luaGenerator.forBlock) {
+ luaGenerator.forBlock = {};
+}
+
+// Math operation block
+luaGenerator.forBlock['math_operation'] = function(block, generator) {
+ var operator = block.getFieldValue('OPERATOR');
+ var num1 = generator.valueToCode(block, 'NUM1', generator.ORDER_ATOMIC);
+ var num2 = generator.valueToCode(block, 'NUM2', generator.ORDER_ATOMIC);
+
+ var operatorSymbol = '';
+ switch (operator) {
+ case 'ADD':
+ operatorSymbol = '+';
+ break;
+ case 'SUBTRACT':
+ operatorSymbol = '-';
+ break;
+ case 'MULTIPLY':
+ operatorSymbol = '*';
+ break;
+ case 'DIVIDE':
+ operatorSymbol = '/';
+ break;
+ default:
+ operatorSymbol = '+';
+ break;
+ }
+
+ var code = `${num1} ${operatorSymbol} ${num2}`;
+ return [code, generator.ORDER_ATOMIC];
+};
+
+// Print text block
+luaGenerator.forBlock['text_print'] = function(block, generator) {
+ var text = generator.valueToCode(block, 'TEXT', generator.ORDER_NONE) || '\'\'';
+ var code = `print(${text})\n`;
+ return code;
+};
+
+// If condition block
+luaGenerator.forBlock['controls_if'] = function(block, generator) {
+ var condition = generator.valueToCode(block, 'IF0', generator.ORDER_NONE) || 'false';
+ var branch = generator.statementToCode(block, 'DO0');
+ var code = `if ${condition} then\n${branch}\nend\n`;
+ return code;
+};
+
+// Set variable block
+luaGenerator.forBlock['variables_set'] = function(block, generator) {
+ var variable = generator.nameDB_.getName(block.getFieldValue('VAR'), Blockly.Variables.NAME_TYPE);
+ var value = generator.valueToCode(block, 'VALUE', generator.ORDER_NONE) || '0';
+ var code = `${variable} = ${value}\n`;
+ return code;
+};
diff --git a/blocks/CCTurtle/index.json b/blocks/CCTurtle/index.json
new file mode 100644
index 0000000..92d0511
--- /dev/null
+++ b/blocks/CCTurtle/index.json
@@ -0,0 +1,22 @@
+{
+ "name": "CC: Turtle",
+ "author": "DPSoftware Foundation",
+ "description": "Library for control turtle",
+ "version": "0.1",
+ "category": "turtle",
+ "keyword": "turtle",
+ "license": "GPL-3.0-or-later",
+ "peripherals": false,
+ "library": true,
+ "require_network": false,
+ "dependencies": {},
+ "design_for_computer": {
+ "basic": false,
+ "adv": false,
+ "command": false,
+ "pocket": false,
+ "advpocket": false,
+ "turtle": true,
+ "advturtle": true
+ }
+}
diff --git a/blocks/CCTurtle/toolbox.xml b/blocks/CCTurtle/toolbox.xml
new file mode 100644
index 0000000..10db08b
--- /dev/null
+++ b/blocks/CCTurtle/toolbox.xml
@@ -0,0 +1,97 @@
+
+
+
+
+
+ 1
+
+
+
+
+
+
+ 1
+
+
+
+
+
+
+
+
+
+ 1
+
+
+
+
+
+
+ 1
+
+
+
+
+
+
+ 1
+
+
+
+
+
+
+ 1
+
+
+
+
+
+
+
+
+ 0
+
+
+
+
+
+
+
+ 0
+
+
+
+
+
+
+ 1
+
+
+
+
+
+
+ 1
+
+
+
+
+ 64
+
+
+
+
+
+
+
+
+
+
+
+ 64
+
+
+
+
+
\ No newline at end of file
diff --git a/blocks/IDE/block_design.json b/blocks/IDE/block_design.json
index 3c538d2..4cb8834 100644
--- a/blocks/IDE/block_design.json
+++ b/blocks/IDE/block_design.json
@@ -13,5 +13,14 @@
"colour": 150,
"tooltip": "Add Code for some code is not in IDE",
"helpUrl": ""
+ },
+ "ide_start": {
+ "message0": "When Code Start",
+ "message1": "do %1",
+ "args1": [
+ {"type": "input_statement", "name": "DO"}
+ ],
+ "colour": 150,
+ "tooltip": "Not require but make your code easy to read."
}
}
diff --git a/blocks/IDE/generator.js b/blocks/IDE/generator.js
index 4266691..f26725d 100644
--- a/blocks/IDE/generator.js
+++ b/blocks/IDE/generator.js
@@ -13,3 +13,17 @@ luaGenerator.forBlock['ide_addcode'] = function(block, generator) {
const cleanedStr = codefromuser.replace(/[']/g, '');
return cleanedStr+"\n";
};
+
+luaGenerator.forBlock['ide_start'] = function(block, generator) {
+ var docode = generator.statementToCode(block, 'DO');
+
+ var code =
+`
+function main()
+${docode}
+end
+
+main()
+`
+ return code;
+};
\ No newline at end of file
diff --git a/blocks/IDE/toolbox.xml b/blocks/IDE/toolbox.xml
index 8055198..7ba83e4 100644
--- a/blocks/IDE/toolbox.xml
+++ b/blocks/IDE/toolbox.xml
@@ -2,5 +2,6 @@
+
\ No newline at end of file
diff --git a/ccIDE Defines.xlsx b/ccIDE Defines.xlsx
index 4e96e61..50bfe4d 100644
Binary files a/ccIDE Defines.xlsx and b/ccIDE Defines.xlsx differ
diff --git a/index.js b/index.js
index 78b24f9..9027828 100644
--- a/index.js
+++ b/index.js
@@ -208,6 +208,19 @@ app.whenReady().then(() => {
}
},
{ type: 'separator' },
+ {
+ label: 'Export',
+ submenu: [
+ {
+ label: "Export Lua",
+ accelerator: 'CmdOrCtrl+Shift+L',
+ click: () => {
+ win.webContents.send('export-lua-request');
+ }
+ }
+ ]
+ },
+ { type: 'separator' },
{
label: 'Exit',
accelerator: 'CmdOrCtrl+Q',
@@ -373,6 +386,28 @@ app.whenReady().then(() => {
}
});
+ ipc.on('export-lua', (event, data) => {
+ dialog.showSaveDialog(win, {
+ title: 'Save Project',
+ defaultPath: path.join(app.getPath('documents'), 'main.lua'),
+ filters: [
+ { extensions: ['lua'] }
+ ]
+ }).then(result => {
+ if (!result.canceled) {
+ fs.writeFile(result.filePath, data, (err) => {
+ if (err) {
+ console.error('Error exporting lua from project:', err);
+ dialog.showErrorBox("Export Lua Error", err.message)
+ }
+ });
+ }
+ }).catch(err => {
+ console.error('Error exporting lua from project:', err);
+ dialog.showErrorBox("Export Lua Error", err.message)
+ });
+ });
+
ipc.on('workspace-notsave', (event) => {
win.setTitle(`${currentprojectname}* | ccIDE`)
currentworkspacechange = true;
@@ -383,7 +418,6 @@ app.whenReady().then(() => {
})
-
app.on("close", function(e) {
console.log("Close event triggered");
if (currentprojectopen) {
diff --git a/src/ccRemote.js b/src/ccRemote.js
index 14c03a2..bd7be97 100644
--- a/src/ccRemote.js
+++ b/src/ccRemote.js
@@ -26,6 +26,15 @@ class CCRemote {
});
}
+ isClientConnect() {
+ for (const client of this.socket.clients) {
+ if (client.readyState === WebSocket.OPEN) {
+ return true;
+ }
+ }
+ return false;
+ }
+
sendCommand(command) {
// Iterate over each connected client and send the command
this.socket.clients.forEach((client) => {
@@ -41,7 +50,6 @@ class CCRemote {
if (client.readyState === WebSocket.OPEN) {
client.send("sendcode");
setTimeout(() => {
- console.log(Code)
client.send(Code);
return true
}, 500);
@@ -62,6 +70,14 @@ class CCRemote {
});
}
+ disconnectAllClients() {
+ this.socket.clients.forEach((client) => {
+ if (client.readyState === WebSocket.OPEN) {
+ client.close();
+ }
+ });
+ }
+
}
module.exports = { CCRemote };
diff --git a/src/codegen.js b/src/codegen.js
index 05d4d17..7bcb46b 100644
--- a/src/codegen.js
+++ b/src/codegen.js
@@ -38,7 +38,13 @@ const uploadUpdateProgress = () => {
function clientexit() {
ccInstance.sendCommand("exit")
+ ccInstance.disconnectAllClients();
}
+
+function gencodeonly() {
+ return luaGenerator.workspaceToCode(workspace);
+}
+
async function gencode() {
document.getElementById('upload-popup').style.display = 'block';
upcurrentActive = 1;
@@ -60,18 +66,25 @@ async function gencode() {
return
}
- // upload to computercraft with remote
- document.getElementById('upload-status').textContent = "Uploading code to machine";
upcurrentActive++;
uploadUpdateProgress();
- ccInstance.sendCode(code);
- await delay(500)
+ if (ccInstance.isClientConnect()) {
+ // upload to computercraft with remote
+ document.getElementById('upload-status').textContent = "Uploading code to machine";
+ ccInstance.sendCode(code);
+ await delay(500)
- // execute with remote
- document.getElementById('upload-status').textContent = "Executing code";
- upcurrentActive++;
- uploadUpdateProgress();
- ccInstance.runCode();
+ // execute with remote
+ document.getElementById('upload-status').textContent = "Executing code";
+ upcurrentActive++;
+ uploadUpdateProgress();
+ ccInstance.runCode();
+ } else {
+ uploadError = true;
+ uploadUpdateProgress();
+ document.getElementById('upload-status').innerHTML = `Please Connect Computer to IDE.\nInstruction: Install Remote code into computercraft in github.`;
+ return
+ }
// done!
document.getElementById('upload-status').textContent = "Done!";
diff --git a/src/module_block_design.json b/src/module_block_design.json
index fafcc30..b7cf57b 100644
--- a/src/module_block_design.json
+++ b/src/module_block_design.json
@@ -1,13 +1,4 @@
{
- "sys_start": {
- "message0": "When Code Start",
- "message1": "do %1",
- "args1": [
- {"type": "input_statement", "name": "DO"}
- ],
- "colour": 45,
- "tooltip": "Not require but make your code easy to read."
- },
"sys_sleep": {
"message0": "Sleep For %1 Second",
"args0": [
diff --git a/src/module_generator.js b/src/module_generator.js
index b3a615c..b06e8a3 100644
--- a/src/module_generator.js
+++ b/src/module_generator.js
@@ -11,18 +11,4 @@ luaGenerator.forBlock['sys_sleep'] = function(block, generator) {
var code = `sleep(${sleepfor})\n`;
return code;
-};
-
-luaGenerator.forBlock['sys_start'] = function(block, generator) {
- var docode = generator.statementToCode(block, 'DO');
-
- var code =
-`
-function main()
-${docode}
-end
-
-main()
-`
- return code;
};
\ No newline at end of file
diff --git a/src/toolbox.xml b/src/toolbox.xml
index 679bd82..16c3bff 100644
--- a/src/toolbox.xml
+++ b/src/toolbox.xml
@@ -46,7 +46,7 @@
-
+
diff --git a/src/virtualcode.js b/src/virtualcode.js
index 3d706ef..2fcb984 100644
--- a/src/virtualcode.js
+++ b/src/virtualcode.js
@@ -39,6 +39,15 @@ var workspace = Blockly.inject('blocklyDiv', {
length: 3,
colour: '#ccc',
snap: true
+ },
+ zoom:{
+ controls: true,
+ wheel: true,
+ startScale: 1.0,
+ maxScale: 5,
+ minScale: 0.1,
+ scaleSpeed: 1.1,
+ pinch: true
}
});
@@ -52,6 +61,10 @@ try {
}
workspace.getToolbox().getFlyout().autoClose = false;
+ipc.on('export-lua-request', (event) => {
+ console.log("exporting lua")
+ ipc.send('export-lua', gencodeonly());
+})
// Save workspace
ipc.on('save-workspace-request', (event) => {