diff --git a/blocks/CCColors/index.json b/blocks/CCColors/index.json index 97ab426..67a3507 100644 --- a/blocks/CCColors/index.json +++ b/blocks/CCColors/index.json @@ -1,5 +1,5 @@ { - "name": "Colors", + "name": "CC: Colors", "author": "DPSoftware Foundation", "description": "Constants and functions for colour values", "version": "0.5", diff --git a/blocks/CCRednet/index.json b/blocks/CCRednet/index.json index 60fe0f4..762d65b 100644 --- a/blocks/CCRednet/index.json +++ b/blocks/CCRednet/index.json @@ -1,5 +1,5 @@ { - "name": "Rednet", + "name": "CC: Rednet", "author": "DPSoftware Foundation", "description": "Library for rednet", "version": "1.0.0", diff --git a/blocks/CCSettings/block_design.json b/blocks/CCSettings/block_design.json new file mode 100644 index 0000000..3db1a7e --- /dev/null +++ b/blocks/CCSettings/block_design.json @@ -0,0 +1,147 @@ +{ + "settings_define": { + "message0": "Define new %1 Description %2 Default %3 Type %4", + "args0": [ + { + "type": "input_value", + "name": "NAME", + "check": "String" + }, + { + "type": "input_value", + "name": "DESC", + "check": "String" + }, + { + "type": "input_value", + "name": "DEF" + }, + { + "type": "input_value", + "name": "TYPE", + "check": "String" + } + ], + "previousStatement": null, + "nextStatement": null, + "colour": 120, + "tooltip": "Define a new setting, optional specifying various properties about it." + }, + "settings_undefine": { + "message0": "UnDefine %1", + "args0": [ + { + "type": "input_value", + "name": "NAME", + "check": "String" + } + ], + "previousStatement": null, + "nextStatement": null, + "colour": 120, + "tooltip": "Remove a definition of a setting." + }, + "settings_set": { + "message0": "Set %1 with value %2", + "args0": [ + { + "type": "input_value", + "name": "NAME", + "check": "String" + }, + { + "type": "input_value", + "name": "VALUE" + } + ], + "previousStatement": null, + "nextStatement": null, + "colour": 120, + "tooltip": "Set the value of a setting." + }, + "settings_get": { + "message0": "Get %1 If no value then use %2 as default", + "args0": [ + { + "type": "input_value", + "name": "NAME", + "check": "String" + }, + { + "type": "input_value", + "name": "DEF" + } + ], + "output": null, + "colour": 120, + "tooltip": "Get the value of a setting." + }, + "settings_getdetails": { + "message0": "Get %1 Details", + "args0": [ + { + "type": "input_value", + "name": "NAME", + "check": "String" + } + ], + "output": "Array", + "colour": 120, + "tooltip": "Get details about a specific setting." + }, + "settings_unset": { + "message0": "UnSet %1 value", + "args0": [ + { + "type": "input_value", + "name": "NAME", + "check": "String" + } + ], + "previousStatement": null, + "nextStatement": null, + "colour": 120, + "tooltip": "Remove the value of a setting, setting it to the default." + }, + "settings_clear": { + "message0": "Clear all settings", + "previousStatement": null, + "nextStatement": null, + "colour": 120, + "tooltip": "Resets the value of all settings." + }, + "settings_getnames": { + "message0": "Get all settings", + "output": "Array", + "colour": 120, + "tooltip": "Get the names of all currently defined settings." + }, + "settings_load": { + "message0": "Load settings from %1", + "args0": [ + { + "type": "input_value", + "name": "FILE", + "check": "String" + } + ], + "previousStatement": null, + "nextStatement": null, + "colour": 120, + "tooltip": "Load settings from the given file." + }, + "settings_save": { + "message0": "Save settings to %1", + "args0": [ + { + "type": "input_value", + "name": "FILE", + "check": "String" + } + ], + "previousStatement": null, + "nextStatement": null, + "colour": 120, + "tooltip": "Save settings to the given file." + } +} diff --git a/blocks/CCSettings/generator.js b/blocks/CCSettings/generator.js new file mode 100644 index 0000000..fdbeb4d --- /dev/null +++ b/blocks/CCSettings/generator.js @@ -0,0 +1,95 @@ +const { luaGenerator } = require('blockly/lua'); + +// Check if luaGenerator.forBlock is defined and initialize if necessary +if (!luaGenerator.forBlock) { + luaGenerator.forBlock = {}; +} + +function exportWithEquals(obj) { + let result = []; + for (let key in obj) { + if (obj.hasOwnProperty(key)) { + result.push(`${key}=${obj[key]}`); + } + } + return `{${result.join(',')}}`; +} + +luaGenerator.forBlock['settings_define'] = function(block, generator) { + var name = generator.valueToCode(block, 'NAME', generator.ORDER_NONE); + var desc = generator.valueToCode(block, 'DESC', generator.ORDER_NONE); + var def = generator.valueToCode(block, 'DEF', generator.ORDER_NONE); + var type = generator.valueToCode(block, 'TYPE', generator.ORDER_NONE); + + var option = {} + + if (desc != "") { + option.description = desc + } + if (def != "") { + option.default = def + } + if (type != "") { + option.type = type + } + var exportedoption = exportWithEquals(option); + + if (exportedoption == "{}") { + var code = `settings.define(${name})` + } else { + var code = `settings.define(${name}, ${exportedoption})` + } + + return code + "\n"; +}; + +luaGenerator.forBlock['settings_undefine'] = function(block, generator) { + var name = generator.valueToCode(block, 'NAME', generator.ORDER_NONE); + + return `settings.undefine(${name})`; +}; + +luaGenerator.forBlock['settings_set'] = function(block, generator) { + var name = generator.valueToCode(block, 'NAME', generator.ORDER_NONE); + var value = generator.valueToCode(block, 'VALUE', generator.ORDER_NONE); + + return `settings.set(${name}, ${value})`; +}; + +luaGenerator.forBlock['settings_get'] = function(block, generator) { + var name = generator.valueToCode(block, 'NAME', generator.ORDER_NONE); + + return [`settings.get(${name})`, luaGenerator.ORDER_NONE]; +}; + +luaGenerator.forBlock['settings_getdetails'] = function(block, generator) { + var name = generator.valueToCode(block, 'NAME', generator.ORDER_NONE); + + return [`settings.getDetails(${name})`, luaGenerator.ORDER_NONE]; +}; + +luaGenerator.forBlock['settings_unset'] = function(block, generator) { + var name = generator.valueToCode(block, 'NAME', generator.ORDER_NONE); + + return `settings.unset(${name})`; +}; + +luaGenerator.forBlock['settings_clear'] = function(block, generator) { + return `settings.clear()`; +}; + +luaGenerator.forBlock['settings_getnames'] = function(block, generator) { + return [`settings.getNames()`, luaGenerator.ORDER_NONE]; +}; + +luaGenerator.forBlock['settings_load'] = function(block, generator) { + var file = generator.valueToCode(block, 'FILE', generator.ORDER_NONE); + + return `settings.load(${file})`; +}; + +luaGenerator.forBlock['settings_save'] = function(block, generator) { + var file = generator.valueToCode(block, 'FILE', generator.ORDER_NONE); + + return `settings.save(${file})`; +}; diff --git a/blocks/IDE/index.json b/blocks/CCSettings/index.json similarity index 70% rename from blocks/IDE/index.json rename to blocks/CCSettings/index.json index 6e73aec..12a9d27 100644 --- a/blocks/IDE/index.json +++ b/blocks/CCSettings/index.json @@ -1,10 +1,10 @@ { - "name": "IDE", + "name": "CC: Settings", "author": "DPSoftware Foundation", - "description": "Block for IDE", + "description": "Read and write configuration options for CraftOS and your programs.", "version": "1.0.0", - "category": "Blockly Extensions", - "keyword": "test", + "category": "Config", + "keyword": "Env", "license": "GPL-3.0-or-later", "peripherals": false, "library": true, @@ -19,4 +19,4 @@ "turtle": true, "advturtle": true } -} \ No newline at end of file +} diff --git a/blocks/CCSettings/toolbox.xml b/blocks/CCSettings/toolbox.xml new file mode 100644 index 0000000..f6b5891 --- /dev/null +++ b/blocks/CCSettings/toolbox.xml @@ -0,0 +1,62 @@ +Install Remote code into computercraft in github.`; + document.getElementById('upload-status').innerHTML = `Please Connect Computer to IDE.\nInstruction: Install Remote code into computercraft in github. (Please press SHIFT or CTRL and click)`; return } diff --git a/src/index.html b/src/index.html index 1ad9467..0e3c49d 100644 --- a/src/index.html +++ b/src/index.html @@ -98,7 +98,7 @@
diff --git a/blocks/IDE/block_design.json b/blocks/IDE/block_design.json deleted file mode 100644 index 4cb8834..0000000 --- a/blocks/IDE/block_design.json +++ /dev/null @@ -1,26 +0,0 @@ -{ - "ide_addcode": { - "message0": "Add Code %1", - "args0": [ - { - "type": "input_value", - "name": "CODE", - "text": "print('hello world!')" - } - ], - "previousStatement": null, - "nextStatement": null, - "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 deleted file mode 100644 index f26725d..0000000 --- a/blocks/IDE/generator.js +++ /dev/null @@ -1,29 +0,0 @@ -const { luaGenerator } = require('blockly/lua'); - -// Check if luaGenerator.forBlock is defined and initialize if necessary- -if (!luaGenerator.forBlock) { - luaGenerator.forBlock = {}; -} - -// Define your custom block handler -luaGenerator.forBlock['ide_addcode'] = function(block, generator) { - var codefromuser = generator.valueToCode(block, 'CODE', generator.ORDER_ATOMIC); - - // Remove all occurrences of the matched characters - 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 deleted file mode 100644 index 7ba83e4..0000000 --- a/blocks/IDE/toolbox.xml +++ /dev/null @@ -1,7 +0,0 @@ - \ No newline at end of file diff --git a/blocks/Template/block_design.json b/blocks/_Template/block_design.json similarity index 100% rename from blocks/Template/block_design.json rename to blocks/_Template/block_design.json diff --git a/blocks/Template/generator.js b/blocks/_Template/generator.js similarity index 98% rename from blocks/Template/generator.js rename to blocks/_Template/generator.js index 6cfab87..f37b9fa 100644 --- a/blocks/Template/generator.js +++ b/blocks/_Template/generator.js @@ -1,3 +1,5 @@ +// this file not for generator only + const { luaGenerator } = require('blockly/lua'); // Check if luaGenerator.forBlock is defined and initialize if necessary diff --git a/blocks/Template/index.json b/blocks/_Template/index.json similarity index 100% rename from blocks/Template/index.json rename to blocks/_Template/index.json diff --git a/blocks/Template/toolbox.xml b/blocks/_Template/toolbox.xml similarity index 100% rename from blocks/Template/toolbox.xml rename to blocks/_Template/toolbox.xml diff --git a/ccIDE Defines.xlsx b/ccIDE Defines.xlsx index 01485bc..f8a2af8 100644 Binary files a/ccIDE Defines.xlsx and b/ccIDE Defines.xlsx differ diff --git a/index.js b/index.js index 9027828..766c708 100644 --- a/index.js +++ b/index.js @@ -233,23 +233,20 @@ app.whenReady().then(() => { { label: 'Edit', submenu: [ - { role: 'undo', accelerator: 'CmdOrCtrl+Z', click: () => {win.webContents.send('request-undo-redo', false)} }, - { role: 'redo', accelerator: 'CmdOrCtrl+Y', click: () => {win.webContents.send('request-undo-redo', true)} }, - { type: 'separator' }, - { role: 'cut', accelerator: 'CmdOrCtrl+X' }, - { role: 'copy', accelerator: 'CmdOrCtrl+C' }, - { role: 'paste', accelerator: 'CmdOrCtrl+V' } - ] - }, - { - label: 'View', - submenu: [ - { label: 'DevTools', accelerator: 'F12', click: () => {win.openDevTools()}}, + { label: "Undo", accelerator: "CmdOrCtrl+Z", selector: "undo:" }, + { label: "Redo", accelerator: "Shift+CmdOrCtrl+Z", selector: "redo:" }, + { type: "separator" }, + { label: "Cut", accelerator: "CmdOrCtrl+X", selector: "cut:" }, + { label: "Copy", accelerator: "CmdOrCtrl+C", selector: "copy:" }, + { label: "Paste", accelerator: "CmdOrCtrl+V", selector: "paste:" }, + { label: "Select All", accelerator: "CmdOrCtrl+A", selector: "selectAll:" } ] }, { label: 'Help', submenu: [ + { label: 'DevTools', accelerator: 'F12', click: () => {win.openDevTools()}}, + { type: 'separator' }, { label: 'About', click: () => { diff --git a/src/blocksmanager.js b/src/blocksmanager.js index c00d86c..ed978b2 100644 --- a/src/blocksmanager.js +++ b/src/blocksmanager.js @@ -6,7 +6,6 @@ const peripheralsfolder = path.join(__dirname, "../blocks"); const fallbackImagePath = path.join(__dirname, '..', 'assets', 'noimagefallback.png'); // Path to fallback image -let registedblock = {} const defineicon = { computer: { @@ -142,77 +141,78 @@ function scanindex() { const jsonData = JSON.parse(content); blockfoldername = extractFolderName(filePath); - registedblock[blockfoldername] = jsonData; - foundedpackages++; + if (!blockfoldername.startsWith("_")) { + foundedpackages++; - // create item in list - const imagePath = path.join(filePath, "icon.png"); + // create item in list + const imagePath = path.join(filePath, "icon.png"); - const libraryItem = document.createElement('div'); - libraryItem.classList.add('library-item', 'overflow-auto', 'library-container'); - libraryItem.setAttribute('data-libraryfolder', blockfoldername); + const libraryItem = document.createElement('div'); + libraryItem.classList.add('library-item', 'overflow-auto', 'library-container'); + libraryItem.setAttribute('data-libraryfolder', blockfoldername); - // add image - const img = document.createElement('img'); - img.classList.add('libimage'); - if (fileExists(imagePath)) { - img.src = imagePath; - } else { - img.src = fallbackImagePath; - } - libraryItem.appendChild(img); + // add image + const img = document.createElement('img'); + img.classList.add('libimage'); + if (fileExists(imagePath)) { + img.src = imagePath; + } else { + img.src = fallbackImagePath; + } + libraryItem.appendChild(img); - // Create the library details container - const libraryDetails = document.createElement('div'); - libraryDetails.classList.add('library-details'); - - // Create the title element - const title = document.createElement('h3'); - title.textContent = jsonData.name + ` [v${jsonData.version} by ${jsonData.author}]`; - libraryDetails.appendChild(title); + // Create the library details container + const libraryDetails = document.createElement('div'); + libraryDetails.classList.add('library-details'); + + // Create the title element + const title = document.createElement('h3'); + title.textContent = jsonData.name + ` [v${jsonData.version} by ${jsonData.author}]`; + libraryDetails.appendChild(title); - // Create the description element - const description = document.createElement('p'); - description.innerHTML = jsonData.description; - libraryDetails.appendChild(description); + // Create the description element + const description = document.createElement('p'); + description.innerHTML = jsonData.description; + libraryDetails.appendChild(description); - console.log(jsonData) - if (jsonData.design_for_computer.basic) { - addimageiconinfo(libraryDetails, defineicon.computer.basic, "Basic Computer Supported"); - } - if (jsonData.design_for_computer.adv) { - addimageiconinfo(libraryDetails, defineicon.computer.adv, "Advanced Computer Supported"); - } - //if (jsonData.design_for_computer.command) { - // addimageiconinfo(libraryDetails, defineicon.computer.command, "Command Computer Supported"); - //} - if (jsonData.design_for_computer.pocket) { - addimageiconinfo(libraryDetails, defineicon.computer.pocket, "Pocket Computer Supported"); - } - if (jsonData.design_for_computer.advpocket) { - addimageiconinfo(libraryDetails, defineicon.computer.advpocket, "Advanced Pocket Computer Supported"); - } - if (jsonData.design_for_computer.turtle) { - addimageiconinfo(libraryDetails, defineicon.computer.turtle, "Turtle Supported"); - } - if (jsonData.design_for_computer.advturtle) { - addimageiconinfo(libraryDetails, defineicon.computer.advturtle, "Advanced Turtle Supported"); - } + console.log(jsonData) + if (jsonData.design_for_computer.basic) { + addimageiconinfo(libraryDetails, defineicon.computer.basic, "Basic Computer Supported"); + } + if (jsonData.design_for_computer.adv) { + addimageiconinfo(libraryDetails, defineicon.computer.adv, "Advanced Computer Supported"); + } + //if (jsonData.design_for_computer.command) { + // addimageiconinfo(libraryDetails, defineicon.computer.command, "Command Computer Supported"); + //} + if (jsonData.design_for_computer.pocket) { + addimageiconinfo(libraryDetails, defineicon.computer.pocket, "Pocket Computer Supported"); + } + if (jsonData.design_for_computer.advpocket) { + addimageiconinfo(libraryDetails, defineicon.computer.advpocket, "Advanced Pocket Computer Supported"); + } + if (jsonData.design_for_computer.turtle) { + addimageiconinfo(libraryDetails, defineicon.computer.turtle, "Turtle Supported"); + } + if (jsonData.design_for_computer.advturtle) { + addimageiconinfo(libraryDetails, defineicon.computer.advturtle, "Advanced Turtle Supported"); + } - // check computer type support - if (jsonData.peripherals) { - addimageiconinfo(libraryDetails, defineicon.peripheral, "Peripheral"); - } - if (jsonData.library) { - addimageiconinfo(libraryDetails, defineicon.library, "Library"); - } - if (jsonData.require_network) { - addimageiconinfo(libraryDetails, defineicon.networkreq, "Require Network"); - } + // check computer type support + if (jsonData.peripherals) { + addimageiconinfo(libraryDetails, defineicon.peripheral, "Peripheral"); + } + if (jsonData.library) { + addimageiconinfo(libraryDetails, defineicon.library, "Library"); + } + if (jsonData.require_network) { + addimageiconinfo(libraryDetails, defineicon.networkreq, "Require Network"); + } - libraryItem.appendChild(libraryDetails); - document.getElementById('libcontainer').appendChild(libraryItem); - console.log(`registered ${blockfoldername} blocks and added to packages managers`) + libraryItem.appendChild(libraryDetails); + document.getElementById('libcontainer').appendChild(libraryItem); + console.log(`registered ${blockfoldername} blocks and added to packages managers`) + } } }) diff --git a/src/codegen.js b/src/codegen.js index 7bcb46b..d7c05a9 100644 --- a/src/codegen.js +++ b/src/codegen.js @@ -82,7 +82,7 @@ async function gencode() { } else { uploadError = true; uploadUpdateProgress(); - document.getElementById('upload-status').innerHTML = `Please Connect Computer to IDE.\nInstruction: