From 9b20e4e5ddea4d1a5dc8cecba51ba94a4f714a1e Mon Sep 17 00:00:00 2001 From: Daniel Date: Thu, 18 Apr 2024 13:24:16 -0400 Subject: [PATCH 1/2] Add loading xml directly from files. --- index.html | 3 ++- main.js | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/index.html b/index.html index 5b0db18..2f93b6a 100644 --- a/index.html +++ b/index.html @@ -30,7 +30,8 @@
more keybinds
Ctrl+Shift+S - copy xml
Ctrl+V - import xml from clipboard
-
Ctrl+Shift+V - import xml and not clear
+
Ctrl+O - import xml from file
+
Ctrl+Shift+V - import xml and not clear
Ctrl+E - export
Ctrl+Shift+Del - clear workspace
Ctrl+Shift+K - toggle keyboard navigation
diff --git a/main.js b/main.js index b214025..1ff66aa 100644 --- a/main.js +++ b/main.js @@ -174,6 +174,36 @@ function getCodeAsXml() { return Blockly.Xml.domToText(xml); } +function loadCodeFromFile(clear = true) { + // Create file input element + const fileInput = document.createElement('input'); + fileInput.type = 'file'; + fileInput.accept = '.xml'; + fileInput.style.display = 'none'; // Hide the actual button + + fileInput.onchange = function(event) { + const file = event.target.files[0]; + const reader = new FileReader(); + + reader.onload = function() { + const code = reader.result; + // load the file + loadCode(code, clear); + + // Remove the file input element from the DOM (to prevent lots of hidden buttons) + document.body.removeChild(fileInput); + }; + + reader.readAsText(file); + }; + + // Append the file input element to the body + document.body.appendChild(fileInput); + + // Open the file input menu + fileInput.click(); +} + function loadCode(code, clear = true) { if (!code) return; if (clear) Blockly.mainWorkspace.clear(); @@ -197,6 +227,11 @@ document.addEventListener('keydown', async e => { } } + if (e.code === 'KeyO' && e.ctrlKey) { + e.preventDefault(); + loadCodeFromFile(!e.shiftKey); + } + if (e.code === 'KeyE' && e.ctrlKey) { e.preventDefault(); clickExport(); From 6952eb1e9583dc9c630914b54d8e981d99c0bbdb Mon Sep 17 00:00:00 2001 From: Daniel Date: Thu, 18 Apr 2024 13:34:08 -0400 Subject: [PATCH 2/2] Added unit unbind block. --- config.js | 1 + index.html | 1 + 2 files changed, 2 insertions(+) diff --git a/config.js b/config.js index 9080f07..a230ef5 100644 --- a/config.js +++ b/config.js @@ -331,6 +331,7 @@ const MINDUSTRY_LOCATE_BUILDINGS = [ const MINDUSTRY_UNIT_CONTROL = { stop: [], + unbind: [], move: ['x', 'y'], flag: ['value'], approach: ['x', 'y', 'radius'], diff --git a/index.html b/index.html index 2f93b6a..bd5df48 100644 --- a/index.html +++ b/index.html @@ -270,6 +270,7 @@ + 0 0