add internal block and define the block

This commit is contained in:
dharm pimsen 2024-07-01 21:10:48 +07:00
parent 27c614d99b
commit 7c3e24104a
8 changed files with 92 additions and 99 deletions

Binary file not shown.

76
package-lock.json generated
View File

@ -11,10 +11,7 @@
"dependencies": {
"blockly": "^11.1.1",
"bootstrap": "^5.3.3",
"electron-prompt": "^1.7.0",
"sweetalert2": "^11.12.1",
"xml2js": "^0.6.2",
"xmldom": "^0.6.0"
"electron-prompt": "^1.7.0"
},
"devDependencies": {
"electron": "^31.1.0"
@ -1069,11 +1066,6 @@
"resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz",
"integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg=="
},
"node_modules/sax": {
"version": "1.4.1",
"resolved": "https://registry.npmjs.org/sax/-/sax-1.4.1.tgz",
"integrity": "sha512-+aWOz7yVScEGoKNd4PA10LZ8sk0A/z5+nXQG5giUO5rprX9jgYsTdov9qCchZiPIZezbZH+jRut8nPodFAX4Jg=="
},
"node_modules/saxes": {
"version": "6.0.0",
"resolved": "https://registry.npmjs.org/saxes/-/saxes-6.0.0.tgz",
@ -1136,15 +1128,6 @@
"node": ">= 8.0"
}
},
"node_modules/sweetalert2": {
"version": "11.12.1",
"resolved": "https://registry.npmjs.org/sweetalert2/-/sweetalert2-11.12.1.tgz",
"integrity": "sha512-xV3/YI7Ah6BeP+bXKcrHy1yn6duh8eqlX2TSI9I/rTIzGLYQvnnTa3mOIo5RHUobAjSmacC2IhPApxjvppZaEQ==",
"funding": {
"type": "individual",
"url": "https://github.com/sponsors/limonte"
}
},
"node_modules/symbol-tree": {
"version": "3.2.4",
"resolved": "https://registry.npmjs.org/symbol-tree/-/symbol-tree-3.2.4.tgz",
@ -1304,39 +1287,11 @@
"node": ">=18"
}
},
"node_modules/xml2js": {
"version": "0.6.2",
"resolved": "https://registry.npmjs.org/xml2js/-/xml2js-0.6.2.tgz",
"integrity": "sha512-T4rieHaC1EXcES0Kxxj4JWgaUQHDk+qwHcYOCFHfiwKz7tOVPLq7Hjq9dM1WCMhylqMEfP7hMcOIChvotiZegA==",
"dependencies": {
"sax": ">=0.6.0",
"xmlbuilder": "~11.0.0"
},
"engines": {
"node": ">=4.0.0"
}
},
"node_modules/xmlbuilder": {
"version": "11.0.1",
"resolved": "https://registry.npmjs.org/xmlbuilder/-/xmlbuilder-11.0.1.tgz",
"integrity": "sha512-fDlsI/kFEx7gLvbecc0/ohLG50fugQp8ryHzMTuW9vSa1GJ0XYWKnhsUx7oie3G98+r56aTQIUB4kht42R3JvA==",
"engines": {
"node": ">=4.0"
}
},
"node_modules/xmlchars": {
"version": "2.2.0",
"resolved": "https://registry.npmjs.org/xmlchars/-/xmlchars-2.2.0.tgz",
"integrity": "sha512-JZnDKK8B0RCDw84FNdDAIpZK+JuJw+s7Lz8nksI7SIuU3UXJJslUthsi+uWBUYOwPFwW7W7PRLRfUKpxjtjFCw=="
},
"node_modules/xmldom": {
"version": "0.6.0",
"resolved": "https://registry.npmjs.org/xmldom/-/xmldom-0.6.0.tgz",
"integrity": "sha512-iAcin401y58LckRZ0TkI4k0VSM1Qg0KGSc3i8rU+xrxe19A/BN1zHyVSJY7uoutVlaTSzYyk/v5AmkewAP7jtg==",
"engines": {
"node": ">=10.0.0"
}
},
"node_modules/yauzl": {
"version": "2.10.0",
"resolved": "https://registry.npmjs.org/yauzl/-/yauzl-2.10.0.tgz",
@ -2134,11 +2089,6 @@
"resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz",
"integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg=="
},
"sax": {
"version": "1.4.1",
"resolved": "https://registry.npmjs.org/sax/-/sax-1.4.1.tgz",
"integrity": "sha512-+aWOz7yVScEGoKNd4PA10LZ8sk0A/z5+nXQG5giUO5rprX9jgYsTdov9qCchZiPIZezbZH+jRut8nPodFAX4Jg=="
},
"saxes": {
"version": "6.0.0",
"resolved": "https://registry.npmjs.org/saxes/-/saxes-6.0.0.tgz",
@ -2186,11 +2136,6 @@
"debug": "^4.1.0"
}
},
"sweetalert2": {
"version": "11.12.1",
"resolved": "https://registry.npmjs.org/sweetalert2/-/sweetalert2-11.12.1.tgz",
"integrity": "sha512-xV3/YI7Ah6BeP+bXKcrHy1yn6duh8eqlX2TSI9I/rTIzGLYQvnnTa3mOIo5RHUobAjSmacC2IhPApxjvppZaEQ=="
},
"symbol-tree": {
"version": "3.2.4",
"resolved": "https://registry.npmjs.org/symbol-tree/-/symbol-tree-3.2.4.tgz",
@ -2302,30 +2247,11 @@
"resolved": "https://registry.npmjs.org/xml-name-validator/-/xml-name-validator-5.0.0.tgz",
"integrity": "sha512-EvGK8EJ3DhaHfbRlETOWAS5pO9MZITeauHKJyb8wyajUfQUenkIg2MvLDTZ4T/TgIcm3HU0TFBgWWboAZ30UHg=="
},
"xml2js": {
"version": "0.6.2",
"resolved": "https://registry.npmjs.org/xml2js/-/xml2js-0.6.2.tgz",
"integrity": "sha512-T4rieHaC1EXcES0Kxxj4JWgaUQHDk+qwHcYOCFHfiwKz7tOVPLq7Hjq9dM1WCMhylqMEfP7hMcOIChvotiZegA==",
"requires": {
"sax": ">=0.6.0",
"xmlbuilder": "~11.0.0"
}
},
"xmlbuilder": {
"version": "11.0.1",
"resolved": "https://registry.npmjs.org/xmlbuilder/-/xmlbuilder-11.0.1.tgz",
"integrity": "sha512-fDlsI/kFEx7gLvbecc0/ohLG50fugQp8ryHzMTuW9vSa1GJ0XYWKnhsUx7oie3G98+r56aTQIUB4kht42R3JvA=="
},
"xmlchars": {
"version": "2.2.0",
"resolved": "https://registry.npmjs.org/xmlchars/-/xmlchars-2.2.0.tgz",
"integrity": "sha512-JZnDKK8B0RCDw84FNdDAIpZK+JuJw+s7Lz8nksI7SIuU3UXJJslUthsi+uWBUYOwPFwW7W7PRLRfUKpxjtjFCw=="
},
"xmldom": {
"version": "0.6.0",
"resolved": "https://registry.npmjs.org/xmldom/-/xmldom-0.6.0.tgz",
"integrity": "sha512-iAcin401y58LckRZ0TkI4k0VSM1Qg0KGSc3i8rU+xrxe19A/BN1zHyVSJY7uoutVlaTSzYyk/v5AmkewAP7jtg=="
},
"yauzl": {
"version": "2.10.0",
"resolved": "https://registry.npmjs.org/yauzl/-/yauzl-2.10.0.tgz",

View File

@ -13,13 +13,5 @@
</shadow>
</value>
</block>
<block type="another_block_type">
<value name="INPUT">
<shadow type="math_number">
<field name="NUM">5</field> <!-- Default value -->
</shadow>
</value>
</block>
</category>
</xml>

View File

@ -1,6 +1,5 @@
const fs = require('fs');
const path = require('path');
const xml2js = require('xml2js');
const peripheralsfolder = path.join(__dirname, "../peripherals");

View File

@ -0,0 +1,50 @@
{
"sys_commmands_exec": {
"message0": "Execute %1",
"args0": [
{
"type": "input_value",
"name": "EXECOMMANDS",
"text": "say Hello World"
}
],
"previousStatement": null,
"nextStatement": null,
"colour": 120,
"tooltip": "Execute a specific command.",
"helpUrl": "https://tweaked.cc/module/commands.html#v:exec"
},
"sys_commmands_getblockposition": {
"message0": "GetBlockInfo at minX %1 minY %2 minZ %3 maxX %4 maxY %5 maxZ %6",
"args0": [
{
"type": "input_value",
"name": "MINX"
},
{
"type": "input_value",
"name": "MINY"
},
{
"type": "input_value",
"name": "MINZ"
},
{
"type": "input_value",
"name": "MAXX"
},
{
"type": "input_value",
"name": "MAXY"
},
{
"type": "input_value",
"name": "MAXZ"
}
],
"colour": 120,
"output": "Array",
"tooltip": "Get information about a range of blocks.",
"helpUrl": "https://tweaked.cc/module/commands.html#v:getBlockInfos"
}
}

0
src/module_generator.js Normal file
View File

View File

@ -1,14 +1,5 @@
<xml id="toolbox" style="display: none;">
<category name="Logic" categorystyle="logic_category">
<block type="controls_if"></block>
<block type="logic_compare"></block>
<block type="logic_operation"></block>
<block type="logic_negate"></block>
<block type="logic_boolean"></block>
<block type="logic_null"></block>
<block type="logic_ternary"></block>
</category>
<category name="Control" categorystyle="loop_category">
<category name="Control">
<block type="controls_repeat_ext" >
<value name="TIMES">
<shadow type="math_number">
@ -17,6 +8,16 @@
</value>
</block>
<block type="controls_whileUntil"></block>
<block type="controls_if"></block>
<block type="controls_ifelse"></block>
<block type="logic_compare"></block>
<block type="logic_operation"></block>
<block type="logic_negate"></block>
<block type="logic_boolean"></block>
<block type="logic_null"></block>
<block type="logic_ternary"></block>
<block type="controls_for">
<value name="FROM">
<shadow type="math_number">
@ -36,8 +37,9 @@
</block>
<block type="controls_forEach"></block>
<block type="controls_flow_statements"></block>
</category>
<category name="Math" categorystyle="math_category">
<category name="Math">
<block type="math_number" gap="32">
<field name="NUM">123</field>
</block>
@ -138,7 +140,7 @@
</value>
</block>
</category>
<category name="Text" categorystyle="text_category">
<category name="Text">
<block type="text"></block>
<block type="text_join"></block>
<block type="text_append">
@ -240,7 +242,7 @@
</value>
</block>
</category>
<category name="Lists" categorystyle="list_category">
<category name="Lists">
<block type="lists_create_with">
<mutation items="0"></mutation>
</block>
@ -293,8 +295,15 @@
<block type="lists_reverse"></block>
</category>
<sep></sep>
<category name="Variables" categorystyle="variable_category" custom="VARIABLE">
<category name="Variables" custom="VARIABLE">
</category>
<category name="Functions" categorystyle="procedure_category" custom="PROCEDURE"></category>
<category name="Functions" custom="PROCEDURE"></category>
<sep></sep>
<!-- commands -->
<category name="Commands" colour="120">
<block type="sys_commmands_exec"></block>
<block type="sys_commmands_getblockposition"></block>
</category>
<sep></sep>
</xml>

View File

@ -15,9 +15,25 @@ window.prompt = function(promptText, defaultValue) {
const Blockly = require('blockly');
Blockly.utils.colour.setHsvSaturation(0.9)
const peripheralsfolder = path.join(__dirname, "../peripherals");
const originaltoolbar = fs.readFileSync(path.join(__dirname, "toolbox.xml"), 'utf8');
const sysmodulejson = fs.readFileSync(path.join(__dirname, "module_block_design.json"), 'utf8');
const blocksJson = JSON.parse(sysmodulejson);
for (const blockId in blocksJson) {
if (blocksJson.hasOwnProperty(blockId)) {
Blockly.Blocks[blockId] = {
init: function() {
this.jsonInit(blocksJson[blockId]);
}
};
}
}
var workspace = Blockly.inject('blocklyDiv', {
toolbox: originaltoolbar,
@ -30,6 +46,7 @@ var workspace = Blockly.inject('blocklyDiv', {
}
});
loadperipheral(workspace, originaltoolbar, "test");
document.getElementById('statusMessage').textContent = "ready";