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 5b0db18..bd5df48 100644
--- a/index.html
+++ b/index.html
@@ -30,7 +30,8 @@
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
@@ -269,6 +270,7 @@
+
0
0
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();