From 9de6039f6b90a050abaaf4a64af297834b6d16ce Mon Sep 17 00:00:00 2001 From: Sarxzer Date: Tue, 19 Mar 2024 18:24:36 +0100 Subject: [PATCH] Update project for version 1.1.6 release This commit includes updates to several files in preparation for the version 1.1.6 release. The changes include updates to the Redstone and Rednet blocks, improvements to the Lua generator, and updates to the project dependencies in package.json. The UPDATE.md file has also been updated with the latest release notes. --- UPDATE.md | 11 + package-lock.json | 14 +- package.json | 2 +- src/blocks/computcraft.js | 414 ++++++++++++++++++++++++++++++++++++++ src/generators/lua.js | 165 +++++++++++++++ src/index.css | 4 +- src/index.html | 2 +- src/index.js | 2 +- src/toolbox.js | 270 +++++++++++++++++++++++++ 9 files changed, 869 insertions(+), 15 deletions(-) diff --git a/UPDATE.md b/UPDATE.md index 03a7189..4e488e6 100644 --- a/UPDATE.md +++ b/UPDATE.md @@ -1,5 +1,16 @@ # Release Notes +## Version 1.1.6 Update + +We're thrilled to announce the release of version 1.1.6 of the ComputerCraft : Blockly Editor. This update introduces a comprehensive set of Redstone and Rednet blocks, expanding the capabilities of your Lua scripts. + +### New Features +- **Redstone and Rednet Blocks**: This update adds a complete set of Redstone and Rednet blocks to the Blockly Editor. These new blocks allow you to interact with Redstone and the Rednet API, opening up physical and wireless interaction in your Minecraft world. + +**Full Changelog**: https://github.com/Sarxzer/cc-blockly-editor/compare/v1.1.5.1...v1.1.6 + +--- + ## Version 1.1.5.1 Update This minor update brings a significant improvement to the saving system of the ComputerCraft : Blockly Editor. diff --git a/package-lock.json b/package-lock.json index c00f4fa..7abbbc3 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { - "name": "hello-world", - "version": "1.0.0", + "name": "computer-craft-blockly-editor", + "version": "1.1.6", "lockfileVersion": 2, "requires": true, "packages": { "": { - "name": "cc-tweaked_blockly", - "version": "1.0.0", + "name": "computer-craft-blockly-editor", + "version": "1.1.6", "license": "Apache-2.0", "dependencies": { "@blockly/shadow-block-converter": "^5.0.1", @@ -4660,12 +4660,6 @@ "integrity": "sha512-f0sqogkEuwzOutCGnV2dD4rmEReaygFRktTrWl0dNkFbHmFteJBIHu6CixY6pBrP4skbzJqtzG+7iZn8vN6NBg==", "requires": {} }, - "@blockly/theme-dark": { - "version": "6.0.5", - "resolved": "https://registry.npmjs.org/@blockly/theme-dark/-/theme-dark-6.0.5.tgz", - "integrity": "sha512-6vftqOY4ZfwqiAUh2lR12TL16t+7UcmiGVYOBSs4dj1emP89UEO7EMaj0RQ+m0BsV9IHsf2fN6iKZu1gWkmnnA==", - "requires": {} - }, "@discoveryjs/json-ext": { "version": "0.5.7", "resolved": "https://registry.npmjs.org/@discoveryjs/json-ext/-/json-ext-0.5.7.tgz", diff --git a/package.json b/package.json index 040e8af..179eed1 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "computer-craft-blockly-editor", - "version": "1.1.4", + "version": "1.1.6", "description": "A Blockly editor for ComputerCraft", "main": "index.js", "private": true, diff --git a/src/blocks/computcraft.js b/src/blocks/computcraft.js index 2a120db..3b07c12 100644 --- a/src/blocks/computcraft.js +++ b/src/blocks/computcraft.js @@ -1569,6 +1569,393 @@ const per_find = { output: "String", }; +//Redstone + +const rs_getsides = { + type: "rs_getsides", + message0: "Get computer sides", + colour: 100, + tooltip: "Get all sides of the computer", + helpUrl: "", + output: "Array", +}; + +const rs_setoutput = { + type: "rs_setoutput", + message0: "Set signal on side %1 to %2", + args0: [ + { + type: "input_value", + name: "SIDE", + check: "String", + }, + { + type: "input_value", + name: "VALUE", + check: "Boolean", + }, + ], + previousStatement: null, + nextStatement: null, + inputsInline: true, + colour: 100, + tooltip: "Set the output on a side between on and off", + helpUrl: "", +}; + +const rs_getoutput = { + type: "rs_getoutput", + message0: "Get output signal on side %1", + args0: [ + { + type: "input_value", + name: "SIDE", + check: "String", + }, + ], + colour: 100, + tooltip: "Get the output on a side", + helpUrl: "", + output: "Boolean", +}; + +const rs_getinput = { + type: "rs_getinput", + message0: "Get input signal on side %1", + args0: [ + { + type: "input_value", + name: "SIDE", + check: "String", + }, + ], + colour: 100, + tooltip: "Get the input on a side", + helpUrl: "", + output: "Boolean", +}; + +const rs_setanalogoutput = { + type: "rs_setanalogoutput", + message0: "Set analog signal on side %1 to %2", + args0: [ + { + type: "input_value", + name: "SIDE", + check: "String", + }, + { + type: "input_value", + name: "VALUE", + check: "Number", + }, + ], + previousStatement: null, + nextStatement: null, + inputsInline: true, + colour: 100, + tooltip: "Set the analog output on a side to a value between 0 and 15", + helpUrl: "", +}; + +const rs_getanalogoutput = { + type: "rs_getanalogoutput", + message0: "Get analog output signal on side %1", + args0: [ + { + type: "input_value", + name: "SIDE", + check: "String", + }, + ], + colour: 100, + tooltip: "Get the analog output on a side", + helpUrl: "", + output: "Number", +}; + +const rs_getanaloginput = { + type: "rs_getanaloginput", + message0: "Get analog input signal on side %1", + args0: [ + { + type: "input_value", + name: "SIDE", + check: "String", + }, + ], + colour: 100, + tooltip: "Get the analog input on a side", + helpUrl: "", + output: "Number", +}; + + +// NEED TO DO BUNDLE + + +// Rednet + +const rn_chbroadcast = { + type: "rn_chbroadcast", + message0: "Change broadcast channel to %1", + args0: [ + { + type: "input_value", + name: "CHANNEL", + check: "Number", + }, + ], + previousStatement: null, + nextStatement: null, + colour: 100, + tooltip: "Set the channel used by the Rednet API to broadcast messages.", + helpUrl: "", +}; + +const rn_getchbroadcast = { + type: "rn_getchbroadcast", + message0: "Get broadcast channel", + colour: 100, + tooltip: "Get the channel used by the Rednet API to broadcast messages.", + helpUrl: "", + output: "Number", +}; + +const rn_chrepeat = { + type: "rn_chrepeat", + message0: "Change repeat channel to %1", + args0: [ + { + type: "input_value", + name: "CHANNEL", + check: "Number", + }, + ], + previousStatement: null, + nextStatement: null, + colour: 100, + tooltip: "Set the channel used by the Rednet API to repeat messages.", + helpUrl: "", +}; + +const rn_getchrepeat = { + type: "rn_getchrepeat", + message0: "Get repeat channel", + colour: 100, + tooltip: "Get the channel used by the Rednet API to repeat messages.", + helpUrl: "", + output: "Number", +}; + +const rn_chmaxid = { + type: "rn_chmaxid", + message0: "Change max id to %1", + args0: [ + { + type: "input_value", + name: "CHANNEL", + check: "Number", + }, + ], + previousStatement: null, + nextStatement: null, + colour: 100, + tooltip: "Set the number of channels rednet reserves for computer IDs.", + helpUrl: "", +}; + +const rn_getchmaxid = { + type: "rn_getchmaxid", + message0: "Get max id", + colour: 100, + tooltip: "Get the number of channels rednet reserves for computer IDs.", + helpUrl: "", + output: "Number", +}; + +const rn_open = { + type: "rn_open", + message0: "Open %1", + args0: [ + { + type: "input_value", + name: "SIDE", + check: "String", + }, + ], + previousStatement: null, + nextStatement: null, + colour: 100, + tooltip: "Open a rednet modem", + helpUrl: "", +}; + +const rn_close = { + type: "rn_close", + message0: "Close %1", + args0: [ + { + type: "input_value", + name: "SIDE", + check: "String", + }, + ], + previousStatement: null, + nextStatement: null, + colour: 100, + tooltip: "Close a rednet modem", + helpUrl: "", +}; + +const rn_isopen = { + type: "rn_isopen", + message0: "Is %1 open?", + args0: [ + { + type: "input_value", + name: "SIDE", + check: "String", + }, + ], + colour: 100, + tooltip: "Check whether a rednet modem is open", + helpUrl: "", + output: "Boolean", +}; + +const rn_send = { + type: "rn_send", + message0: "Send %1 to %2 with protocol %3 (optional)", + args0: [ + { + type: "input_value", + name: "MESSAGE", + check: "String", + }, + { + type: "input_value", + name: "ID", + check: "Number", + }, + { + type: "input_value", + name: "FILTER", + check: "String", + }, + ], + previousStatement: null, + nextStatement: null, + colour: 100, + tooltip: "Send a message to a computer with a specific id", + helpUrl: "", +}; + +const rn_broadcast = { + type: "rn_broadcast", + message0: "Broadcast %1 with protocol %2 (optional)", + args0: [ + { + type: "input_value", + name: "MESSAGE", + check: "String", + }, + { + type: "input_value", + name: "FILTER", + check: "String", + }, + ], + previousStatement: null, + nextStatement: null, + colour: 100, + tooltip: "Broadcast a message to all computers on the same channel", + helpUrl: "", +}; + +const rn_receive = { + type: "rn_receive", + message0: "Receive with timeout %1 and protocol filter %2 (optional)", + args0: [ + { + type: "input_value", + name: "TIMEOUT", + check: "Number", + }, + { + type: "input_value", + name: "FILTER", + check: "String", + }, + ], + colour: 100, + tooltip: "Receive a message from the rednet", + helpUrl: "", + output: "Array", +}; + +const rn_host = { + type: "rn_host", + message0: "Host %1 with protocol %2", + args0: [ + { + type: "input_value", + name: "ID", + check: "Number", + }, + { + type: "input_value", + name: "FILTER", + check: "String", + }, + ], + previousStatement: null, + nextStatement: null, + colour: 100, + tooltip: "Register a computer as a host for a specific protocol", + helpUrl: "", +}; + +const rn_unhost = { + type: "rn_unhost", + message0: "Unhost %1", + args0: [ + { + type: "input_value", + name: "FILTER", + check: "String", + }, + ], + previousStatement: null, + nextStatement: null, + colour: 100, + tooltip: "Unregister a computer as a host for a specific protocol", + helpUrl: "", +}; + +const rn_lookup = { + type: "rn_lookup", + message0: "Lookup %1 with hostname %2 (optional)", + args0: [ + { + type: "input_value", + name: "FILTER", + check: "String", + }, + { + type: "input_value", + name: "HOSTNAME", + check: "String", + }, + ], + colour: 100, + tooltip: "Get the ID of a computer hosting a specific protocol", + helpUrl: "", + output: "Number", +}; + + + // Create the block definitions for the JSON-only blocks. // This does not register their definitions with Blockly. // This file has no side effects! @@ -1582,6 +1969,7 @@ export const blocks = Blockly.common.createBlockDefinitionsFromJsonArray([ read_replace, tonumber, tostring, + fs_open, fs_close, fs_read, @@ -1608,6 +1996,7 @@ export const blocks = Blockly.common.createBlockDefinitionsFromJsonArray([ fs_isdriveroot, shell_resolve, fs_combine, + turtle_attack, turtle_build, turtle_compare, @@ -1629,6 +2018,7 @@ export const blocks = Blockly.common.createBlockDefinitionsFromJsonArray([ turtle_select, turtle_suck, turtle_transferto, + get_arg, get_arg_amount, args, @@ -1666,4 +2056,28 @@ export const blocks = Blockly.common.createBlockDefinitionsFromJsonArray([ per_call, per_wrap, per_find, + + rs_getsides, + rs_setoutput, + rs_getoutput, + rs_getinput, + rs_setanalogoutput, + rs_getanalogoutput, + rs_getanaloginput, + + rn_chbroadcast, + rn_getchbroadcast, + rn_chrepeat, + rn_getchrepeat, + rn_chmaxid, + rn_getchmaxid, + rn_open, + rn_close, + rn_isopen, + rn_send, + rn_broadcast, + rn_receive, + rn_host, + rn_unhost, + rn_lookup, ]); diff --git a/src/generators/lua.js b/src/generators/lua.js index 1942026..8609f69 100644 --- a/src/generators/lua.js +++ b/src/generators/lua.js @@ -590,4 +590,169 @@ forBlock["per_find"] = function (block, generator) { // Generate the function call for this block. const code = `peripheral.find(${type})`; return [code, Order.NONE]; +} + + +// Redstone + +forBlock["rs_getsides"] = function (block, generator) { + // Generate the function call for this block. + const code = `redstone.getSides()`; + return [code, Order.NONE]; +} + +forBlock["rs_setoutput"] = function (block, generator) { + const side = generator.valueToCode(block, "SIDE", Order.NONE) || "''"; + const value = generator.valueToCode(block, "VALUE", Order.NONE) || "''"; + // Generate the function call for this block. + const code = `redstone.setOutput(${side},${value})\n`; + return code; +} + +forBlock["rs_getoutput"] = function (block, generator) { + const side = generator.valueToCode(block, "SIDE", Order.NONE) || "''"; + // Generate the function call for this block. + const code = `redstone.getOutput(${side})`; + return [code, Order.NONE]; +} + +forBlock["rs_getinput"] = function (block, generator) { + const side = generator.valueToCode(block, "SIDE", Order.NONE) || "''"; + // Generate the function call for this block. + const code = `redstone.getInput(${side})`; + return [code, Order.NONE]; +} + +forBlock["rs_setanalogoutput"] = function (block, generator) { + const side = generator.valueToCode(block, "SIDE", Order.NONE) || "''"; + const value = generator.valueToCode(block, "VALUE", Order.NONE) || "''"; + // Generate the function call for this block. + const code = `redstone.setAnalogOutput(${side},${value})\n`; + return code; +} + +forBlock["rs_getanalogoutput"] = function (block, generator) { + const side = generator.valueToCode(block, "SIDE", Order.NONE) || "''"; + // Generate the function call for this block. + const code = `redstone.getAnalogOutput(${side})`; + return [code, Order.NONE]; +} + +forBlock["rs_getanaloginput"] = function (block, generator) { + const side = generator.valueToCode(block, "SIDE", Order.NONE) || "''"; + // Generate the function call for this block. + const code = `redstone.getAnalogInput(${side})`; + return [code, Order.NONE]; +} + + + +// Rednet + +forBlock["rn_chbroadcast"] = function (block, generator) { + const channel = generator.valueToCode(block, "CHANNEL", Order.NONE) || "''"; + // Generate the function call for this block. + const code = `rednet.CHANNEL_BROADCAST = ${channel}`; + return code; +} + +forBlock["rn_getchbroadcast"] = function (block, generator) { + // Generate the function call for this block. + const code = `rednet.CHANNEL_BROADCAST`; + return [code, Order.NONE]; +} + +forBlock["rn_chrepeat"] = function (block, generator) { + const channel = generator.valueToCode(block, "CHANNEL", Order.NONE) || "''"; + // Generate the function call for this block. + const code = `rednet.CHANNEL_REPEAT = ${channel}`; + return code; +} + +forBlock["rn_getchrepeat"] = function (block, generator) { + // Generate the function call for this block. + const code = `rednet.CHANNEL_REPEAT`; + return [code, Order.NONE]; +} + +forBlock["rn_chmaxid"] = function (block, generator) { + const channel = generator.valueToCode(block, "CHANNEL", Order.NONE) || "''"; + // Generate the function call for this block. + const code = `rednet.CHANNEL_MAXID = ${channel}`; + return code; +} + +forBlock["rn_getchmaxid"] = function (block, generator) { + // Generate the function call for this block. + const code = `rednet.CHANNEL_MAXID`; + return [code, Order.NONE]; +} + +forBlock["rn_open"] = function (block, generator) { + const side = generator.valueToCode(block, "SIDE", Order.NONE) || "''"; + // Generate the function call for this block. + const code = `rednet.open(${side})`; + return [code, Order.NONE]; +} + +forBlock["rn_close"] = function (block, generator) { + const side = generator.valueToCode(block, "SIDE", Order.NONE) || "''"; + // Generate the function call for this block. + const code = `rednet.close(${side})`; + return code; +} + +forBlock["rn_isopen"] = function (block, generator) { + const side = generator.valueToCode(block, "SIDE", Order.NONE) || "''"; + // Generate the function call for this block. + const code = `rednet.isOpen(${side})`; + return [code, Order.NONE]; +} + +forBlock["rn_send"] = function (block, generator) { + const id = generator.valueToCode(block, "ID", Order.NONE) || "''"; + const message = generator.valueToCode(block, "MESSAGE", Order.NONE) || "''"; + const protocol = generator.valueToCode(block, "FILTER", Order.NONE) || "''"; + // Generate the function call for this block. + const code = `rednet.send(${id},${message},${protocol})\n`; + return code; +} + +forBlock["rn_broadcast"] = function (block, generator) { + const message = generator.valueToCode(block, "MESSAGE", Order.NONE) || "''"; + const protocol = generator.valueToCode(block, "FILTER", Order.NONE) || "''"; + // Generate the function call for this block. + const code = `rednet.broadcast(${message},${protocol})\n`; + return code; +} + +forBlock["rn_receive"] = function (block, generator) { + const protocol = generator.valueToCode(block, "FILTER", Order.NONE) || "''"; + const timeout = generator.valueToCode(block, "TIMEOUT", Order.NONE) || "''"; + // Generate the function call for this block. + const code = `rednet.receive(${protocol},${timeout})`; + return [code, Order.NONE]; +} + +forBlock["rn_host"] = function (block, generator) { + const protocol = generator.valueToCode(block, "FILTER", Order.NONE) || "''"; + const hostname = generator.valueToCode(block, "HOSTNAME", Order.NONE) || "''"; + // Generate the function call for this block. + const code = `rednet.host(${protocol},${hostname})`; + return code; +} + +forBlock["rn_unhost"] = function (block, generator) { + const protocol = generator.valueToCode(block, "FILTER", Order.NONE) || "''"; + // Generate the function call for this block. + const code = `rednet.unhost(${protocol})`; + return code; +} + +forBlock["rn_lookup"] = function (block, generator) { + const protocol = generator.valueToCode(block, "FILTER", Order.NONE) || "''"; + const hostname = generator.valueToCode(block, "HOSTNAME", Order.NONE) || "''"; + // Generate the function call for this block. + const code = `rednet.lookup(${protocol},${hostname})`; + return [code, Order.NONE]; } \ No newline at end of file diff --git a/src/index.css b/src/index.css index 42893a5..2332afd 100644 --- a/src/index.css +++ b/src/index.css @@ -29,8 +29,8 @@ pre, code { margin: 1rem; } -#output { - height: 50%; +#generatedCode { + height: 500px; } .copy-to-clipboard-button { diff --git a/src/index.html b/src/index.html index 6d1c82c..eb22494 100644 --- a/src/index.html +++ b/src/index.html @@ -8,7 +8,7 @@
- +