rainbow-quox download button

This commit is contained in:
Rhiannon Morris 2024-12-16 22:40:26 +01:00
parent 845c0b9708
commit 7e4518bdaf
5 changed files with 86 additions and 13 deletions

View file

@ -375,6 +375,31 @@ function closeHistory() {
document.documentElement.dataset.state = 'ready';
}
function download(seed: string) {
const colors = Color.toRgbs(Color.colors(new Color.Rand(seed)));
let lines = [
"GIMP Palette\n",
`Name: quox ${seed}\n\n`,
];
for (const name of Color.allLayers) {
let { r, g, b } = colors[name];
lines.push(`${r} ${g} ${b} ${name}\n`);
}
const blob = new Blob(lines, { type: 'application/x-gimp-palette' });
// there must be a better way to push out a file than
// this autohotkey-ass nonsense
const elem = document.createElement('a');
elem.download = `quox-${seed}.gpl`;
const url = URL.createObjectURL(blob);
elem.href = url;
elem.click();
URL.revokeObjectURL(url);
}
async function setup() {
message('loading layers…');
@ -383,9 +408,10 @@ async function setup() {
let buf = new OffscreenCanvas(WIDTH, HEIGHT).getContext('2d')!;
let seed = urlState() ?? new Color.Rand().alphaNum();
let prevSeed = urlState() ?? new Color.Rand().alphaNum();
let seed =
await applyState(data, { seed: prevSeed, buf, history, firstLoad: true });
let side: Side = 'front';
seed = await applyState(data, { seed, buf, history, firstLoad: true });
const reroll = document.getElementById('reroll')!;
const swap = document.getElementById('swap')!;
@ -415,8 +441,12 @@ async function setup() {
elem.innerText = str;
// todo allow images cos it's funny
prevSeed = seed;
seed = await applyState(data, { side, seed: str, buf, history });
});
document.getElementById('download-button')?.addEventListener('click', () => {
download(prevSeed);
});
document.documentElement.dataset.state = 'ready';
@ -430,12 +460,14 @@ async function setup() {
const newSeed = urlState();
if (newSeed) {
const opts = { history, side, seed: newSeed, buf, done: k };
prevSeed = seed;
seed = await applyState(data, opts);
}
});
}
function runReroll() {
run(async k => {
prevSeed = seed;
seed = await applyState(data, { side, seed, buf, history, done: k });
});
}