Skip to content

Instantly share code, notes, and snippets.

@Rio6
Last active January 28, 2020 23:53
Show Gist options
  • Save Rio6/d3a32d9e84055d39af4de8c36036d6da to your computer and use it in GitHub Desktop.
Save Rio6/d3a32d9e84055d39af4de8c36036d6da to your computer and use it in GitHub Desktop.
Archive/restore fleets for Istrolid. Now obsolete.
/*
* From version 0.51.1, fleet tab replaces this mod
* Below is a script that transfers archived fleets to a new tab
*/
var moveArchive = function() {
if(!commander) {
setTimeout(moveArchive, 1000);
return;
}
if(!commander.fleet.archive) return;
if(!confirm("Archived fleet detected. Do you want to move them to a new tab?")) return;
let uniqueTabName = function(name) {
var count, oldName;
oldName = name;
count = 1;
while (commander.fleet.tabs.indexOf(name) >= 0) {
name = oldName + count;
count += 1;
}
return name.replace(",", ",");
};
let archiveTab = uniqueTabName("archived");
for(let k in commander.fleet.archive) {
let [r, c] = k.split(",");
let newKey = getFleetKey(r, c, archiveTab);
let newAi = getAIKey(r, archiveTab);
commander.fleet[newKey] = commander.fleet.archive[k];
commander.fleet.ais[newAi] = commander.fleet.archive.ais[+r];
}
commander.fleet.tabs.push(archiveTab);
commander.fleet.archive = null;
}
moveArchive();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment