Last active
October 9, 2021 17:34
-
-
Save Rio6/6e32d62d0cd766d581ee5a52c80735b2 to your computer and use it in GitHub Desktop.
Swap fleets using keyboard shortcut in Istrolid
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Swapping fleet using shift + arrow up/down key. | |
* Use alt-shift-num to select one of the first 10 fleets | |
*/ | |
var fleetSwap = window.fleetSwap || { | |
onkeydown: ControlsMode.prototype.onkeydown | |
} | |
ControlsMode.prototype.onkeydown = function(e) { | |
const saveAndRefresh = () => { | |
account.save(); | |
onecup.refresh(); | |
}; | |
if(e.shiftKey && e.key == "ArrowUp") { | |
if(commander.fleet.selection.row > 0) { | |
commander.fleet.selection.row -= 1; | |
saveAndRefresh(); | |
} | |
return; | |
} else if(e.shiftKey && e.key == "ArrowDown") { | |
commander.fleet.selection.row += 1; | |
saveAndRefresh(); | |
return; | |
} else if(e.shiftKey && e.altKey) { | |
let row = e.which - 49; | |
if(row === -1) row += 49; | |
if(row >= 0 && row < 49) { // is numeric key | |
commander.fleet.selection.row = row; | |
saveAndRefresh(); | |
Object.defineProperty(e, 'which', { get: () => 0 }); // Prevent battleMode spawn unit | |
return; | |
} | |
} | |
return fleetSwap.onkeydown.call(this, e); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Nice!