asciibird/src/components/BrushLibrary.vue

234 lines
6.4 KiB
Vue
Raw Normal View History

2021-08-06 01:51:58 +00:00
<template>
<div>
2021-08-06 04:00:21 +00:00
<vue-draggable-resizable
2021-08-07 02:41:47 +00:00
@dragstop="onDragStop"
@resizestop="onResize"
2021-08-14 06:41:42 +00:00
:grid="[blockWidth, blockHeight]"
:min-width="blockWidth * 35"
2021-08-07 02:41:47 +00:00
:max-width="blockWidth * 50"
:min-height="blockHeight * 15"
2021-08-07 02:41:47 +00:00
:max-height="blockHeight * 100"
:w="brushLibraryState.w"
:h="brushLibraryState.h"
:x="brushLibraryState.x"
:y="brushLibraryState.y"
ref="brushlibrarypanel"
2021-08-06 04:00:21 +00:00
>
<t-card class="h-full overflow-y-auto overflow-x-auto">
2021-08-06 11:00:35 +00:00
<t-button
type="button"
:class="`w-1/2 border-gray-200 bg-gray-500 text-sm ${
panel.tab === 0
2021-08-06 11:00:35 +00:00
? 'border-gray-900 bg-blue-500'
: 'border-gray-200 bg-gray-500'
}`"
@click="changeTab(0)"
2021-08-06 11:00:35 +00:00
>
<span class="material-icons relative top-2 pb-4">history</span> History
</t-button>
2021-08-06 04:00:21 +00:00
2021-08-06 11:00:35 +00:00
<t-button
type="button"
:class="`w-1/2 border-gray-200 bg-gray-500 text-sm ${
panel.tab === 1
2021-08-06 11:00:35 +00:00
? 'border-gray-900 bg-blue-500'
: 'border-gray-200 bg-gray-500'
}`"
@click="changeTab(1)"
2021-08-06 11:00:35 +00:00
>
<span class="material-icons relative top-2 pb-4">library_books</span> Library {{ libraryCount }}
</t-button>
2021-08-06 04:00:21 +00:00
2021-08-06 11:00:35 +00:00
<div class="flex">
<div v-if="panel.tab === 0">
<div v-for="(brush, key) in brushHistory" :key="key">
2021-08-14 06:41:42 +00:00
<t-card
class="hover:border-blue-900 border-gray-300 bg-gray-200 mt-2"
>
2021-08-06 11:00:35 +00:00
<BrushCanvas :blocks="decompressBlock(brush.blocks)" />
2021-08-06 04:00:21 +00:00
2021-08-06 11:00:35 +00:00
<t-button
type="button"
class="ab-rounded-button ml-1 mt-1"
2021-08-06 11:00:35 +00:00
@click="saveToLibrary(decompressBlock(brush.blocks))"
>
<span class="material-icons">save</span>
</t-button>
2021-08-06 11:00:35 +00:00
<t-button
type="button"
class="ab-rounded-button ml-1 mt-1"
@click="reuseBlocks(decompressBlock(brush.blocks))">
<span class="material-icons">brush</span>
</t-button>
<t-button
type="button"
class="ab-rounded-button ml-1 mt-1"
@click="removeFromHistory(decompressBlock(brush.blocks))"
>
<span class="material-icons">delete</span>
</t-button>
2021-08-06 11:00:35 +00:00
</t-card>
</div>
</div>
2021-08-06 04:00:21 +00:00
<div v-if="panel.tab === 1">
<div v-for="(brush, key) in brushLibrary" :key="key">
2021-08-06 11:00:35 +00:00
<t-card
2021-08-07 23:45:37 +00:00
:class="`hover:border-blue-900 border-gray-300 bg-gray-200 mt-2`"
2021-08-06 11:00:35 +00:00
>
<BrushCanvas :blocks="decompressBlock(brush.blocks)" />
2021-08-06 11:00:35 +00:00
<t-button
type="button"
class="ab-rounded-button ml-1 mt-1"
2021-08-06 11:00:35 +00:00
@click="removeFromLibrary(decompressBlock(brush.blocks))"
>
<span class="material-icons">delete</span>
</t-button>
2021-08-06 11:00:35 +00:00
<t-button
type="button"
class="ab-rounded-button ml-1 mt-1"
2021-08-06 11:00:35 +00:00
@click="reuseBlocks(decompressBlock(brush.blocks))"
>
<span class="material-icons">brush</span>
</t-button>
2021-08-06 11:00:35 +00:00
</t-card>
</div>
</div>
2021-08-06 04:00:21 +00:00
</div>
2021-08-06 11:00:35 +00:00
</t-card>
2021-08-06 04:00:21 +00:00
</vue-draggable-resizable>
2021-08-06 01:51:58 +00:00
</div>
</template>
2021-08-14 06:41:42 +00:00
<style scoped>
.buttons {
margin-top: 35px;
}
.ghost {
opacity: 0.5;
background: #c8ebfb;
}
</style>
2021-08-06 01:51:58 +00:00
<script>
2021-08-06 04:00:21 +00:00
import { mircColours99, blockWidth, blockHeight } from "../ascii";
2021-08-06 11:00:35 +00:00
import BrushCanvas from "./parts/BrushCanvas.vue";
import LZString from "lz-string";
2021-08-06 01:51:58 +00:00
export default {
name: "BrushLibrary",
2021-08-07 02:41:47 +00:00
created() {
this.panel.x = this.brushLibraryState.x;
this.panel.y = this.brushLibraryState.y;
this.panel.w = this.brushLibraryState.w;
this.panel.h = this.brushLibraryState.h;
this.panel.tab = this.brushLibraryState.tab;
2021-08-07 02:41:47 +00:00
},
2021-08-06 01:51:58 +00:00
data: () => ({
2021-08-07 02:41:47 +00:00
panel: {
w: 0,
h: 0,
x: 100,
y: 100,
visible: true,
tab: 1,
2021-08-14 06:41:42 +00:00
dragging: false,
2021-08-07 02:41:47 +00:00
},
2021-08-06 01:51:58 +00:00
}),
2021-08-06 04:00:21 +00:00
components: {
BrushCanvas,
},
props: ['yOffset'],
2021-08-06 01:51:58 +00:00
computed: {
2021-08-06 04:00:21 +00:00
blockWidth() {
2021-08-14 06:41:42 +00:00
return blockWidth * this.blockSizeMultiplier;
2021-08-06 04:00:21 +00:00
},
blockHeight() {
2021-08-14 06:41:42 +00:00
return blockHeight * this.blockSizeMultiplier;
},
blockSizeMultiplier() {
return this.$store.getters.blockSizeMultiplier;
2021-08-06 04:00:21 +00:00
},
2021-08-06 01:51:58 +00:00
currentAscii() {
return this.$store.getters.currentAscii;
},
2021-08-06 04:00:21 +00:00
brushHistory() {
return this.$store.getters.brushHistory;
2021-08-06 04:00:21 +00:00
},
brushLibrary() {
return this.$store.getters.brushLibrary;
},
2021-08-06 01:51:58 +00:00
mircColours() {
return mircColours99;
},
2021-08-06 04:00:21 +00:00
brushBlocks() {
return this.$store.getters.brushBlocks;
},
2021-08-07 02:41:47 +00:00
brushLibraryState() {
return this.$store.getters.brushLibraryState;
},
libraryCount() {
return this.brushLibrary.length > 0 ? `(${this.brushLibrary.length})` : '';
}
2021-08-06 01:51:58 +00:00
},
watch: {
yOffset(val) {
this.$refs.brushlibrarypanel.top = Number.parseInt(this.brushLibraryState.y+val)
}
},
2021-08-06 01:51:58 +00:00
methods: {
2021-08-06 04:00:21 +00:00
changeTab(tab) {
this.panel.tab = tab;
this.$store.commit("changeBrushLibraryState", this.panel);
2021-08-06 04:00:21 +00:00
},
decompressBlock(item) {
2021-08-06 11:00:35 +00:00
return JSON.parse(LZString.decompressFromUTF16(item));
2021-08-06 04:00:21 +00:00
},
reuseBlocks(value) {
2021-08-06 11:00:35 +00:00
this.$store.commit("brushBlocks", value);
this.$store.commit("changeTool", 4);
this.$toasted.show(`Applied brush from Library`, {
type: "success",
});
2021-08-06 04:00:21 +00:00
},
saveToLibrary(value) {
2021-08-06 11:00:35 +00:00
this.$store.commit("pushBrushLibrary", value);
this.$toasted.show(`Saved brush to Library`, {
type: "success",
});
2021-08-06 11:00:35 +00:00
},
removeFromLibrary(value) {
this.$store.commit("removeBrushLibrary", value);
this.$toasted.show(`Removed brush from Library`);
2021-08-06 11:00:35 +00:00
},
removeFromHistory(value) {
this.$store.commit("removeBrushHistory", value);
this.$toasted.show(`Removed brush from History`);
},
2021-08-07 02:41:47 +00:00
onResize(x, y, w, h) {
this.panel.x = x;
this.panel.y = y;
this.panel.w = w;
this.panel.h = h;
this.$store.commit("changeBrushLibraryState", this.panel);
2021-08-07 02:41:47 +00:00
},
onDragStop(x, y) {
this.panel.x = x;
this.panel.y = y;
this.$store.commit("changeBrushLibraryState", this.panel);
2021-08-07 02:41:47 +00:00
},
2021-08-06 01:51:58 +00:00
},
};
</script>