asciibird/src/ascii.js

796 lines
41 KiB
JavaScript
Raw Normal View History

2021-08-04 03:21:06 +00:00
import LZString from 'lz-string';
import store from './store';
// 0 => 'white',
// 1 => 'black',
// 2 => 'navy',
// 3 => 'green',
// 4 => 'red',
// 5 => 'brown',
// 6 => 'purple',
// 7 => 'olive',
// 8 => 'yellow', # dark yellow
// 9 => 'lime', # ltgreen
// 10 => 'teal',
// 11 => 'cyan',
// 12 => 'blue', # ltblue,
// 13 => 'fuchsia', # pink
// 14 => 'grey',
// 15 => 'lightgrey',
export const mircColours99 = [
'rgb(255,255,255)',
'rgb(0,0,0)',
'rgb(0,0,127)',
'rgb(0,147,0)',
'rgb(255,0,0)',
'rgb(127,0,0)',
'rgb(156,0,156)',
'rgb(252,127,0)',
'rgb(255,255,0)',
'rgb(0,252,0)',
'rgb(0,147,147)',
'rgb(0,255,255)',
'rgb(0,0,252)',
'rgb(255,0,255)',
'rgb(127,127,127)',
'rgb(210,210,210)',
"#470000",
"#472100",
"#474700",
"#324700",
"#004700",
"#00472c",
"#004747",
"#002747",
"#000047",
"#2e0047",
"#470047",
"#47002a",
"#740000",
"#743a00",
"#747400",
"#517400",
"#007400",
"#007449",
"#007474",
"#004074",
"#000074",
"#4b0074",
"#740074",
"#740045",
"#b50000",
"#b56300",
"#b5b500",
"#7db500",
"#00b500",
"#00b571",
"#00b5b5",
"#0063b5",
"#0000b5",
"#7500b5",
"#b500b5",
"#b5006b",
"#ff0000",
"#ff8c00",
"#ffff00",
"#b2ff00",
"#00ff00",
"#00ffa0",
"#00ffff",
"#008cff",
"#0000ff",
"#a500ff",
"#ff00ff",
"#ff0098",
"#ff5959",
"#ffb459",
"#ffff71",
"#cfff60",
"#6fff6f",
"#65ffc9",
"#6dffff",
"#59b4ff",
"#5959ff",
"#c459ff",
"#ff66ff",
"#ff59bc",
"#ff9c9c",
"#ffd39c",
"#ffff9c",
"#e2ff9c",
"#9cff9c",
"#9cffdb",
"#9cffff",
"#9cd3ff",
"#9c9cff",
"#dc9cff",
"#ff9cff",
"#ff94d3",
"#000000",
"#131313",
"#282828",
"#363636",
"#4d4d4d",
"#656565",
"#818181",
"#9f9f9f",
"#bcbcbc",
"#e2e2e2",
"#ffffff",
2021-08-04 03:21:06 +00:00
];
2021-08-12 01:52:40 +00:00
// How big the brush size can get
// Although you can type in the input a bigger number than this anyway
export const maxBrushSize = 50;
2021-08-12 01:52:40 +00:00
// Chars that end up in the toolbar
export const charCodes = [' ', '!', '"', '#', '$', '%', '&', '\'', '(', ')', '*', '+', ',', '-',
'.', '/',
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', ':', ';', '<', '=', '>', '?', '@', 'A',
'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S',
'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '[', '\\', ']', '^', '_', '`', 'a', 'b', 'c', 'd', 'e',
'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w',
'x', 'y', 'z', '{', '|', '}', '~', 'Ç', 'ü', 'é', 'â', 'ä', 'à', 'å', 'ç', 'ê', 'ë', 'è',
'ï', 'î', 'ì', 'Ä', 'Å', 'É', 'æ', 'Æ', 'ô', 'ö', 'ò', 'û', 'ù', 'ÿ', 'Ö', 'Ü', 'ø', '£',
'Ø', '×', 'ƒ', 'á', 'í', 'ó', 'ú', 'ñ', 'Ñ', 'ª', 'º', '¿', '®', '¬', '½', '¼', '¡', '«',
'»', 'Á', 'Â', 'À', '©', '¢', '¥', 'ã', 'Ã', '¤', 'ð', 'Ð', 'Ê', 'Ë', 'È', 'ı', 'Í', 'Î',
'Ï', '¦', 'Ì', 'Ó', 'ß', 'Ô', 'Ò', 'õ', 'Õ', 'µ', 'þ', 'Þ', 'Ú', 'Û', 'Ù', 'ý', 'Ý', '¸',
'°', '¨', '·', '¯', '´', '≡', '±', '‗', '¶', '§', '÷',
'⁰', '¹', '³', '²', '⁴', '⁵', '⁶', '⁷', '⁸', '⁹', '⁺', '⁻', '⁼', '⁽', '⁾',
'₀', '₁', '₂', '₃', '₄', '₅', '₆', '₇', '₈', '₉', '₊', '₋', '₌', '₍', '₎',
2021-12-04 03:47:31 +00:00
'¼', '½', '¾', '⅓', '⅔', '⅕', '⅖', '⅗', '⅘', '⅙', '⅚', '⅛', '⅜', '⅝', '⅞', '⅟', '⅒', '⅑', '',
'└', '┐', '┘', '┌', '│', '┤', '├', '┴', '┬', '─', '┼',
'╚', '╗', '╝', '╔', '║', '╣', '╠', '╩', '╦', '═', '╬',
'╰', '╮', '╯', '╭', '', '╲', '',
'▘', '▖', '▝', '▗', '▚',
'▏', '▎', '▍', '▌', '▋', '▊', '▉',
'▁', '▂', '▃', '▄', '▅', '▆', '▇', '▀', '▔', '░', '▒', '▓', '█',
];
// Toolbar icons
export const toolbarIcons = [{
name: 'default',
icon: 'edit_off',
},
{
name: 'select',
icon: 'photo_size_select_small',
},
{
name: 'text',
icon: 'text_rotation_none',
},
{
name: 'fill',
icon: 'format_color_fill',
},
{
name: 'brush',
icon: 'brush',
},
{
name: 'dropper',
icon: 'colorize',
},
{
name: 'eraser',
icon: 'remove_circle_outline',
},
{
name: 'fill-eraser',
icon: 'auto_fix_off',
},
];
2021-08-04 03:21:06 +00:00
export const emptyBlock = {
// bg: null,
// fg: null,
// char: null,
2021-08-04 03:21:06 +00:00
};
export const create2DArray = (rows) => {
const arr = [];
for (let i = 0; i < rows; i++) {
arr[i] = [];
}
return arr;
};
// Width and height of the ASCII blocks
// they seem to be 8x15 in asciiblaster
export const blockWidth = 8;
export const blockHeight = 15;
// Limits for undo and brush histories
2021-11-06 00:59:17 +00:00
export const maxBrushHistory = 200;
2021-12-17 11:03:10 +00:00
export const maxUndoHistory = 500;
2021-11-06 00:59:17 +00:00
export const tabLimit = 20;
2021-12-18 09:33:47 +00:00
export const parseMircAscii = async (contents, filename) => {
2021-12-18 11:18:39 +00:00
const mIrcColourRegex = new RegExp(/\u0003(\d{0,2})?[,]?(\d{0,2})?/, 'gu');
2021-12-18 09:33:47 +00:00
// The current state of the Colours
let curBlock = {
...emptyBlock,
};
contents = contents
.split('\u0003\u0003')
.join('\u0003')
.split('\u000F').join('')
2021-12-30 04:25:07 +00:00
.split('\u0003\n').join('\n')
.split('\u0002\u0003').join('\u0003')
.split('\u0002').join('') // bold
.split('\u001D').join(''); // italics
2021-12-18 09:33:47 +00:00
let asciiLines = contents.split("\n");
const finalAscii = {
title: filename,
layers: [{
label: filename,
visible: true,
data: create2DArray(contents.split('\n').length),
width: 0, // calculated down bellow
2021-12-18 09:33:47 +00:00
height: contents.split('\n').length,
}],
history: [],
historyIndex: 0,
imageOverlay: {
url: null,
opacity: 95,
position: 'centered',
size: 100,
repeatx: true,
repeaty: true,
visible: false,
stretched: false,
},
x: blockWidth * 35, // the dragable ascii canvas x
y: blockHeight * 2, // the dragable ascii canvas y
selectedLayer: 0,
};
// Determine if we have a plain text ascii
const colourCodeRegex = new RegExp(/\u0003/, 'g');
let isPlainText = !colourCodeRegex.test(contents);
// Get the max line width, as some lines can be trimmed by spaces
// we cannot always rely on the first line for the width
for (let i = 0; i < asciiLines.length; i++) {
let cleanedWidth = asciiLines[i].replace(mIrcColourRegex, '').length;
if (cleanedWidth > finalAscii.layers[0].width) {
finalAscii.layers[0].width = cleanedWidth;
}
}
2021-12-18 09:33:47 +00:00
// https://modern.ircdocs.horse/formatting.html#color
// In the following list, <CODE> represents the color formatting character (0x03), <COLOR> represents one or two ASCII digits (either 0-9 or 00-99).
// The use of this code can take on the following forms:
// <CODE> - Reset foreground and background colors.
// <CODE>, - Reset foreground and background colors and display the , character as text.
// <CODE><COLOR> - Set the foreground color.
// <CODE><COLOR>, - Set the foreground color and display the , character as text.
// <CODE><COLOR>,<COLOR> - Set the foreground and background color.
// The foreground color is the first <COLOR>, and the background color is the second <COLOR> (if sent).
for (let y in asciiLines) {
let line = asciiLines[y];
2021-12-18 11:18:39 +00:00
let cleanLines = line.replace(mIrcColourRegex, '').split("");
2021-12-18 09:33:47 +00:00
2021-12-18 11:18:39 +00:00
let parsedLine = [...line.matchAll(mIrcColourRegex)];
2021-12-18 09:33:47 +00:00
let colourData = [];
curBlock = {
...emptyBlock,
};
2021-12-18 11:18:39 +00:00
let newData = [];
2021-12-18 09:33:47 +00:00
if (!isPlainText) {
for (let x in parsedLine) {
let codeData = parsedLine[x];
let colourArray = codeData[0].split("\u0003").join("").split(",");
2021-12-18 11:18:39 +00:00
if (colourArray.length === 2) {
if (colourArray[0] > -1) {
2021-12-18 09:33:47 +00:00
curBlock.fg = Number.parseInt(colourArray[0]);
}
2021-12-18 11:18:39 +00:00
if (colourArray[1] > -1) {
2021-12-18 09:33:47 +00:00
curBlock.bg = Number.parseInt(colourArray[1]);
}
2021-12-18 11:18:39 +00:00
} else if (colourArray.length === 1) {
if (colourArray[0] == "") {
2021-12-18 11:18:39 +00:00
delete curBlock['bg'];
delete curBlock['fg'];
delete curBlock['char'];
2021-12-18 11:18:39 +00:00
}
if (colourArray[0] > 0) {
curBlock.fg = Number.parseInt(colourArray[0]);
delete curBlock['bg'];
}
}
2021-12-18 11:18:39 +00:00
colourData.push({
code: codeData,
b: {
...curBlock
}
});
2021-12-18 09:33:47 +00:00
}
2021-12-18 11:18:39 +00:00
// Readjust the indexes
let indexAdjustment = 0;
2021-12-18 09:33:47 +00:00
for (let index in colourData) {
if (index === 0) {
continue;
}
2021-12-18 11:18:39 +00:00
colourData[index].code.index = colourData[index].code.index - indexAdjustment;
indexAdjustment = indexAdjustment + colourData[index].code[0].length;
newData[colourData[index].code.index] = colourData[index].b;
2021-12-18 09:33:47 +00:00
}
2021-12-18 11:18:39 +00:00
2021-12-18 09:33:47 +00:00
}
2021-12-18 11:18:39 +00:00
// Construct the ascii blocks
for (let i in cleanLines) {
let char = cleanLines[i];
2021-12-18 09:33:47 +00:00
2021-12-18 11:18:39 +00:00
// If there is a colour change present at this index
// we will keep track of it
if (!isPlainText && newData[i]) {
if (newData[i].bg !== undefined) {
2021-12-18 09:33:47 +00:00
curBlock.bg = newData[i].bg;
}
if (newData[i].fg !== undefined) {
2021-12-18 09:33:47 +00:00
curBlock.fg = newData[i].fg;
}
2021-12-18 11:18:39 +00:00
if (newData[i].fg === undefined && newData[i].bg === undefined) {
curBlock = {
...emptyBlock
};
2021-12-18 09:33:47 +00:00
}
2021-12-18 11:18:39 +00:00
}
2021-12-18 09:33:47 +00:00
curBlock.char = char;
2021-12-18 11:18:39 +00:00
2021-12-18 09:33:47 +00:00
finalAscii.layers[0].data[y][i] = {
...curBlock
};
}
}
// First layer data generation
finalAscii.layers = [...fillNullBlocks(finalAscii.layers[0].height, finalAscii.layers[0]
.width, finalAscii.layers)];
2021-12-18 11:18:39 +00:00
2021-12-18 09:33:47 +00:00
// Store the ASCII and ensure we have no null blocks
finalAscii.layers = LZString.compressToUTF16(
JSON.stringify(finalAscii.layers),
);
2021-08-07 06:10:52 +00:00
// Save ASCII to storage
2021-08-04 03:21:06 +00:00
store.commit('newAsciibirdMeta', finalAscii);
2021-08-04 02:47:17 +00:00
return true;
};
// Creates new blank ASCII
2021-08-04 02:47:17 +00:00
export const createNewAscii = (forms) => {
2021-08-04 03:21:06 +00:00
const newAscii = {
2021-08-04 02:47:17 +00:00
title: forms.createAscii.title,
history: [],
historyIndex: 0,
2021-08-04 02:47:17 +00:00
x: 247, // the dragable ascii canvas x
y: 24, // the dragable ascii canvas y
layers: [{
2021-08-14 06:41:42 +00:00
label: forms.createAscii.title,
visible: true,
data: create2DArray(forms.createAscii.height),
width: forms.createAscii.width,
height: forms.createAscii.height,
2021-08-14 06:41:42 +00:00
}],
2021-10-16 05:16:21 +00:00
imageOverlay: {
url: null,
opacity: 95,
position: 'centered',
size: 100,
repeatx: true,
repeaty: true,
visible: false,
2021-10-23 00:23:02 +00:00
stretched: false,
2021-10-16 05:16:21 +00:00
},
2021-08-14 06:41:42 +00:00
selectedLayer: 0,
2021-08-04 02:47:17 +00:00
};
// Push all the default ASCII blocks
for (let x = 0; x < newAscii.layers[0].width; x++) {
for (let y = 0; y < newAscii.layers[0].height; y++) {
newAscii.layers[0].data[y].push({
2021-08-04 03:21:06 +00:00
...emptyBlock,
});
2021-08-04 02:47:17 +00:00
}
}
newAscii.layers = LZString.compressToUTF16(JSON.stringify(newAscii.layers));
2021-08-04 03:21:06 +00:00
store.commit('newAsciibirdMeta', newAscii);
2021-08-06 01:51:58 +00:00
store.commit('closeModal', 'new-ascii');
2021-08-04 02:47:17 +00:00
return true;
2021-08-04 03:21:06 +00:00
};
// Converts ASCIIBIRD blocks to mIRC colours
export const exportMirc = (blocks = null) => {
2021-12-26 01:41:24 +00:00
var isPng = false;
if (blocks === null) {
var {
currentAscii
} = store.getters;
2021-08-28 03:20:59 +00:00
2021-12-26 01:41:24 +00:00
var {
currentAsciiLayersWidthHeight
} = store.getters;
2021-08-28 03:20:59 +00:00
blocks = mergeLayers();
2021-12-26 01:41:24 +00:00
} else {
var currentAscii = {};
currentAscii.title = `brush-${cyrb53(JSON.stringify(blocks))}.png`
isPng = true;
var currentAsciiLayersWidthHeight = {
height: blocks.length,
width: blocks[0].length
}
}
const output = [];
2021-08-14 06:41:42 +00:00
let curBlock = false;
2021-09-04 00:21:53 +00:00
let pushString = '';
2021-08-28 03:20:59 +00:00
let prevBlock = {
bg: -1,
fg: -1
};
2021-09-04 05:16:27 +00:00
for (let y = 0; y <= currentAsciiLayersWidthHeight.height - 1; y++) {
2021-08-14 22:51:45 +00:00
2021-09-04 05:16:27 +00:00
for (let x = 0; x <= currentAsciiLayersWidthHeight.width - 1; x++) {
2021-08-28 03:20:59 +00:00
curBlock = {
...blocks[y][x]
};
2021-08-14 22:51:45 +00:00
// 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) {
2021-08-14 22:51:45 +00:00
curBlock = {
2021-08-28 03:20:59 +00:00
...blocks[y][x]
2021-08-14 22:51:45 +00:00
};
const zeroPad = (num, places) => String(num).padStart(places, '0');
2021-08-28 03:20:59 +00:00
if (curBlock.fg === undefined && curBlock.bg === undefined) {
2021-09-04 00:21:53 +00:00
output.push('\u0003');
2021-08-28 03:20:59 +00:00
} else {
2021-09-04 00:21:53 +00:00
2021-12-30 04:25:07 +00:00
if (curBlock.bg === undefined && (curBlock.fg !== undefined && curBlock.fg !== null)) {
2021-12-29 06:52:32 +00:00
pushString = `\u0003${zeroPad(curBlock.fg ?? 0, 2)}`;
2021-09-04 00:21:53 +00:00
}
2021-12-30 04:25:07 +00:00
if ((curBlock.bg !== undefined && curBlock.bg !== null) && (curBlock.fg !== undefined && curBlock.fg !== null)) {
2021-12-29 06:52:32 +00:00
// export will check if the next char is a number and add 0 padding to prevent clients eating characters
if (blocks[y][x + 1].char !== undefined && (Number.parseInt(blocks[y][x + 1].char) >= 0 && Number.parseInt(blocks[y][x + 1].char) <= 9)) {
pushString = `\u0003${curBlock.fg ?? 0},${zeroPad(curBlock.bg ?? 1, 2)}`;
} else {
pushString = `\u0003${curBlock.fg},${curBlock.bg}`;
}
2021-09-04 00:21:53 +00:00
}
2021-12-29 06:52:32 +00:00
if ((curBlock.bg !== undefined && curBlock.bg !== null) && curBlock.fg === undefined) {
pushString = `\u0003,${zeroPad(curBlock.bg ?? 1, 2)}`;
2021-10-23 00:37:25 +00:00
}
2021-09-04 00:21:53 +00:00
output.push(pushString);
2021-08-28 03:20:59 +00:00
}
2021-09-04 00:21:53 +00:00
}
// null .chars will end up as space
output.push(curBlock.char ?? ' ');
2021-09-04 00:21:53 +00:00
prevBlock = {
...blocks[y][x]
};
}
// We can never have a -1 colour code so we'll always
// write one at the start of each line
prevBlock = {
bg: -1,
fg: -1
};
// New line except for the very last line
2021-12-29 06:52:32 +00:00
// if (blocks[y] && y < blocks[y].length - 1) {
output.push('\n');
2021-12-29 06:52:32 +00:00
// }
}
// Download to a txt file
// Check if txt already exists and append it
var filename = currentAscii.title.slice(currentAscii.title.length - 3) === 'txt' ?
currentAscii.title :
`${currentAscii.title}.txt`;
2021-12-26 01:41:24 +00:00
return {
filename,
output
}
}
// Download a string to a file with a filename
export const downloadFile = (content, filename, contentType) => {
const a = document.createElement('a');
const file = new Blob([content], {
type: contentType
});
a.href = URL.createObjectURL(file);
a.download = filename;
a.click();
URL.revokeObjectURL(a.href);
};
2021-12-26 01:41:24 +00:00
export function canvasToPng(canvas, filename) {
let downloadLink = document.createElement('a');
downloadLink.setAttribute('download', filename);
canvas.toBlob(function (blob) {
let url = URL.createObjectURL(blob);
downloadLink.setAttribute('href', url);
downloadLink.click();
});
}
export const checkForGetRequest = async () => {
const asciiUrlCdn = new URL(location.href).searchParams.get('ascii');
if (asciiUrlCdn) {
const res = await fetch(`https://ascii.jewbird.live/${asciiUrlCdn}`, {
method: 'GET',
headers: {
Accept: 'text/plain',
},
});
const asciiData = await res.text();
parseMircAscii(asciiData, asciiUrlCdn);
return;
}
const asciiUrl = new URL(location.href).searchParams.get('ircwatch');
if (asciiUrl) {
const res = await fetch(`https://irc.watch/ascii/txt/${asciiUrl}`, {
method: 'GET',
headers: {
Accept: 'text/plain',
},
});
const asciiData = await res.text();
parseMircAscii(asciiData, asciiUrl);
return;
}
const haxAscii = new URL(location.href).searchParams.get('haxAscii');
if (haxAscii) {
const res = await fetch(`https://art.h4x.life/${haxAscii}`, {
method: 'GET',
headers: {
Accept: 'text/plain',
},
});
// Considers paths
const asciiName = haxAscii.split('/').pop();
const asciiData = await res.text();
parseMircAscii(asciiData, asciiName);
}
}
2021-08-04 02:47:17 +00:00
// Hashing algo to detect duplicate brushes
2021-08-06 11:00:35 +00:00
// from https://stackoverflow.com/questions/7616461/generate-a-hash-from-string-in-javascript
export const cyrb53 = function (str, seed = 1337) {
let h1 = 0xdeadbeef ^ seed,
h2 = 0x41c6ce57 ^ seed;
for (let i = 0, ch; i < str.length; i++) {
ch = str.charCodeAt(i);
h1 = Math.imul(h1 ^ ch, 2654435761);
h2 = Math.imul(h2 ^ ch, 1597334677);
}
h1 = Math.imul(h1 ^ (h1 >>> 16), 2246822507) ^ Math.imul(h2 ^ (h2 >>> 13), 3266489909);
h2 = Math.imul(h2 ^ (h2 >>> 16), 2246822507) ^ Math.imul(h1 ^ (h1 >>> 13), 3266489909);
return 4294967296 * (2097151 & h2) + (h1 >>> 0);
};
2021-08-07 06:10:52 +00:00
// Mostly plain text asciis wont have all their blocks
// so this will fix that
export const fillNullBlocks = function (height, width, layerData = null) {
2021-08-12 01:52:40 +00:00
// Probably used on irc import to make the blocks proper,
// especially with plain text ascii
2021-08-15 00:15:36 +00:00
if (layerData === null) {
var layers = [...store.getters.currentAsciiLayers]
} else {
var layers = [...layerData]
2021-08-12 01:52:40 +00:00
}
2021-08-15 00:15:36 +00:00
for (let i = 0; i <= layers.length - 1; i++) {
let blocks = layers[i].data;
for (let y = 0; y < height; y++) {
// New row
if (!blocks[y]) {
blocks[y] = [];
for (let x = 0; x < width; x++) {
2021-08-12 01:52:40 +00:00
blocks[y][x] = {
...emptyBlock
};
2021-08-07 02:41:47 +00:00
}
2021-08-15 00:15:36 +00:00
} else {
// no new rows but new cols
for (let x = 0; x < width; x++) {
if (blocks[y] && !blocks[y][x]) {
blocks[y][x] = {
...emptyBlock
};
}
}
2021-08-07 02:41:47 +00:00
}
}
2021-08-15 00:15:36 +00:00
// Update layer with new blocks
layers[i].data = [...blocks]
layers[i].width = width
layers[i].height = height
2021-08-07 02:41:47 +00:00
}
return [ ... layers]
2021-08-07 02:41:47 +00:00
}
2021-08-07 06:10:52 +00:00
// Sometimes if we copy blocks the initial Y values will be null
// and cause an error when trying to calculate width
2021-08-12 01:52:40 +00:00
// So we get the longest x length
2021-08-07 02:41:47 +00:00
export const getBlocksWidth = function (blocks) {
2021-08-12 01:52:40 +00:00
let maxWidth = 0;
2021-08-07 02:41:47 +00:00
2021-08-12 01:52:40 +00:00
for (let y = 0; y < blocks.length; y++) {
2021-08-07 02:41:47 +00:00
if (!blocks[y]) {
continue
}
2021-08-12 01:52:40 +00:00
if (blocks[y] && blocks[y].length > maxWidth) {
maxWidth = blocks[y].length
2021-08-07 02:41:47 +00:00
}
}
2021-08-12 01:52:40 +00:00
return maxWidth
2021-08-07 02:41:47 +00:00
}
2021-08-07 06:10:52 +00:00
// This removes the null blocks from our copy and paste
// to make sure it's centered better
2021-08-07 02:41:47 +00:00
export const filterNullBlocks = function (blocks) {
let newBlocks = [];
let y;
blocks = blocks.filter(function (item) {
return item !== null
});
for (y = 0; y < blocks.length; y++) {
newBlocks[y] = (blocks[y].filter(function (item) {
return item !== null
}))
2021-08-07 02:41:47 +00:00
}
return newBlocks
}
2021-08-14 06:41:42 +00:00
// Function to check if the left and top values are visible on the screen
export const checkVisible = function (bottom, top) {
var viewHeight = Math.max(
document.documentElement.clientHeight,
window.innerHeight
);
return !(bottom < 0 || top - viewHeight >= 0);
}
export const mergeLayers = function (blocks = null) {
let mergedLayers = [];
// Position of the meta array
let x = 0;
let y = 0;
let z = 0;
// Draws the actual rectangle
let canvasX = 0;
let canvasY = 0;
let curBlock = null;
for (y = 0; y < store.getters.currentAsciiLayers[0].height + 1; y++) {
canvasY = blockHeight * y;
if (!mergedLayers[y]) {
mergedLayers[y] = [];
}
for (x = 0; x < store.getters.currentAsciiLayers[0].width + 1; x++) {
canvasX = blockWidth * x;
curBlock = {
...emptyBlock
};
// Loop layers
for (z = store.getters.currentAsciiLayers.length - 1; z >= 0; z--) {
if (store.getters.currentAsciiLayers[z].visible === false) {
continue;
}
if (
store.getters.currentAsciiLayers[z] &&
store.getters.currentAsciiLayers[z].data &&
store.getters.currentAsciiLayers[z].data[y] &&
store.getters.currentAsciiLayers[z].data[y][x]
) {
2021-12-26 10:04:20 +00:00
if (curBlock.bg === undefined) {
curBlock.bg = store.getters.currentAsciiLayers[z].data[y][x].bg;
2021-08-28 02:41:31 +00:00
}
if (curBlock.fg === undefined) {
2021-08-28 02:41:31 +00:00
curBlock.fg = store.getters.currentAsciiLayers[z].data[y][x].fg;
2021-12-26 23:23:55 +00:00
}
2021-12-26 10:04:20 +00:00
if (curBlock.char === undefined) {
curBlock.char = store.getters.currentAsciiLayers[z].data[y][x].char;
2021-08-28 02:41:31 +00:00
}
2021-08-28 02:41:31 +00:00
continue;
}
2021-12-26 10:04:20 +00:00
// break;
}
2021-08-28 02:41:31 +00:00
mergedLayers[y][x] = {
...curBlock
}
}
}
2021-10-09 00:47:16 +00:00
return mergedLayers;
}
// Splash screen ascii encoded
export const splashAscii = JSON.parse(LZString.decompressFromEncodedURIComponent(
"NrDeCICMHNwLgIwBYA04Bms4E4C+KIZ5k1N5s0BjACwEMAnecACXH0KxIywvBoaYBLNgSidU3clTqM44AAQiOxCWRzSBcgA5KxK0jw2zwtXUUSrDfGUwA2Z8QanXN4AM4P9k9S+OL2ehZOPvzGAO6eQd68oUwAppFcajE2cvYB5klWsXKUiZbOOeAA9vnBKa4AtmXRRvE1yXVy-qKZBSGp4AAuDdmdpRmOtb5MLcpRjSNypoNek0UesxN9rnlLWYWdwuvtFcbbrUPznZC9m64H4xsdrow75U3gACZnN36ve0wAbh+PCL9TBQAoo9e7DIoJMHHVyLQ5zFbGUFw5bnfbAzoAO3RrlgUIRo2xxlOeNRTAAroShJS0tTnq8AMwkuAAJiZrOR13ZV3aXMCnLZAo5PMF3OCvLaYpFfOFQslsu84qOWEV8PgKpRLKlEoVWqVat1qs18rU6v5xuVBo1pplop15v19qNoFwAF0UGBpXLbSbLWbvRbHdavZ67f6HWGnSGfYHfTaowGI0HQ-HwynI9ro4nY8GMwm03hHQWI585OhaXdC48BpXAdUmSWgfXHkji49qLTITWimN848K63AZ2B0UZl3Oi8m7WO7SAHS0utj1wTmMrrOrtNJzMb7PJ3OpvfpvWHw2bvMH0-7o8X49Wndb893s9Xx+Xk8vm9+7frh-f58EV3umuiaPAAxK817Mo8ABC4GPJcG6PLiv4no8ADKsGAu2bJVhhRQUthgItl+wGAtWJF4bhnREeejywkBCGEZRrhkcRDFFAACkxxijuRVFcUw-Zsf0-FyFiBELOB74QVJMnI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