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-01-16 03:03:14 +00:00
|
|
|
<!-- Main Menu -->
|
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"
|
|
|
|
max="3"
|
|
|
|
/>
|
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"
|
|
|
|
max="4"
|
|
|
|
/>
|
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>
|
|
|
|
<t-button @click="createClick()" class="ml-1">Add new ASCII</t-button>
|
2021-01-30 02:33:11 +00:00
|
|
|
<t-button @click="clearCache()" class="ml-1">Clear and Refresh</t-button>
|
2021-01-16 03:03:14 +00:00
|
|
|
<t-button @click="$refs.asciiInput.click()" class="ml-1"
|
|
|
|
>Import ASCII</t-button
|
|
|
|
>
|
2021-02-20 03:18:32 +00:00
|
|
|
|
2021-01-16 03:03:14 +00:00
|
|
|
<input
|
|
|
|
type="file"
|
|
|
|
style="display: none"
|
|
|
|
ref="asciiInput"
|
|
|
|
@change="onAsciiImport()"
|
|
|
|
/>
|
|
|
|
<h3>Content:</h3>
|
|
|
|
<pre id="msg"></pre>
|
|
|
|
|
|
|
|
<t-button
|
|
|
|
v-for="(value, key) in asciibirdMeta"
|
|
|
|
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-01-09 01:57:48 +00:00
|
|
|
{{ value.title }} ({{ value.width }} / {{ value.height }})
|
|
|
|
</t-button>
|
|
|
|
|
2021-02-06 01:22:16 +00:00
|
|
|
<Toolbar v-if="asciibirdMeta.length" />
|
2021-02-20 02:16:45 +00:00
|
|
|
<DebugPanel v-if="asciibirdMeta.length" />
|
2021-02-13 01:51:01 +00:00
|
|
|
|
2021-02-06 01:22:16 +00:00
|
|
|
<div class="border-gray-600">
|
2021-02-20 03:18:32 +00:00
|
|
|
<!-- <router-view /> -->
|
|
|
|
<Editor v-if="asciibirdMeta.length" />
|
2021-01-09 01:57:48 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
2020-12-27 02:42:26 +00:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
2021-02-06 01:22:16 +00:00
|
|
|
import Toolbar from "./components/Toolbar.vue";
|
2021-02-13 01:51:01 +00:00
|
|
|
import DebugPanel from "./components/DebugPanel.vue";
|
2021-02-20 03:18:32 +00:00
|
|
|
import Editor from "./views/Editor.vue";
|
2020-12-27 02:42:26 +00:00
|
|
|
export default {
|
|
|
|
created() {
|
2021-02-20 03:18:32 +00:00
|
|
|
this.mircColors = this.$store.getters.mircColors;
|
|
|
|
this.charCodes = this.$store.getters.charCodes;
|
|
|
|
this.asciibirdMeta = this.$store.getters.asciibirdMeta;
|
2020-12-27 02:42:26 +00:00
|
|
|
},
|
2021-02-20 03:18:32 +00:00
|
|
|
components: { Toolbar, DebugPanel, Editor },
|
2021-02-13 01:17:07 +00:00
|
|
|
name: "Dashboard",
|
2020-12-27 02:42:26 +00:00
|
|
|
data: () => ({
|
|
|
|
forms: {
|
|
|
|
createAscii: {
|
|
|
|
width: 5,
|
|
|
|
height: 5,
|
2021-02-13 01:17:07 +00:00
|
|
|
title: "ascii",
|
2020-12-27 02:42:26 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
formsDefault: null,
|
|
|
|
status: {
|
|
|
|
createNew: false,
|
|
|
|
},
|
2021-02-13 01:17:07 +00:00
|
|
|
text: "ASCII",
|
2020-12-27 02:42:26 +00:00
|
|
|
currentTab: 1,
|
|
|
|
asciibirdMeta: [],
|
2021-02-06 01:22:16 +00:00
|
|
|
mircColors: null,
|
|
|
|
charCodes: null,
|
|
|
|
|
2021-02-13 01:17:07 +00:00
|
|
|
asciiImport: "",
|
2021-01-16 03:03:14 +00:00
|
|
|
finalAscii: null,
|
|
|
|
asciiArray: [],
|
|
|
|
imageUrl: null,
|
2021-01-23 02:50:32 +00:00
|
|
|
parseColor: false,
|
2021-01-16 03:03:14 +00:00
|
|
|
colorCode: false,
|
|
|
|
importBlocks: null,
|
2020-12-27 02:42:26 +00:00
|
|
|
}),
|
|
|
|
methods: {
|
2021-01-16 03:03:14 +00:00
|
|
|
onAsciiImport() {
|
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();
|
|
|
|
this.asciiImport = fileReader.readAsText(files[0]);
|
|
|
|
|
2021-02-13 01:17:07 +00:00
|
|
|
fileReader.addEventListener("load", () => {
|
2021-02-20 03:18:32 +00:00
|
|
|
const MIRC_MAX_COLORS = this.$store.getters.mircColors.length;
|
2021-02-20 02:16:45 +00:00
|
|
|
|
|
|
|
let curBlock = {
|
|
|
|
fg: null,
|
|
|
|
bg: null,
|
|
|
|
char: null,
|
|
|
|
};
|
|
|
|
|
|
|
|
let emptyCurBlock = {
|
|
|
|
fg: null,
|
|
|
|
bg: null,
|
|
|
|
char: null,
|
|
|
|
};
|
|
|
|
|
2021-01-16 03:03:14 +00:00
|
|
|
this.asciiImport = fileReader.result;
|
|
|
|
|
2021-01-23 02:50:32 +00:00
|
|
|
this.finalAscii = {
|
2021-02-20 02:16:45 +00:00
|
|
|
width: 0, // defined later
|
2021-02-20 03:18:32 +00:00
|
|
|
height: this.asciiImport.split("\n").length + 1,
|
2021-01-16 03:03:14 +00:00
|
|
|
title: filename,
|
2021-01-30 02:33:11 +00:00
|
|
|
blockWidth: 16,
|
|
|
|
blockHeight: 26,
|
2021-01-23 02:50:32 +00:00
|
|
|
blocks: this.create2DArray(this.asciiImport.length),
|
2021-01-16 03:03:14 +00:00
|
|
|
};
|
|
|
|
|
2021-02-20 02:16:45 +00:00
|
|
|
let asciiStringArray = this.asciiImport.split("");
|
2021-01-16 03:03:14 +00:00
|
|
|
|
2021-02-20 02:16:45 +00:00
|
|
|
let asciiX = 0;
|
|
|
|
let asciiY = 0;
|
2021-01-16 03:03:14 +00:00
|
|
|
|
2021-02-20 03:18:32 +00:00
|
|
|
for (
|
|
|
|
let charPos = 0;
|
|
|
|
charPos < this.asciiImport.length - 1;
|
|
|
|
charPos++
|
|
|
|
) {
|
2021-02-20 02:16:45 +00:00
|
|
|
let curChar = asciiStringArray[charPos];
|
|
|
|
// Defining a small finite state machine
|
|
|
|
// Detect the colour code
|
2021-02-13 01:17:07 +00:00
|
|
|
|
2021-02-20 02:16:45 +00:00
|
|
|
switch (curChar) {
|
|
|
|
case "\n":
|
|
|
|
// Reset the colours here on a new line
|
|
|
|
curBlock = Object.assign(curBlock, emptyCurBlock);
|
|
|
|
asciiY++;
|
|
|
|
asciiX = 0;
|
|
|
|
break;
|
2021-02-13 01:17:07 +00:00
|
|
|
|
2021-02-20 02:16:45 +00:00
|
|
|
case "\u0003":
|
|
|
|
curBlock = Object.assign(curBlock, emptyCurBlock);
|
|
|
|
let firstColor = true;
|
|
|
|
// Pick up the colour here, then set it
|
|
|
|
charPos++;
|
2021-02-13 01:17:07 +00:00
|
|
|
|
2021-02-20 02:16:45 +00:00
|
|
|
for (let k = charPos; k <= k + 3; k++) {
|
2021-02-20 03:18:32 +00:00
|
|
|
if (
|
|
|
|
!isNaN(`${asciiStringArray[k]}${asciiStringArray[k + 1]}`) &&
|
|
|
|
`${asciiStringArray[k]}${asciiStringArray[k + 1]}` <=
|
|
|
|
MIRC_MAX_COLORS
|
|
|
|
) {
|
|
|
|
// Is valid number
|
|
|
|
curBlock.fg = `${asciiStringArray[k]}${
|
|
|
|
asciiStringArray[k + 1]
|
|
|
|
}`;
|
|
|
|
firstColor = false
|
|
|
|
} else {
|
|
|
|
//
|
|
|
|
curBlock.fg = `${asciiStringArray[k]}`;
|
|
|
|
firstColor = false
|
2021-02-13 01:17:07 +00:00
|
|
|
}
|
|
|
|
|
2021-02-20 02:16:45 +00:00
|
|
|
if (!firstColor && asciiStringArray[k] !== ",") {
|
2021-02-20 03:18:32 +00:00
|
|
|
if (
|
|
|
|
!isNaN(
|
|
|
|
`${asciiStringArray[k]}${asciiStringArray[k + 1]}`
|
|
|
|
) &&
|
|
|
|
`${asciiStringArray[k]}${asciiStringArray[k + 1]}` <=
|
|
|
|
MIRC_MAX_COLORS
|
|
|
|
) {
|
2021-02-20 02:16:45 +00:00
|
|
|
// Is valid number
|
2021-02-20 03:18:32 +00:00
|
|
|
curBlock.bg = `${asciiStringArray[k]}${
|
|
|
|
asciiStringArray[k + 1]
|
|
|
|
}`;
|
2021-02-13 01:17:07 +00:00
|
|
|
} else {
|
2021-02-20 02:16:45 +00:00
|
|
|
//
|
|
|
|
curBlock.bg = `${asciiStringArray[k]}`;
|
2021-02-13 01:17:07 +00:00
|
|
|
}
|
|
|
|
|
2021-02-20 03:18:32 +00:00
|
|
|
curBlock.char = `${asciiStringArray[k + 1]}`;
|
2021-02-20 02:16:45 +00:00
|
|
|
break;
|
2021-02-13 01:17:07 +00:00
|
|
|
}
|
2021-02-20 02:16:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Check colours
|
|
|
|
if (
|
2021-02-20 03:18:32 +00:00
|
|
|
!isNaN(curBlock.fg) &&
|
|
|
|
curBlock.fg >= 0 &&
|
|
|
|
curBlock.fg <= MIRC_MAX_COLORS &&
|
|
|
|
!isNaN(curBlock.bg) &&
|
|
|
|
curBlock.bg >= 0 &&
|
|
|
|
curBlock.bg <= MIRC_MAX_COLORS
|
2021-02-20 02:16:45 +00:00
|
|
|
) {
|
|
|
|
// Block is good
|
|
|
|
// console.log(`curBlock GOOD`, curBlock);
|
|
|
|
} else {
|
|
|
|
console.log(`curBlock BAD`, curBlock);
|
|
|
|
}
|
2021-01-30 02:33:11 +00:00
|
|
|
|
2021-02-20 02:16:45 +00:00
|
|
|
charPos++;
|
2021-02-20 03:18:32 +00:00
|
|
|
break;
|
2021-02-20 02:16:45 +00:00
|
|
|
|
2021-02-20 03:18:32 +00:00
|
|
|
default:
|
|
|
|
asciiX++;
|
|
|
|
break;
|
2021-02-20 02:16:45 +00:00
|
|
|
} // End Switch
|
|
|
|
|
2021-02-20 03:18:32 +00:00
|
|
|
curBlock.fg = this.mircColors[curBlock.fg - 1];
|
|
|
|
curBlock.bg = this.mircColors[curBlock.bg - 1];
|
2021-02-20 02:16:45 +00:00
|
|
|
|
|
|
|
this.finalAscii.blocks[asciiY][asciiX] = curBlock;
|
|
|
|
} // End loop charPos
|
|
|
|
|
2021-02-20 03:18:32 +00:00
|
|
|
// Presume if we get this far we have a colour state set
|
|
|
|
this.$store.commit("newAsciibirdMeta", this.finalAscii);
|
2021-02-20 02:16:45 +00:00
|
|
|
|
2021-02-20 03:18:32 +00:00
|
|
|
// End file upload
|
2021-02-13 01:17:07 +00:00
|
|
|
});
|
2021-02-20 02:16:45 +00:00
|
|
|
|
|
|
|
this.asciiImportFile = files[0];
|
2021-01-16 03:03:14 +00:00
|
|
|
},
|
2020-12-27 02:42:26 +00:00
|
|
|
createClick() {
|
2021-01-08 00:51:41 +00:00
|
|
|
this.forms.createAscii.title = `New ASCII ${this.asciibirdMeta.length}`;
|
2021-02-13 01:17:07 +00:00
|
|
|
this.$modal.show("create-ascii-modal");
|
2020-12-27 02:42:26 +00:00
|
|
|
},
|
|
|
|
changeTab(key, value) {
|
|
|
|
// Update the router title
|
2021-01-23 02:50:32 +00:00
|
|
|
// if (this.$router.params[0] !== key) {
|
2021-02-20 03:18:32 +00:00
|
|
|
// this.$router.push({ name: "editor", params: { ascii: key } });
|
2021-01-23 02:50:32 +00:00
|
|
|
// }/
|
2020-12-27 02:42:26 +00:00
|
|
|
|
|
|
|
// Update the tab index in vuex store
|
2021-02-13 01:17:07 +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-02-13 01:17:07 +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-01-08 00:47:08 +00:00
|
|
|
key: this.asciibirdMeta.length,
|
2020-12-27 02:42:26 +00:00
|
|
|
width: this.forms.createAscii.width,
|
|
|
|
height: this.forms.createAscii.height,
|
2021-01-30 02:33:11 +00:00
|
|
|
blockWidth: 16,
|
|
|
|
blockHeight: 26,
|
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-01-16 03:03:14 +00:00
|
|
|
bg: this.mircColors[
|
|
|
|
Math.floor(Math.random() * this.mircColors.length)
|
|
|
|
],
|
|
|
|
fg: this.mircColors[
|
|
|
|
Math.floor(Math.random() * this.mircColors.length)
|
|
|
|
],
|
|
|
|
char: this.charCodes[
|
|
|
|
Math.floor(Math.random() * this.charCodes.length)
|
|
|
|
],
|
2020-12-27 02:42:26 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-06 01:22:16 +00:00
|
|
|
// console.log('payload', payload);
|
2021-01-30 02:33:11 +00:00
|
|
|
|
2021-02-13 01:17:07 +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-02-13 01:17:07 +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;
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
</script>
|