better ascii export with layers
This commit is contained in:
bovenliggende
b891d52b73
commit
dc15bbac18
59
src/ascii.js
59
src/ascii.js
|
@ -469,63 +469,72 @@ export const exportMirc = () => {
|
|||
const {
|
||||
currentAscii
|
||||
} = store.getters;
|
||||
const layers = [...store.getters.currentAsciiLayers].reverse();
|
||||
// const blocks = store.getters.currentAsciiBlocks;
|
||||
const blocks = [...store.getters.currentAsciiLayers];
|
||||
const output = [];
|
||||
let curBlock = false;
|
||||
let currentLayer = 0;
|
||||
let prevBlock = {
|
||||
bg: -1,
|
||||
fg: -1
|
||||
};
|
||||
|
||||
for (let y = 0; y <= currentAscii.height - 1; y++) {
|
||||
for (let x = 0; x <= currentAscii.width - 1; x++) {
|
||||
// Find the best block to use going top down with layers
|
||||
for (let i = layers.length - 1; i >= 0; i--) {
|
||||
for (let y = 0; y <= blocks[0].data.length - 1; y++) {
|
||||
if (y >= currentAscii.height) {
|
||||
continue;
|
||||
}
|
||||
|
||||
for (let x = 0; x <= blocks[0].data[y].length - 1; x++) {
|
||||
if (x >= currentAscii.width) {
|
||||
continue;
|
||||
}
|
||||
|
||||
for (let i = blocks.length - 1; i >= 0; i--) {
|
||||
if (blocks[i].visible === true) {
|
||||
currentLayer = i;
|
||||
|
||||
if (layers[i].visible === true) {
|
||||
if (
|
||||
layers[i] &&
|
||||
layers[i].data &&
|
||||
layers[i].data[y] &&
|
||||
layers[i].data[y][x] &&
|
||||
JSON.stringify(layers[i].data[y][x]) ===
|
||||
blocks[i].data &&
|
||||
blocks[i].data[y] &&
|
||||
blocks[i].data[y][x] &&
|
||||
i > 0 &&
|
||||
JSON.stringify(blocks[i].data[y][x]) ===
|
||||
JSON.stringify(emptyBlock)
|
||||
) {
|
||||
continue;
|
||||
} else if (
|
||||
// Otherwise if we are on the very first layer we need to render it
|
||||
layers[i] &&
|
||||
layers[i].data &&
|
||||
layers[i].data[y] &&
|
||||
layers[i].data[y][x]
|
||||
blocks[i].data &&
|
||||
blocks[i].data[y] &&
|
||||
blocks[i].data[y][x]
|
||||
) {
|
||||
|
||||
curBlock = {
|
||||
...layers[i].data[y][x]
|
||||
...blocks[i].data[y][x]
|
||||
};
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// If we have a difference between our previous block
|
||||
// we'll put a colour codes and continue as normal
|
||||
if (curBlock.bg !== prevBlock.bg || curBlock.fg !== prevBlock.fg) {
|
||||
curBlock = {
|
||||
...blocks[currentLayer].data[y][x]
|
||||
};
|
||||
const zeroPad = (num, places) => String(num).padStart(places, '0');
|
||||
output.push(
|
||||
`\u0003${zeroPad(
|
||||
curBlock.fg ?? '',
|
||||
curBlock.fg ?? store.getters.options.defaultFg,
|
||||
2,
|
||||
)},${zeroPad(curBlock.bg ??'', 2)}`,
|
||||
)},${zeroPad(curBlock.bg ?? store.getters.options.defaultBg, 2)}`,
|
||||
);
|
||||
}
|
||||
|
||||
// null .chars will end up as space
|
||||
output.push(curBlock.char ?? ' ');
|
||||
prevBlock = {
|
||||
...curBlock
|
||||
}
|
||||
|
||||
prevBlock = blocks[currentLayer].data[y][x];
|
||||
}
|
||||
|
||||
// We can never have a -1 colour code so we'll always
|
||||
|
@ -536,7 +545,7 @@ export const exportMirc = () => {
|
|||
};
|
||||
|
||||
// New line except for the very last line
|
||||
if (y < currentAscii.height - 1) {
|
||||
if (y < blocks[currentLayer].data[y].length - 1) {
|
||||
output.push('\n');
|
||||
}
|
||||
}
|
||||
|
|
Laden…
Verwijs in nieuw issue