Last active
November 23, 2024 17:59
-
-
Save LapisOnTheMoon/a45a8ae903224fa39fa3c9a40c99cdbb to your computer and use it in GitHub Desktop.
rcgi constellation import/export
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
// ==UserScript== | |
// @name RCGI Constellation Import/Export | |
// @version 0.1 | |
// @description Import/Export for Constellation | |
// @author LapisOnTheMoon | |
// @match https://mrredshark77.github.io/RGCI-Classic/ | |
// @icon https://www.google.com/s2/favicons?sz=64&domain=https://mrredshark77.github.io/RGCI-Classic/ | |
// @updateURL https://gist.github.com/LapisOnTheMoon/a45a8ae903224fa39fa3c9a40c99cdbb/raw/fb3c8ac2453a057d25402738e4eb094aaaaccd1a/constellation-importexport.user.js | |
// @grant none | |
// ==/UserScript== | |
(function() { | |
function importPreset(base64String = prompt('Input preset base64')) { | |
if (!base64String || base64String.length === 0) return; | |
const dataString = atob(base64String), su5 = hasSolarUpgrade(2,5) | |
const p = JSON.parse(dataString); | |
for (let i = 0; i < p.cost.length; i++) p.cost[i] = E(p.cost[i]); | |
if (p.encode && player.constellation.line.gte(p.cost[0]) && player.constellation.arc.gte(p.cost[1])) { | |
player.constellation.line = player.constellation.line.sub(p.cost[0]); | |
player.constellation.arc = player.constellation.arc.sub(p.cost[1]); | |
let e = p.encode.split(','); | |
sellAllGrids(false); | |
for (let y = 0; y < 7; y++) { | |
for (let x = 0; x < 7; x++) { | |
let g = e[y*7+x]; | |
if (g != '-') { | |
let t = parseInt(g.split('t')[0]); | |
if (!su5 || t > 13) player.constellation.grid[y][x] = g | |
} | |
} | |
} | |
updateConstellation(); | |
console.log('Imported preset'); | |
} | |
} | |
window.importPreset = importPreset; | |
function exportPreset(i) { | |
let pd = player.constellation.presets[i]; | |
let presetData; | |
if (typeof i !== 'undefined' && i >= 0 && i <= 4) { | |
presetData = { | |
encode: pd.encode, | |
cost: pd.cost, | |
boosts: pd.boosts | |
} | |
} else { | |
let grids = player.constellation.grid; | |
let c = '', cost = [E(0), E(0)], b = ''; | |
for (let y = 0; y < 7; y++) { | |
for (let x = 0; x < 7; x++) { | |
if (grids[y][x]) { | |
let s = grids[y][x].split('t'); | |
let type = parseInt(s[0]), tier = parseInt(s[1]); | |
let cs = CS_BUILDINGS[type], cs_type = cs.type || 0; | |
c += c ? ',' + grids[y][x] : grids[y][x]; | |
cost[cs_type] = cost[cs_type].add(cs.cost(tier - 1)); | |
if (type in PRES_BOOSTS && !b.includes(PRES_BOOSTS[type])) { | |
b += b ? ', ' + PRES_BOOSTS[type] : PRES_BOOSTS[type]; | |
} | |
} else { | |
c += c ? ',-' : '-'; | |
} | |
} | |
} | |
presetData = { | |
encode: c, | |
cost: cost, | |
boosts: b | |
} | |
} | |
const stringified = JSON.stringify(presetData); | |
const b64 = btoa(stringified); | |
let copyText = document.getElementById('copy'); | |
copyText.value = b64; | |
copyText.style.visibility = "visible"; | |
copyText.select(); | |
document.execCommand("copy"); | |
copyText.style.visibility = "hidden"; | |
console.log("Exported to clipboard"); | |
} | |
window.exportPreset = exportPreset; | |
function injectHTML() { | |
const presets = document.getElementsByClassName("cs-preset"); | |
for (let i = 0; i < presets.length; i++) { | |
const html = `<button onclick="exportPreset(${i})">Export</button>`; | |
presets[i].insertAdjacentHTML('beforeend', html); | |
} | |
const sellAllBtn = document.querySelectorAll('button[onclick="sellAllGrids()"]')[0]; | |
const sellAllHtml = ` | |
<button onclick="importPreset()" style="font-size: 16px;">Import</button> | |
<button onclick="exportPreset()" style="font-size: 16px;">Export</button> | |
`; | |
sellAllBtn.insertAdjacentHTML('afterend', sellAllHtml); | |
} | |
window.addEventListener('load', event => { | |
injectHTML(); | |
}); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment