Skip to content

Commit

Permalink
Merge pull request #5 from dimani128/master
Browse files Browse the repository at this point in the history
A Couple QOL features.
  • Loading branch information
Meshiest authored Apr 19, 2024
2 parents 98b5035 + 6952eb1 commit 68fea81
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 1 deletion.
1 change: 1 addition & 0 deletions config.js
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,7 @@ const MINDUSTRY_LOCATE_BUILDINGS = [

const MINDUSTRY_UNIT_CONTROL = {
stop: [],
unbind: [],
move: ['x', 'y'],
flag: ['value'],
approach: ['x', 'y', 'radius'],
Expand Down
4 changes: 3 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@
<div class="more-header">more keybinds</div>
<div class="bind button" id="copyxmlBtn"><code>Ctrl+Shift+S</code> - <b>copy xml</b></div>
<div class="bind"><code>Ctrl+V</code> - <b>import xml from clipboard</b></div>
<div class="bind"><code>Ctrl+Shift+V</code> - <b>import xml and not clear</b></div>
<div class="bind"><code>Ctrl+O</code> - <b>import xml from file</b></div>
<div class="bind" id="importBtn"><code>Ctrl+Shift+V</code> - <b>import xml and not clear</b></div>
<div class="bind button" id="exportBtn"><code>Ctrl+E</code> - <b>export</b></div>
<div class="bind button" id="clearBtn"><code>Ctrl+Shift+Del</code> - <b>clear workspace</b></div>
<div class="bind"><code>Ctrl+Shift+K</code> - <b>toggle <a href="https://developers.google.com/blockly/guides/configure/web/keyboard-nav#using_keyboard_navigation" tabindex="-1" target="_blank" rel="noopener noreferrer">keyboard navigation</a></b></div>
Expand Down Expand Up @@ -269,6 +270,7 @@
</value>
</block>
<block type="mind_unit_control_stop"></block>
<block type="mind_unit_control_unbind"></block>
<block type="mind_unit_control_move">
<value name="x"><shadow type="var_block_text"><field name="VALUE">0</field></shadow></value>
<value name="y"><shadow type="var_block_text"><field name="VALUE">0</field></shadow></value>
Expand Down
35 changes: 35 additions & 0 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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();
Expand Down

0 comments on commit 68fea81

Please sign in to comment.