asciibird/src/Dashboard.vue

453 lines
11 KiB
Vue
Raw Normal View History

<template>
<div id="app">
2021-04-24 00:42:33 +00:00
<NewAscii />
2021-08-17 00:24:41 +00:00
<EditAscii v-if="asciibirdMeta.length" />
<PasteAscii />
2021-04-17 01:58:45 +00:00
<KeyboardShortcuts
:selected-blocks="selectedBlocks"
:text-editing="textEditing"
2021-08-17 00:24:41 +00:00
:selecting="selecting"
@updatecanvas="updatecanvas"
/>
<context-menu
:display="showContextMenu"
ref="menu"
2021-08-17 00:24:41 +00:00
class="z-50"
>
2021-04-17 01:36:44 +00:00
<ul>
2021-04-24 00:20:11 +00:00
<li
2021-04-24 00:42:33 +00:00
@click="$store.commit('openModal', 'new-ascii')"
2021-04-24 00:20:11 +00:00
class="ml-1"
@contextmenu.prevent
>
New ASCII
</li>
<li
2021-08-17 00:24:41 +00:00
@click="$store.commit('openModal', 'edit-ascii')"
class="ml-1"
2021-08-17 00:24:41 +00:00
v-if="asciibirdMeta.length"
>
2021-08-17 00:24:41 +00:00
Edit Ascii
</li>
2021-08-17 00:24:41 +00:00
<li
@click="closeTab(currentTab)"
class="ml-1 border-b"
v-if="asciibirdMeta.length"
>
Close Ascii
</li>
<li
@click="startImport('mirc')"
class="ml-1"
>
2021-08-17 00:24:41 +00:00
Import mIRC from File
</li>
2021-08-04 03:21:06 +00:00
<li
@click="startExport('file')"
2021-08-17 00:24:41 +00:00
class="ml-1 border-b"
v-if="asciibirdMeta.length"
2021-04-24 00:20:11 +00:00
>
Export mIRC to File
</li>
<li
class="ml-1"
@click="$store.commit('openModal', 'paste-ascii')"
>
Import mIRC from Clipboard
</li>
2021-04-24 00:20:11 +00:00
<li
2021-08-17 00:24:41 +00:00
class="ml-1 border-b"
@click="startExport('clipboard')"
v-if="asciibirdMeta.length"
2021-04-17 01:36:44 +00:00
>
2021-04-24 00:20:11 +00:00
Export mIRC to Clipboard
2021-04-17 01:36:44 +00:00
</li>
<li
@click="exportAsciibirdState()"
class="ml-1"
v-if="asciibirdMeta.length"
2021-04-17 01:36:44 +00:00
>
Save Asciibird State
</li>
<li
@click="startImport('asb')"
class="ml-1"
>
Load Asciibird State
</li>
<li
2021-08-17 00:24:41 +00:00
@click="clearCache()"
class="ml-1"
>
2021-08-17 00:24:41 +00:00
Reset State
</li>
2021-04-17 01:36:44 +00:00
</ul>
</context-menu>
<span
@mouseup.right="openContextMenu"
@contextmenu.prevent
style="width: 100%; height: 100%; position: absolute; z-index: -1"
2021-08-04 03:21:06 +00:00
/>
2021-04-17 01:36:44 +00:00
<input
type="file"
style="display: none"
ref="asciiInput"
@change="onImport()"
>
2021-04-17 01:36:44 +00:00
<template v-if="asciibirdMeta.length">
2021-08-17 00:24:41 +00:00
<div class="bg-gray-500 z-50">
2021-08-16 07:03:53 +00:00
<t-button
class="p-1 rounded-xl"
@click="openContextMenu"
>
:::
2021-08-17 00:24:41 +00:00
</t-button>
2021-08-16 07:03:53 +00:00
2021-08-17 00:24:41 +00:00
<span
v-for="(value, key) in asciibirdMeta"
:key="key"
class="mr-2 z-50"
>
2021-08-12 02:22:29 +00:00
<t-button
2021-08-17 00:24:41 +00:00
class="p-1 z-50"
:class="buttonStyle(key)"
@click="changeTab(key, value)"
2021-08-12 02:22:29 +00:00
>
2021-08-17 00:24:41 +00:00
{{ value.title }}
<t-button
class="z-50"
@click="closeTab(key)"
>
X
</t-button>
</t-button>
2021-08-17 00:24:41 +00:00
</span>
2021-08-16 07:03:53 +00:00
</div>
2021-01-09 01:57:48 +00:00
<Toolbar
:canvas-x="canvasX"
:canvas-y="canvasY"
2021-08-17 00:24:41 +00:00
class="z-10"
/>
<DebugPanel
:canvas-x="canvasX"
:canvas-y="canvasY"
v-if="debugPanelState.visible"
2021-08-17 00:24:41 +00:00
class="z-10"
/>
2021-08-17 00:24:41 +00:00
<Editor
@coordsupdate="updateCoords"
@selectedblocks="selectedblocks"
@textediting="textediting"
:update-canvas="updateCanvas"
2021-08-17 00:24:41 +00:00
@selecting="updateSelecting"
class="z-10"
/>
2021-03-29 08:44:42 +00:00
2021-08-17 00:24:41 +00:00
<CharPicker
v-if="toolbarState.isChoosingChar"
class="z-10"
/>
2021-03-30 08:36:53 +00:00
<ColourPicker
v-if="toolbarState.isChoosingFg || toolbarState.isChoosingBg"
2021-08-17 00:24:41 +00:00
class="z-10"
2021-03-30 08:36:53 +00:00
/>
2021-08-06 04:00:21 +00:00
2021-08-17 00:24:41 +00:00
<BrushLibrary
v-if="brushLibraryState.visible"
class="z-10"
/>
<BrushPreview class="z-10" />
<LayersLibrary class="z-10" />
2021-04-17 01:36:44 +00:00
</template>
<template v-else>
<div
class="
absolute
top-1/2
left-1/2
transform
-translate-x-1/2 -translate-y-1/2
text-center
"
@mouseup.right="openContextMenu"
@contextmenu.prevent
>
<h1 class="text-4xl">
ASCIIBIRD
</h1>
<h3>Right click to start</h3>
<BrushCanvas :blocks="splashAscii" />
2021-04-17 01:36:44 +00:00
</div>
</template>
</div>
</template>
<script>
import LZString from "lz-string";
import Toolbar from "./components/Toolbar.vue";
import DebugPanel from "./components/DebugPanel.vue";
2021-08-06 04:00:21 +00:00
import BrushLibrary from "./components/BrushLibrary.vue";
import LayersLibrary from "./components/LayersLibrary.vue";
import Editor from "./views/Editor.vue";
import CharPicker from "./components/parts/CharPicker.vue";
import ColourPicker from "./components/parts/ColourPicker.vue";
import ContextMenu from "./components/parts/ContextMenu.vue";
import NewAscii from "./components/modals/NewAscii.vue";
import EditAscii from "./components/modals/EditAscii.vue";
import PasteAscii from "./components/modals/PasteAscii.vue";
import BrushCanvas from "./components/parts/BrushCanvas.vue";
2021-08-14 06:41:42 +00:00
import BrushPreview from "./components/parts/BrushPreview.vue";
import KeyboardShortcuts from "./components/parts/KeyboardShortcuts.vue";
import {
parseMircAscii,
toolbarIcons,
exportMirc,
downloadFile,
checkForGetRequest,
splashAscii,
} from "./ascii";
export default {
async created() {
2021-03-31 23:29:55 +00:00
// Load from irc watch if present in the URL bar
checkForGetRequest();
},
2021-03-31 23:29:55 +00:00
components: {
2021-04-17 01:36:44 +00:00
Toolbar,
DebugPanel,
Editor,
CharPicker,
ColourPicker,
2021-04-24 00:20:11 +00:00
ContextMenu,
NewAscii,
EditAscii,
PasteAscii,
BrushLibrary,
BrushCanvas,
2021-08-14 06:41:42 +00:00
BrushPreview,
KeyboardShortcuts,
LayersLibrary
2021-03-31 23:29:55 +00:00
},
name: "Dashboard",
data: () => ({
2021-03-29 05:10:31 +00:00
canvasX: null,
canvasY: null,
2021-04-02 02:07:49 +00:00
dashboardX: 0,
dashboardY: 0,
importType: null,
2021-04-17 01:36:44 +00:00
showContextMenu: false,
selectedBlocks: null,
textEditing: null,
updateCanvas: false,
2021-08-17 00:24:41 +00:00
selecting: null,
}),
computed: {
splashAscii() {
return splashAscii;
},
2021-04-03 03:13:03 +00:00
currentTool() {
return toolbarIcons[this.$store.getters.currentTool] ?? null;
2021-04-03 03:13:03 +00:00
},
icon() {
2021-04-17 01:36:44 +00:00
return [
this.currentTool.fa ?? "fas",
this.currentTool.icon ?? "mouse-pointer",
2021-04-17 01:36:44 +00:00
];
2021-04-03 03:13:03 +00:00
},
options() {
return this.$store.getters.options;
},
canFg() {
return this.$store.getters.isTargettingFg;
},
canBg() {
return this.$store.getters.isTargettingBg;
},
canText() {
return this.$store.getters.isTargettingChar;
},
currentFg() {
return this.$store.getters.currentFg;
},
currentBg() {
return this.$store.getters.currentBg;
},
currentChar() {
2021-08-06 01:51:58 +00:00
return this.$store.getters.currentChar;
},
toolbarState() {
return this.$store.getters.toolbarState;
},
asciibirdMeta() {
return this.$store.getters.asciibirdMeta;
},
debugPanelState() {
return this.$store.getters.debugPanel;
},
2021-08-07 02:41:47 +00:00
brushLibraryState() {
return this.$store.getters.brushLibraryState;
},
currentAscii() {
return this.$store.getters.currentAscii;
},
2021-08-16 07:03:53 +00:00
currentTab() {
return this.$store.getters.currentTab;
2021-08-12 02:22:29 +00:00
},
},
methods: {
2021-08-16 07:03:53 +00:00
buttonStyle(key) {
return (this.currentTab === key)
? `text-sm pl-1 p-1 h-10 text-white border border-transparent shadow-sm hover:bg-blue-500 bg-gray-900`
: `text-sm pl-1 p-1 h-10 text-white border border-transparent shadow-sm hover:bg-blue-500 bg-gray-400`;
},
2021-04-17 01:36:44 +00:00
openContextMenu(e) {
2021-06-19 01:34:31 +00:00
e.preventDefault();
2021-04-17 01:36:44 +00:00
this.$refs.menu.open(e);
},
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
},
selectedblocks(value) {
this.selectedBlocks = value
},
2021-08-17 00:24:41 +00:00
updateSelecting(value) {
this.selecting = value
},
textediting(value) {
this.textEditing = value
},
updatecanvas() {
this.updateCanvas = !this.updateCanvas
},
async 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-08-04 03:21:06 +00:00
const fileType = this.importType;
fileReader.addEventListener("load", () => {
2021-08-04 03:21:06 +00:00
switch (fileType) {
case "asb":
2021-04-03 03:13:03 +00:00
this.importAsciibirdState(fileReader.result, filename);
break;
2021-08-04 03:21:06 +00:00
default:
case "mirc":
parseMircAscii(fileReader.result, filename);
break;
}
});
// This will fire the file reader 'load' event
2021-08-04 03:21:06 +00:00
fileReader.readAsText(files[0]);
},
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-03 03:13:03 +00:00
this.importType = type;
// console.log(this.importType);
this.$refs.asciiInput.click();
},
importAsciibirdState(fileContents) {
2021-08-04 03:21:06 +00:00
const contents = JSON.parse(
LZString.decompressFromEncodedURIComponent(fileContents)
2021-06-19 00:26:23 +00:00
);
this.$store.commit("changeState", { ...contents });
},
exportAsciibirdState() {
let output;
try {
2021-06-19 00:26:23 +00:00
output = LZString.compressToEncodedURIComponent(
JSON.stringify(this.$store.getters.state)
2021-06-19 00:26:23 +00:00
);
// Default timestamp for filename
2021-04-03 03:13:03 +00:00
const today = new Date();
const y = today.getFullYear();
const m = today.getMonth() + 1; // JavaScript months are 0-based.
const d = today.getDate();
const h = today.getHours();
const mi = today.getMinutes();
const s = today.getSeconds();
downloadFile(
2021-04-17 01:36:44 +00:00
output,
`asciibird-${y}-${m}-${d}-${h}-${mi}-${s}.asb`,
"application/gzip"
2021-04-17 01:36:44 +00:00
);
} catch (err) {
2021-08-12 02:22:29 +00:00
this.$toasted.show(err, {
type: "error",
});
}
},
startExport(type) {
let ascii = exportMirc();
2021-04-24 00:20:11 +00:00
switch (type) {
case "clipboard":
this.$copyText(ascii.output.join("")).then(
2021-08-04 03:21:06 +00:00
(e) => {
2021-08-12 02:22:29 +00:00
this.$toasted.show("Copied mIRC to clipboard!", {
type: "success",
});
2021-06-19 00:26:23 +00:00
},
2021-08-04 03:21:06 +00:00
(e) => {
2021-08-12 02:22:29 +00:00
this.$toasted.show("Error when copying mIRC to clipboard!", {
type: "error",
});
}
2021-06-19 00:26:23 +00:00
);
2021-04-24 00:20:11 +00:00
break;
default:
case "file":
downloadFile(ascii.output.join(""), ascii.filename, "text/plain");
2021-04-24 00:20:11 +00:00
break;
}
},
2021-08-04 03:21:06 +00:00
changeTab(key) {
// Update the tab index in vuex store
this.$store.commit("changeTab", key);
},
closeTab(key) {
this.$dialog
.confirm({
2021-08-12 02:22:29 +00:00
title: `Close ${this.asciibirdMeta[key].title}?`,
text: "This action cannot be undone and the ASCII will be gone.",
icon: "info",
})
.then((result) => {
if (result.isOk) {
this.$store.commit("closeTab", key);
}
});
},
2021-01-30 02:33:11 +00:00
clearCache() {
localStorage.clear();
window.location.href = "/";
2021-01-30 02:33:11 +00:00
},
2021-04-02 02:07:49 +00:00
captureMouse(event) {
2021-04-03 03:13:03 +00:00
this.dashboardX = event.pageX;
this.dashboardY = event.pageY;
},
},
};
</script>