update 1.1.4 add new Settings block

add new Settings block for env settings
and merge IDE block to system for default
This commit is contained in:
dharm pimsen 2024-07-20 16:49:13 +07:00
parent 18200b2b51
commit b77dc34ec6
22 changed files with 439 additions and 156 deletions

View File

@ -1,5 +1,5 @@
{
"name": "Colors",
"name": "CC: Colors",
"author": "DPSoftware Foundation",
"description": "Constants and functions for colour values",
"version": "0.5",

View File

@ -1,5 +1,5 @@
{
"name": "Rednet",
"name": "CC: Rednet",
"author": "DPSoftware Foundation",
"description": "Library for rednet",
"version": "1.0.0",

View File

@ -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."
}
}

View File

@ -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})`;
};

View File

@ -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,

View File

@ -0,0 +1,62 @@
<xml id="toolbox" style="display: none;">
<category name="Settings" colour="120">
<block type="settings_define">
<value name="NAME">
<shadow type="text">
<field name="TEXT">SomeSettingsName</field>
</shadow>
</value>
</block>
<block type="settings_undefine">
<value name="NAME">
<shadow type="text">
<field name="TEXT">SomeSettingsName</field>
</shadow>
</value>
</block>
<block type="settings_set">
<value name="NAME">
<shadow type="text">
<field name="TEXT">SomeSettingsName</field>
</shadow>
</value>
</block>
<block type="settings_get">
<value name="NAME">
<shadow type="text">
<field name="TEXT">SomeSettingsName</field>
</shadow>
</value>
</block>
<block type="settings_getdetails">
<value name="NAME">
<shadow type="text">
<field name="TEXT">SomeSettingsName</field>
</shadow>
</value>
</block>
<block type="settings_unset">
<value name="NAME">
<shadow type="text">
<field name="TEXT">SomeSettingsName</field>
</shadow>
</value>
</block>
<block type="settings_clear"></block>
<block type="settings_getnames"></block>
<block type="settings_load">
<value name="FILE">
<shadow type="text">
<field name="TEXT">.settings</field>
</shadow>
</value>
</block>
<block type="settings_save">
<value name="FILE">
<shadow type="text">
<field name="TEXT">.settings</field>
</shadow>
</value>
</block>
</category>
</xml>

View File

@ -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."
}
}

View File

@ -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;
};

View File

@ -1,7 +0,0 @@
<xml id="toolbox" style="display: none;">
<category name="IDE" colour="150">
<!-- Define your custom blocks here -->
<block type="ide_addcode"></block>
<block type="ide_start"></block>
</category>
</xml>

View File

@ -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

Binary file not shown.

View File

@ -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: () => {

View File

@ -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 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 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`)
}
}
})

View File

@ -82,7 +82,7 @@ async function gencode() {
} else {
uploadError = true;
uploadUpdateProgress();
document.getElementById('upload-status').innerHTML = `Please Connect Computer to IDE.\nInstruction: <a href="https://github.com/DPSoftware-Foundation/ccIDE#install-remote-code-into-computercraft">Install Remote code into computercraft</a> in github.`;
document.getElementById('upload-status').innerHTML = `Please Connect Computer to IDE.\nInstruction: <a href="https://github.com/DPSoftware-Foundation/ccIDE#install-remote-code-into-computercraft">Install Remote code into computercraft</a> in github. (Please press SHIFT or CTRL and click)`;
return
}

View File

@ -98,7 +98,7 @@
</div>
<div class="popup" id="library-popup" style="overflow-y:hidden;">
<div class="popup-content p-3" style="max-width: 1280px; position: relative; margin-top: 150px;">
<div class="popup-content p-3" style="max-width: 1280px; position: relative; margin-top: 100px;">
<button type="button" class="btn-close" aria-label="Close" id="libraryCloseBtn" style="position: absolute; top: 10px; right: 10px;"></button>
<h3>Packages Managers</h3>
<div class="library-content">

View File

@ -97,5 +97,29 @@
],
"output": "Array",
"colour": 260
},
"ide_addcode": {
"message0": "Add Code %1",
"args0": [
{
"type": "input_value",
"name": "CODE",
"text": "print('hello world!')"
}
],
"previousStatement": null,
"nextStatement": null,
"colour": 220,
"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": 220,
"tooltip": "Not require but make your code easy to read."
}
}

View File

@ -58,3 +58,26 @@ luaGenerator.forBlock['sys_table_append_data'] = function(block, generator) {
return `table.insert(${table}, ${data})\n`;
};
// 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;
};

View File

@ -318,6 +318,8 @@
</category>
<category name="Utils" colour="220">
<block type="sys_utils_get_type"></block>
<block type="ide_addcode"></block>
<block type="ide_start"></block>
</category>
<sep></sep>
<category name="Variables" custom="VARIABLE" colour="330">

View File

@ -17,8 +17,9 @@ let usedlibinproject = []
Blockly.utils.colour.setHsvSaturation(0.9)
let originaltoolbar = fs.readFileSync(path.join(__dirname, "toolbox.xml"), 'utf8');
const sysmodulejson = fs.readFileSync(path.join(__dirname, "module_block_design.json"), 'utf8');
// load some system library
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)) {
@ -53,9 +54,6 @@ var workspace = Blockly.inject('blocklyDiv', {
try {
scanindex();
originaltoolbar = loadperipheral(workspace, originaltoolbar, "IDE");
usedlibinproject.push("IDE");
} catch (e) {
ipc.send("erroronstart", `Error on loading block: ${e}`)
}
@ -165,11 +163,6 @@ ipc.on('workspace-saved', (event, success) => {
}, 1000);
});
ipc.on('request-undo-redo', (event, redo) => {
console.log(redo)
workspace.undo(redo)
});
ipc.on("open-about", () => {
document.getElementById('about-popup').style.display = 'block';
})