2020-12-27 02:42:26 +00:00
|
|
|
<template>
|
|
|
|
<div id="app">
|
|
|
|
<t-modal
|
|
|
|
name="create-ascii-modal"
|
|
|
|
header="Create new ASCII"
|
2021-01-16 03:03:14 +00:00
|
|
|
:clickToClose="false"
|
|
|
|
:escToClose="false"
|
2020-12-27 02:42:26 +00:00
|
|
|
@before-closed="closeNewASCII"
|
|
|
|
>
|
2021-03-31 23:29:55 +00:00
|
|
|
|
2021-01-30 02:33:11 +00:00
|
|
|
Width
|
2021-01-16 03:03:14 +00:00
|
|
|
<t-input
|
|
|
|
type="number"
|
|
|
|
name="width"
|
|
|
|
v-model="forms.createAscii.width"
|
2021-04-02 00:19:33 +00:00
|
|
|
min="1"
|
2021-01-16 03:03:14 +00:00
|
|
|
/>
|
2021-01-30 02:33:11 +00:00
|
|
|
|
|
|
|
Height
|
2021-01-16 03:03:14 +00:00
|
|
|
<t-input
|
|
|
|
type="number"
|
|
|
|
name="height"
|
|
|
|
v-model="forms.createAscii.height"
|
2021-04-02 00:19:33 +00:00
|
|
|
min="1"
|
2021-01-16 03:03:14 +00:00
|
|
|
/>
|
2021-01-30 02:33:11 +00:00
|
|
|
|
|
|
|
Title
|
2021-01-16 03:03:14 +00:00
|
|
|
<t-input
|
|
|
|
type="text"
|
|
|
|
name="title"
|
|
|
|
v-model="forms.createAscii.title"
|
|
|
|
max="128"
|
|
|
|
/>
|
2020-12-27 02:42:26 +00:00
|
|
|
|
|
|
|
<template v-slot:footer>
|
2021-01-16 03:03:14 +00:00
|
|
|
<div
|
|
|
|
class="flex justify-between"
|
|
|
|
@click="$modal.hide('create-ascii-modal')"
|
|
|
|
>
|
|
|
|
<t-button type="button"> Cancel </t-button>
|
|
|
|
<t-button type="button" @click="createNewASCII()"> Ok </t-button>
|
2020-12-27 02:42:26 +00:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
</t-modal>
|
|
|
|
|
2021-01-09 01:57:48 +00:00
|
|
|
<div>
|
2021-03-14 07:36:14 +00:00
|
|
|
<t-button @click="createClick()" class="ml-1">New ASCII</t-button>
|
2021-04-01 23:01:36 +00:00
|
|
|
<t-button @click="clearCache()" class="ml-1"
|
2021-03-30 10:42:30 +00:00
|
|
|
>Clear and Refresh</t-button
|
|
|
|
>
|
2021-03-14 07:36:14 +00:00
|
|
|
<t-button @click="startImport('mirc')" class="ml-1">Import mIRC</t-button>
|
2021-03-31 23:29:55 +00:00
|
|
|
<t-button @click="exportMirc()" class="ml-1" v-if="this.$store.getters.asciibirdMeta.length"
|
2021-03-30 08:36:53 +00:00
|
|
|
>Export ASCII to mIRC</t-button
|
|
|
|
>
|
2021-04-01 01:10:52 +00:00
|
|
|
<t-button @click="exportAsciibirdState()" class="ml-1" v-if="this.$store.getters.asciibirdMeta.length"
|
|
|
|
>Save Asciibird State</t-button
|
|
|
|
>
|
|
|
|
<t-button @click="startImport('asb')" class="ml-1"
|
|
|
|
>Load Asciibird State</t-button
|
|
|
|
>
|
2021-03-29 00:39:42 +00:00
|
|
|
<!-- <t-button @click="startImport('ansi')" class="ml-1">Import ANSI</t-button> -->
|
2021-01-16 03:03:14 +00:00
|
|
|
<input
|
|
|
|
type="file"
|
|
|
|
style="display: none"
|
|
|
|
ref="asciiInput"
|
2021-03-14 07:36:14 +00:00
|
|
|
@change="onImport()"
|
2021-01-16 03:03:14 +00:00
|
|
|
/>
|
|
|
|
|
|
|
|
<t-button
|
2021-03-31 23:29:55 +00:00
|
|
|
v-for="(value, key) in this.$store.getters.asciibirdMeta"
|
2021-01-16 03:03:14 +00:00
|
|
|
v-bind:key="key"
|
|
|
|
class="ml-1"
|
|
|
|
@click="changeTab(key, value)"
|
2021-01-30 02:33:11 +00:00
|
|
|
:disabled="false"
|
2021-01-16 03:03:14 +00:00
|
|
|
>
|
2021-03-29 00:39:42 +00:00
|
|
|
{{ value.title }}
|
2021-01-09 01:57:48 +00:00
|
|
|
</t-button>
|
|
|
|
|
2021-03-30 08:36:53 +00:00
|
|
|
<Toolbar
|
|
|
|
:canvas-x="canvasX"
|
|
|
|
:canvas-y="canvasY"
|
2021-03-31 23:29:55 +00:00
|
|
|
v-if="this.$store.getters.asciibirdMeta.length"
|
2021-03-30 08:36:53 +00:00
|
|
|
/>
|
|
|
|
<DebugPanel
|
|
|
|
:canvas-x="canvasX"
|
|
|
|
:canvas-y="canvasY"
|
2021-03-31 23:29:55 +00:00
|
|
|
v-if="this.$store.getters.asciibirdMeta.length"
|
2021-03-30 08:36:53 +00:00
|
|
|
/>
|
2021-03-31 23:29:55 +00:00
|
|
|
<Editor @coordsupdate="updateCoords" v-if="this.$store.getters.asciibirdMeta.length" />
|
2021-03-29 08:44:42 +00:00
|
|
|
|
2021-03-30 08:36:53 +00:00
|
|
|
<CharPicker v-if="$store.getters.getToolbarState.isChoosingChar" />
|
|
|
|
<ColourPicker
|
|
|
|
v-if="
|
|
|
|
$store.getters.getToolbarState.isChoosingFg ||
|
|
|
|
$store.getters.getToolbarState.isChoosingBg
|
|
|
|
"
|
|
|
|
/>
|
2021-04-02 02:07:49 +00:00
|
|
|
|
|
|
|
<!-- <AsciiCursor :mousex="dashboardX" :mousey="dashboardY" :z="500" /> -->
|
2021-01-09 01:57:48 +00:00
|
|
|
</div>
|
2020-12-27 02:42:26 +00:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
2021-03-31 23:29:55 +00:00
|
|
|
import Toolbar from './components/Toolbar.vue';
|
|
|
|
import DebugPanel from './components/DebugPanel.vue';
|
|
|
|
import Editor from './views/Editor.vue';
|
2021-03-29 01:50:33 +00:00
|
|
|
// import * as Anser from "anser";
|
2021-03-31 23:29:55 +00:00
|
|
|
import CharPicker from './components/parts/CharPicker.vue';
|
|
|
|
import ColourPicker from './components/parts/ColourPicker.vue';
|
2021-04-02 02:07:49 +00:00
|
|
|
import AsciiCursor from './components/parts/AsciiCursor.vue';
|
2021-04-01 23:01:36 +00:00
|
|
|
// import pako from 'pako';
|
2021-03-14 07:36:14 +00:00
|
|
|
|
2020-12-27 02:42:26 +00:00
|
|
|
export default {
|
2021-03-14 07:36:14 +00:00
|
|
|
async created() {
|
2021-03-31 23:29:55 +00:00
|
|
|
// Load from irc watch if present in the URL bar
|
|
|
|
const asciiUrl = new URL(location.href).searchParams.get('ircwatch');
|
2021-03-14 07:36:14 +00:00
|
|
|
if (asciiUrl) {
|
2021-03-31 23:29:55 +00:00
|
|
|
const res = await fetch(`https://irc.watch/ascii/txt/${asciiUrl}`);
|
|
|
|
const asciiData = await res.text();
|
2021-03-14 07:36:14 +00:00
|
|
|
this.mircAsciiImport(asciiData, asciiUrl);
|
2021-03-31 23:29:55 +00:00
|
|
|
window.location.href = '/';
|
2021-03-14 07:36:14 +00:00
|
|
|
}
|
2020-12-27 02:42:26 +00:00
|
|
|
},
|
2021-03-31 23:29:55 +00:00
|
|
|
components: {
|
2021-04-02 02:07:49 +00:00
|
|
|
Toolbar, DebugPanel, Editor, CharPicker, ColourPicker, AsciiCursor
|
2021-03-31 23:29:55 +00:00
|
|
|
},
|
|
|
|
name: 'Dashboard',
|
2020-12-27 02:42:26 +00:00
|
|
|
data: () => ({
|
|
|
|
forms: {
|
|
|
|
createAscii: {
|
|
|
|
width: 5,
|
|
|
|
height: 5,
|
2021-03-31 23:29:55 +00:00
|
|
|
title: 'ascii',
|
2020-12-27 02:42:26 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
currentTab: 1,
|
2021-03-29 05:10:31 +00:00
|
|
|
canvasX: null,
|
|
|
|
canvasY: null,
|
2021-04-02 02:07:49 +00:00
|
|
|
dashboardX: 0,
|
|
|
|
dashboardY: 0,
|
2021-04-01 01:10:52 +00:00
|
|
|
importType: null,
|
2020-12-27 02:42:26 +00:00
|
|
|
}),
|
|
|
|
methods: {
|
2021-03-29 05:10:31 +00:00
|
|
|
updateCoords(value) {
|
2021-03-30 08:36:53 +00:00
|
|
|
this.canvasX = value.x;
|
|
|
|
this.canvasY = value.y;
|
2021-03-29 05:10:31 +00:00
|
|
|
},
|
2021-03-14 07:36:14 +00:00
|
|
|
onImport() {
|
2021-01-23 02:50:32 +00:00
|
|
|
const { files } = this.$refs.asciiInput;
|
|
|
|
const filename = files[0].name;
|
2021-01-16 03:03:14 +00:00
|
|
|
const fileReader = new FileReader();
|
|
|
|
|
2021-04-01 01:10:52 +00:00
|
|
|
var _importType = this.importType
|
2021-03-31 23:29:55 +00:00
|
|
|
fileReader.addEventListener('load', () => {
|
2021-04-01 01:10:52 +00:00
|
|
|
|
|
|
|
switch(_importType) {
|
|
|
|
|
|
|
|
case 'asb':
|
|
|
|
this.importAsciibirdState(fileReader.result, filename)
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'mirc':
|
|
|
|
this.mircAsciiImport(fileReader.result, filename);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2021-03-14 07:36:14 +00:00
|
|
|
});
|
2021-04-01 01:10:52 +00:00
|
|
|
|
|
|
|
// This will fire the file reader 'load' event
|
|
|
|
const asciiImport = fileReader.readAsText(files[0]);
|
2021-03-14 07:36:14 +00:00
|
|
|
},
|
2021-04-01 01:10:52 +00:00
|
|
|
startImport(type) {
|
2021-03-31 23:29:55 +00:00
|
|
|
// For ANSI we'll need to add back in the
|
|
|
|
// type cariable here
|
2021-04-01 01:10:52 +00:00
|
|
|
this.importType = type
|
|
|
|
console.log(this.importType)
|
2021-03-14 07:36:14 +00:00
|
|
|
this.$refs.asciiInput.click();
|
|
|
|
},
|
2021-03-29 01:50:33 +00:00
|
|
|
// We can maybe try something different to import ANSI
|
|
|
|
// asniImport(contents, filename) {
|
|
|
|
// let ansiArray = contents.split("\n");
|
|
|
|
|
|
|
|
// let ansiWidth = 0;
|
|
|
|
|
|
|
|
// this.finalAscii = {
|
|
|
|
// width: false, // defined in: switch (curChar) case "\n":
|
|
|
|
// height: contents.split("\r\n").length,
|
|
|
|
// title: filename,
|
|
|
|
// key: this.$store.getters.nextTabValue,
|
|
|
|
// blockWidth: 8 * this.$store.getters.blockSizeMultiplier,
|
|
|
|
// blockHeight: 13 * this.$store.getters.blockSizeMultiplier,
|
|
|
|
// blocks: this.create2DArray(contents.split("\r\n").length),
|
|
|
|
// };
|
|
|
|
|
|
|
|
// for (let i = 0; i <= ansiArray.length - 1; i++) {
|
|
|
|
// if (ansiWidth > 0 && this.finalAscii.width === false) {
|
|
|
|
// this.finalAscii.width = ansiWidth;
|
|
|
|
// }
|
|
|
|
|
|
|
|
// ansiWidth = 0;
|
|
|
|
|
|
|
|
// for (let j = 0; j <= ansiArray[i].length - 1; j++) {
|
|
|
|
// let ansiParse = Anser.ansiToJson(ansiArray[i]);
|
|
|
|
|
|
|
|
// for (let l = 0; l <= ansiParse.length - 1; l++) {
|
|
|
|
// var contentArray = ansiParse[l].content.split("");
|
|
|
|
|
|
|
|
// var curBlock = {
|
2021-03-29 05:10:31 +00:00
|
|
|
// fg: this.mircColours.indexOf(`rgb(${ansiParse[l].fg})`),
|
|
|
|
// bg: this.mircColours.indexOf(`rgb(${ansiParse[l].bg})`),
|
2021-03-29 01:50:33 +00:00
|
|
|
// char: null,
|
|
|
|
// };
|
|
|
|
|
|
|
|
// // If we had no matches in our mIRC RGB lookup, then we have to try match
|
|
|
|
// // the ASNI colours to the best mIRC colour
|
|
|
|
|
|
|
|
// if (curBlock.fg === -1) {
|
|
|
|
// switch (ansiParse[l].fg) {
|
|
|
|
// case "187, 187, 0": // orangeish yellow
|
|
|
|
// curBlock.fg = 8;
|
|
|
|
// break;
|
|
|
|
|
|
|
|
// case "187, 0, 0": // red
|
|
|
|
// curBlock.fg = 4;
|
|
|
|
// break;
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
|
|
|
|
// if (curBlock.bg === -1) {
|
|
|
|
// switch (ansiParse[l].bg) {
|
|
|
|
// case "187, 187, 0": // orangeish yellow
|
|
|
|
// curBlock.bg = 8;
|
|
|
|
// break;
|
|
|
|
|
|
|
|
// case "187, 0, 0": // red
|
|
|
|
// curBlock.bg = 4;
|
|
|
|
// break;
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
|
|
|
|
// for (let k = 0; k <= contentArray.length - 1; k++) {
|
|
|
|
// if (contentArray[k] === "\r") {
|
|
|
|
// continue;
|
|
|
|
// }
|
|
|
|
|
2021-03-29 05:10:31 +00:00
|
|
|
// this.mircColours.indexOf(`rgb(${ansiParse[l].fg})`);
|
2021-03-29 01:50:33 +00:00
|
|
|
|
|
|
|
// curBlock.char = contentArray[k];
|
|
|
|
|
|
|
|
// this.finalAscii.blocks[i][ansiWidth] = JSON.parse(
|
|
|
|
// JSON.stringify(curBlock)
|
|
|
|
// );
|
|
|
|
|
|
|
|
// ansiWidth++;
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
|
|
|
|
// this.$store.commit("newAsciibirdMeta", this.finalAscii);
|
|
|
|
// },
|
2021-03-14 07:36:14 +00:00
|
|
|
mircAsciiImport(contents, filename) {
|
2021-03-31 23:29:55 +00:00
|
|
|
const MIRC_MAX_COLOURS = this.$store.getters.mircColours.length;
|
2021-03-14 07:36:14 +00:00
|
|
|
|
2021-03-29 05:10:31 +00:00
|
|
|
// The current state of the Colours
|
2021-03-14 07:36:14 +00:00
|
|
|
let curBlock = {
|
|
|
|
fg: null,
|
|
|
|
bg: null,
|
|
|
|
char: null,
|
|
|
|
};
|
|
|
|
|
|
|
|
// set asciiImport as the entire file contents as a string
|
2021-03-31 23:29:55 +00:00
|
|
|
const asciiImport = contents.split('\u0003\u0003').join('\u0003');
|
2021-03-14 07:36:14 +00:00
|
|
|
|
|
|
|
// This will end up in the asciibirdMeta
|
2021-03-31 23:29:55 +00:00
|
|
|
const finalAscii = {
|
2021-03-14 07:36:14 +00:00
|
|
|
width: false, // defined in: switch (curChar) case "\n":
|
2021-03-31 23:29:55 +00:00
|
|
|
height: asciiImport.split('\n').length,
|
2021-03-14 07:36:14 +00:00
|
|
|
title: filename,
|
|
|
|
key: this.$store.getters.nextTabValue,
|
|
|
|
blockWidth: 8 * this.$store.getters.blockSizeMultiplier,
|
|
|
|
blockHeight: 13 * this.$store.getters.blockSizeMultiplier,
|
2021-03-31 23:29:55 +00:00
|
|
|
blocks: this.create2DArray(asciiImport.split('\n').length),
|
2021-04-02 00:19:33 +00:00
|
|
|
x: 247, // the dragable ascii canvas x
|
|
|
|
y: 24, // the dragable ascii canvas y
|
2021-03-14 07:36:14 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// Turn the entire ascii string into an array
|
2021-03-31 23:29:55 +00:00
|
|
|
let asciiStringArray = asciiImport.split('');
|
2021-03-14 07:36:14 +00:00
|
|
|
|
|
|
|
// The proper X and Y value of the block inside the ASCII
|
|
|
|
let asciiX = 0;
|
|
|
|
let asciiY = 0;
|
|
|
|
|
2021-03-30 08:36:53 +00:00
|
|
|
// used to determine colours
|
|
|
|
let colourChar1 = null;
|
|
|
|
let colourChar2 = null;
|
2021-03-31 23:29:55 +00:00
|
|
|
let parsedColour = null;
|
2021-03-14 07:36:14 +00:00
|
|
|
|
2021-03-30 08:36:53 +00:00
|
|
|
// This variable just counts the amount of colour and char codes to minus
|
|
|
|
// to get the real width
|
2021-03-31 23:29:55 +00:00
|
|
|
let widthOfColCodes = 0;
|
2021-03-14 07:36:14 +00:00
|
|
|
|
2021-03-20 00:39:17 +00:00
|
|
|
while (asciiStringArray.length) {
|
2021-03-31 23:29:55 +00:00
|
|
|
const curChar = asciiStringArray[0];
|
2021-03-14 07:36:14 +00:00
|
|
|
|
|
|
|
// Defining a small finite state machine
|
|
|
|
// to detect the colour code
|
|
|
|
switch (curChar) {
|
2021-03-31 23:29:55 +00:00
|
|
|
case '\n':
|
2021-03-14 07:36:14 +00:00
|
|
|
// Reset the colours here on a new line
|
|
|
|
curBlock = {
|
|
|
|
fg: null,
|
|
|
|
bg: null,
|
|
|
|
char: null,
|
|
|
|
};
|
|
|
|
|
2021-03-31 23:29:55 +00:00
|
|
|
// the Y value of the ascii
|
2021-03-14 07:36:14 +00:00
|
|
|
asciiY++;
|
|
|
|
|
|
|
|
// We can determine the width at the end of the first line
|
2021-03-31 23:29:55 +00:00
|
|
|
// If for some reason like in aphex.txt the first line is
|
|
|
|
// trimmed it will trim the entire ascii!
|
|
|
|
if (!finalAscii.width) {
|
|
|
|
finalAscii.width = asciiImport.split('\n')[0].length - 1 - widthOfColCodes; // minus \n for the proper width
|
2021-03-14 07:36:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Resets the X value
|
|
|
|
asciiX = 0;
|
|
|
|
|
|
|
|
asciiStringArray.shift();
|
|
|
|
break;
|
|
|
|
|
2021-03-31 23:29:55 +00:00
|
|
|
case '\u0003':
|
|
|
|
// Remove the colour char
|
2021-03-14 07:36:14 +00:00
|
|
|
asciiStringArray.shift();
|
2021-03-31 23:29:55 +00:00
|
|
|
widthOfColCodes++;
|
2021-03-14 07:36:14 +00:00
|
|
|
|
2021-03-31 23:29:55 +00:00
|
|
|
// Attempt to work out bg
|
2021-03-30 08:36:53 +00:00
|
|
|
colourChar1 = `${asciiStringArray[0]}`;
|
|
|
|
colourChar2 = `${asciiStringArray[1]}`;
|
|
|
|
parsedColour = parseInt(`${colourChar1}${colourChar2}`);
|
2021-03-14 07:36:14 +00:00
|
|
|
|
2021-03-31 23:29:55 +00:00
|
|
|
// Work out the 01, 02 double digit codes
|
2021-03-31 01:14:33 +00:00
|
|
|
if (parseInt(colourChar1) === 0 && parseInt(colourChar2) >= 0) {
|
|
|
|
asciiStringArray.shift();
|
2021-03-31 23:29:55 +00:00
|
|
|
widthOfColCodes += 1;
|
2021-03-31 01:14:33 +00:00
|
|
|
}
|
|
|
|
|
2021-03-29 05:10:31 +00:00
|
|
|
if (isNaN(parsedColour)) {
|
2021-03-30 08:36:53 +00:00
|
|
|
curBlock.bg = parseInt(colourChar1);
|
2021-03-31 23:29:55 +00:00
|
|
|
widthOfColCodes += 1;
|
2021-03-27 04:54:44 +00:00
|
|
|
asciiStringArray.shift();
|
2021-03-31 23:29:55 +00:00
|
|
|
} else if (parsedColour <= MIRC_MAX_COLOURS && parsedColour >= 0) {
|
2021-03-29 05:10:31 +00:00
|
|
|
curBlock.fg = parseInt(parsedColour);
|
2021-03-31 23:29:55 +00:00
|
|
|
widthOfColCodes += parsedColour.toString().length;
|
2021-03-27 04:54:44 +00:00
|
|
|
|
|
|
|
asciiStringArray = asciiStringArray.slice(
|
2021-03-29 05:10:31 +00:00
|
|
|
parsedColour.toString().length,
|
2021-03-31 23:29:55 +00:00
|
|
|
asciiStringArray.length,
|
2021-03-27 04:54:44 +00:00
|
|
|
);
|
2021-03-14 07:36:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// No background colour
|
2021-03-31 23:29:55 +00:00
|
|
|
if (asciiStringArray[0] !== ',') {
|
2021-02-20 03:18:32 +00:00
|
|
|
break;
|
2021-03-14 07:36:14 +00:00
|
|
|
} else {
|
2021-03-20 09:59:32 +00:00
|
|
|
// Remove , from array
|
2021-03-14 07:36:14 +00:00
|
|
|
asciiStringArray.shift();
|
|
|
|
}
|
2021-02-20 02:16:45 +00:00
|
|
|
|
2021-03-31 23:29:55 +00:00
|
|
|
// Attempt to work out bg
|
2021-03-30 08:36:53 +00:00
|
|
|
colourChar1 = `${asciiStringArray[0]}`;
|
|
|
|
colourChar2 = `${asciiStringArray[1]}`;
|
|
|
|
parsedColour = parseInt(`${colourChar1}${colourChar2}`);
|
2021-03-20 09:59:32 +00:00
|
|
|
|
2021-03-29 00:39:42 +00:00
|
|
|
if (
|
2021-03-31 23:29:55 +00:00
|
|
|
!isNaN(colourChar1)
|
|
|
|
&& !isNaN(colourChar2)
|
|
|
|
&& parseInt(colourChar2) > parseInt(colourChar1)
|
|
|
|
&& !isNaN(parsedColour)
|
|
|
|
&& parseInt(parsedColour) < 10
|
2021-03-29 00:39:42 +00:00
|
|
|
) {
|
2021-03-30 08:36:53 +00:00
|
|
|
parsedColour = parseInt(colourChar2);
|
2021-03-29 00:39:42 +00:00
|
|
|
asciiStringArray.shift();
|
|
|
|
}
|
|
|
|
|
2021-03-29 05:10:31 +00:00
|
|
|
if (isNaN(parsedColour)) {
|
2021-03-30 08:36:53 +00:00
|
|
|
curBlock.bg = parseInt(colourChar1);
|
2021-03-31 23:29:55 +00:00
|
|
|
widthOfColCodes += 1;
|
2021-03-29 00:39:42 +00:00
|
|
|
asciiStringArray.shift();
|
2021-03-31 23:29:55 +00:00
|
|
|
} else if (parsedColour <= MIRC_MAX_COLOURS && parsedColour >= 0) {
|
2021-03-29 05:10:31 +00:00
|
|
|
curBlock.bg = parseInt(parsedColour);
|
2021-03-31 23:29:55 +00:00
|
|
|
widthOfColCodes += parsedColour.toString().length;
|
2021-02-20 02:16:45 +00:00
|
|
|
|
2021-03-29 00:39:42 +00:00
|
|
|
asciiStringArray = asciiStringArray.slice(
|
2021-03-29 05:10:31 +00:00
|
|
|
parsedColour.toString().length,
|
2021-03-31 23:29:55 +00:00
|
|
|
asciiStringArray.length,
|
2021-03-29 00:39:42 +00:00
|
|
|
);
|
2021-02-20 02:16:45 +00:00
|
|
|
|
2021-03-29 00:39:42 +00:00
|
|
|
break;
|
2021-03-14 07:36:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
curBlock.char = curChar;
|
|
|
|
asciiStringArray.shift();
|
|
|
|
asciiX++;
|
|
|
|
|
2021-03-31 23:29:55 +00:00
|
|
|
finalAscii.blocks[asciiY][asciiX - 1] = { ...curBlock };
|
2021-03-14 07:36:14 +00:00
|
|
|
break;
|
|
|
|
} // End Switch
|
|
|
|
} // End loop charPos
|
|
|
|
|
2021-03-31 23:29:55 +00:00
|
|
|
// Store the ASCII
|
|
|
|
this.$store.commit('newAsciibirdMeta', finalAscii);
|
2021-03-27 02:07:33 +00:00
|
|
|
|
2021-03-31 23:29:55 +00:00
|
|
|
// To show the ASCII after importing we get the last key
|
|
|
|
// from the asciiBirdMeta array
|
|
|
|
const keys = this.$store.getters.asciibirdMeta
|
2021-03-27 04:54:44 +00:00
|
|
|
.map((v, k) => k)
|
|
|
|
.filter((i) => i !== undefined);
|
2021-03-27 02:07:33 +00:00
|
|
|
|
2021-03-31 23:29:55 +00:00
|
|
|
// Set the current tab and pop the array for the last value
|
2021-03-27 02:07:33 +00:00
|
|
|
this.currentTab = keys.pop();
|
2021-03-31 23:29:55 +00:00
|
|
|
this.$store.commit('changeTab', this.currentTab);
|
|
|
|
|
|
|
|
// Update the browsers title to the ASCII filename
|
2021-03-29 00:39:42 +00:00
|
|
|
document.title = `asciibird - ${this.$store.getters.currentAscii.title}`;
|
2021-01-16 03:03:14 +00:00
|
|
|
},
|
2021-04-01 01:10:52 +00:00
|
|
|
importAsciibirdState(fileContents, fileName) {
|
|
|
|
// Import from a gzipped json file
|
2021-04-01 01:35:10 +00:00
|
|
|
// let input;
|
2021-04-01 01:10:52 +00:00
|
|
|
|
2021-04-01 01:35:10 +00:00
|
|
|
// try {
|
2021-04-01 23:01:36 +00:00
|
|
|
// // convert the incoming base64 -> binary
|
|
|
|
// const strData = fileContents;
|
|
|
|
|
|
|
|
// // split it into an array rather than a "string"
|
|
|
|
// const charData = strData.split('').map(function(x){return x.charCodeAt(0); });
|
2021-04-01 01:10:52 +00:00
|
|
|
|
2021-04-01 23:01:36 +00:00
|
|
|
// // var strData = String.fromCharCode.apply(null, pako.inflate(String.fromCharCode.apply(null, input).split("").map(function(x){return x.charCodeAt(0);})));
|
|
|
|
// input = pako.inflate(charData, { to: 'string' });
|
|
|
|
|
2021-04-01 01:35:10 +00:00
|
|
|
// console.log(input);
|
|
|
|
// } catch (err) {
|
|
|
|
// console.log(err);
|
|
|
|
// }
|
2021-04-01 01:10:52 +00:00
|
|
|
|
2021-04-01 23:01:36 +00:00
|
|
|
// console.log(fileContents)
|
|
|
|
|
|
|
|
// No gz for now unless can get the above working
|
2021-04-01 01:35:10 +00:00
|
|
|
this.$store.commit("changeState", Object.assign({},JSON.parse(fileContents)));
|
2021-04-01 01:10:52 +00:00
|
|
|
},
|
|
|
|
exportAsciibirdState() {
|
|
|
|
// Download to a gzipped json file
|
|
|
|
let output;
|
|
|
|
|
|
|
|
try {
|
|
|
|
// Make a gzipped JSON of the asciibird app state
|
2021-04-01 23:01:36 +00:00
|
|
|
// While making a gzip bellow works, had some trouble gunzipping in importAsciibirdState(fileContents, fileName)
|
2021-04-01 01:35:10 +00:00
|
|
|
// output = pako.gzip(JSON.stringify(this.$store.getters.getState), {level:"9"});
|
|
|
|
output = JSON.stringify(this.$store.getters.getState);
|
2021-04-01 23:01:36 +00:00
|
|
|
|
|
|
|
// Default timestamp for filename
|
|
|
|
let today = new Date();
|
|
|
|
let y = today.getFullYear();
|
|
|
|
let m = today.getMonth() + 1; // JavaScript months are 0-based.
|
|
|
|
let d = today.getDate();
|
|
|
|
let h = today.getHours();
|
|
|
|
let mi = today.getMinutes();
|
|
|
|
let s = today.getSeconds();
|
|
|
|
|
|
|
|
this.downloadToFile(output, `asciibird-${y}-${m}-${d}-${h}-${mi}-${s}.asb`, 'application/json');
|
2021-04-01 01:10:52 +00:00
|
|
|
} catch (err) {
|
|
|
|
console.log(err);
|
|
|
|
}
|
|
|
|
},
|
2021-03-30 08:36:53 +00:00
|
|
|
exportMirc() {
|
2021-03-31 23:29:55 +00:00
|
|
|
const { currentAscii } = this.$store.getters;
|
|
|
|
const output = [];
|
|
|
|
let curBlock = null;
|
|
|
|
let prevBlock = { bg: -1, fg: -1 };
|
2021-03-30 08:36:53 +00:00
|
|
|
|
|
|
|
for (let y = 0; y <= currentAscii.blocks.length - 1; y++) {
|
|
|
|
for (let x = 0; x <= currentAscii.blocks[y].length - 1; x++) {
|
|
|
|
curBlock = currentAscii.blocks[y][x];
|
2021-03-30 10:50:54 +00:00
|
|
|
|
2021-03-31 23:29:55 +00:00
|
|
|
// If we have a difference between our previous block
|
|
|
|
// we'll put a colour codes and continue as normal
|
2021-03-31 00:46:33 +00:00
|
|
|
if (curBlock.bg !== prevBlock.bg || curBlock.fg !== prevBlock.fg) {
|
2021-03-30 10:42:30 +00:00
|
|
|
Object.assign(curBlock, currentAscii.blocks[y][x]);
|
2021-03-31 23:29:55 +00:00
|
|
|
const zeroPad = (num, places) => String(num).padStart(places, '0');
|
2021-04-01 23:01:36 +00:00
|
|
|
output.push(`\u0003${zeroPad(curBlock.fg ?? this.$store.getstate.options.defaultFg, 2)},${zeroPad(curBlock.bg ?? this.$store.getstate.options.defaultBg, 2)}`);
|
2021-03-30 08:36:53 +00:00
|
|
|
}
|
|
|
|
|
2021-03-31 23:29:55 +00:00
|
|
|
// null .chars will end up as space
|
|
|
|
output.push(curBlock.char ?? ' ');
|
2021-03-30 08:36:53 +00:00
|
|
|
prevBlock = currentAscii.blocks[y][x];
|
|
|
|
}
|
|
|
|
|
2021-03-31 23:29:55 +00:00
|
|
|
// We can never have a -1 colour code so we'll always
|
|
|
|
// write one at the start of each line
|
2021-03-31 00:46:33 +00:00
|
|
|
prevBlock = { bg: -1, fg: -1 };
|
2021-03-31 23:29:55 +00:00
|
|
|
|
|
|
|
// New line except for the very last line
|
2021-03-30 08:36:53 +00:00
|
|
|
if (y < currentAscii.blocks.length - 1) {
|
2021-03-31 23:29:55 +00:00
|
|
|
output.push('\n');
|
2021-03-30 10:42:30 +00:00
|
|
|
}
|
2021-03-30 08:36:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Download to a txt file
|
2021-04-01 01:10:52 +00:00
|
|
|
// Check if txt already exists and append it
|
|
|
|
const filename = currentAscii.title.slice(currentAscii.title.length - 3) === 'txt' ? currentAscii.title : `${currentAscii.title}.txt`;
|
|
|
|
this.downloadToFile(output.join(''), filename, 'text/plain');
|
|
|
|
},
|
|
|
|
downloadToFile(content, filename, contentType) {
|
2021-03-30 08:36:53 +00:00
|
|
|
const downloadToFile = (content, filename, contentType) => {
|
2021-03-31 23:29:55 +00:00
|
|
|
const a = document.createElement('a');
|
2021-03-30 08:36:53 +00:00
|
|
|
const file = new Blob([content], { type: contentType });
|
|
|
|
|
|
|
|
a.href = URL.createObjectURL(file);
|
|
|
|
a.download = filename;
|
|
|
|
a.click();
|
|
|
|
|
|
|
|
URL.revokeObjectURL(a.href);
|
|
|
|
};
|
2021-04-01 01:10:52 +00:00
|
|
|
|
|
|
|
return downloadToFile(content, filename, contentType)
|
2021-03-30 08:36:53 +00:00
|
|
|
},
|
2020-12-27 02:42:26 +00:00
|
|
|
createClick() {
|
2021-03-31 23:29:55 +00:00
|
|
|
this.forms.createAscii.title = `New ASCII ${this.$store.getters.asciibirdMeta.length}`;
|
|
|
|
this.$modal.show('create-ascii-modal');
|
2020-12-27 02:42:26 +00:00
|
|
|
},
|
|
|
|
changeTab(key, value) {
|
|
|
|
// Update the tab index in vuex store
|
2021-03-13 03:30:58 +00:00
|
|
|
this.currentTab = key;
|
2021-03-31 23:29:55 +00:00
|
|
|
this.$store.commit('changeTab', key);
|
2020-12-27 02:42:26 +00:00
|
|
|
},
|
2021-01-30 02:33:11 +00:00
|
|
|
clearCache() {
|
|
|
|
localStorage.clear();
|
2021-03-31 23:29:55 +00:00
|
|
|
window.location.href = '/';
|
2021-01-30 02:33:11 +00:00
|
|
|
},
|
2020-12-27 02:42:26 +00:00
|
|
|
createNewASCII() {
|
|
|
|
const payload = {
|
|
|
|
title: this.forms.createAscii.title,
|
2021-03-31 23:29:55 +00:00
|
|
|
key: this.$store.getters.asciibirdMeta.length,
|
2020-12-27 02:42:26 +00:00
|
|
|
width: this.forms.createAscii.width,
|
|
|
|
height: this.forms.createAscii.height,
|
2021-03-27 02:07:33 +00:00
|
|
|
blockWidth: 8,
|
|
|
|
blockHeight: 13,
|
2021-04-02 00:19:33 +00:00
|
|
|
x: 247, // the dragable ascii canvas x
|
|
|
|
y: 24, // the dragable ascii canvas y
|
2020-12-27 02:42:26 +00:00
|
|
|
blocks: this.create2DArray(this.forms.createAscii.height),
|
|
|
|
};
|
|
|
|
|
|
|
|
// Push all the default ASCII blocks
|
2021-01-30 02:33:11 +00:00
|
|
|
for (let x = 0; x < payload.width; x++) {
|
|
|
|
for (let y = 0; y < payload.height; y++) {
|
|
|
|
payload.blocks[y].push({
|
2021-03-27 02:07:33 +00:00
|
|
|
bg: null,
|
|
|
|
fg: null,
|
|
|
|
char: null,
|
2020-12-27 02:42:26 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-31 23:29:55 +00:00
|
|
|
this.$store.commit('newAsciibirdMeta', payload);
|
|
|
|
this.$modal.hide('create-ascii-modal');
|
2020-12-27 02:42:26 +00:00
|
|
|
},
|
|
|
|
closeNewASCII({ params, cancel }) {
|
|
|
|
this.forms.createAscii.width = 5;
|
|
|
|
this.forms.createAscii.height = 5;
|
2021-03-31 23:29:55 +00:00
|
|
|
this.forms.createAscii.title = 'New ASCII';
|
2020-12-27 02:42:26 +00:00
|
|
|
},
|
|
|
|
create2DArray(rows) {
|
|
|
|
const arr = [];
|
|
|
|
|
|
|
|
for (let i = 0; i < rows; i++) {
|
|
|
|
arr[i] = [];
|
|
|
|
}
|
|
|
|
|
|
|
|
return arr;
|
|
|
|
},
|
2021-04-02 02:07:49 +00:00
|
|
|
captureMouse(event) {
|
|
|
|
// clientX/Y gives the coordinates relative to the viewport in CSS pixels.
|
|
|
|
// console.log("viewport", event.clientX);
|
|
|
|
// console.log("viewport", event.clientY);
|
|
|
|
|
|
|
|
// // pageX/Y gives the coordinates relative to the <html> element in CSS pixels.
|
|
|
|
// console.log("element", event.pageX);
|
|
|
|
// console.log("element", event.pageY);
|
|
|
|
|
|
|
|
this.dashboardX = event.pageX
|
|
|
|
this.dashboardY = event.pageY
|
|
|
|
|
|
|
|
// // screenX/Y gives the coordinates relative to the screen in device pixels.
|
|
|
|
// console.log("screen", event.screenX);
|
|
|
|
// console.log("screen", event.screenY);
|
|
|
|
}
|
2020-12-27 02:42:26 +00:00
|
|
|
},
|
|
|
|
};
|
|
|
|
</script>
|