2020-12-19 01:27:50 +00:00
|
|
|
<template>
|
2020-12-27 02:42:26 +00:00
|
|
|
<div>
|
2021-01-02 01:52:44 +00:00
|
|
|
<h1>
|
|
|
|
{{ currentAsciibirdMeta.title }} ({{ currentAsciibirdMeta.width }} /
|
|
|
|
{{ currentAsciibirdMeta.height }})
|
|
|
|
</h1>
|
2021-01-09 01:57:48 +00:00
|
|
|
<!-- <pre><small>{{ JSON.stringify(currentAsciibirdMeta) }}</small></pre> -->
|
|
|
|
|
|
|
|
<!-- @mousedown="processMouseDown"
|
|
|
|
@mousemove="processMouseMove"
|
|
|
|
@mouseup="processMouseUp" -->
|
2020-12-27 02:42:26 +00:00
|
|
|
|
2021-01-02 01:52:44 +00:00
|
|
|
<div>
|
|
|
|
<canvas
|
|
|
|
:ref="generateCanvasId"
|
|
|
|
:id="generateCanvasId"
|
2021-01-09 01:57:48 +00:00
|
|
|
:width=canvas.width
|
|
|
|
:height=canvas.height
|
2021-01-02 01:52:44 +00:00
|
|
|
v-bind:class="dataFieldClass"
|
2021-01-07 23:32:19 +00:00
|
|
|
class="border-gray-500"
|
2021-01-09 01:57:48 +00:00
|
|
|
style="border-width: 2px;"
|
2021-01-02 01:52:44 +00:00
|
|
|
></canvas>
|
|
|
|
|
2021-01-09 01:57:48 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2021-01-02 01:52:44 +00:00
|
|
|
<!-- <span v-for="(yValue, y) in currentAsciibirdMeta.blocks" :key="y">
|
2020-12-27 02:42:26 +00:00
|
|
|
<span v-for="(xValue, x) in currentAsciibirdMeta.blocks" :key="x">
|
|
|
|
|
2021-01-02 01:52:44 +00:00
|
|
|
<Block :data="currentAsciibirdMeta.blocks[y][x]" v-if="currentAsciibirdMeta.blocks.length" :blockWidth="currentAsciibirdMeta.blockWidth" :blockHeight="currentAsciibirdMeta.blockHeight" />
|
2020-12-27 02:42:26 +00:00
|
|
|
|
|
|
|
</span>
|
2021-01-02 01:52:44 +00:00
|
|
|
</span> -->
|
2020-12-27 02:42:26 +00:00
|
|
|
</div>
|
2020-12-19 01:27:50 +00:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
2021-01-02 01:52:44 +00:00
|
|
|
<style>
|
|
|
|
body {
|
|
|
|
margin: 2rem;
|
|
|
|
background: #eee;
|
|
|
|
}
|
|
|
|
|
|
|
|
#canvas {
|
|
|
|
background: white;
|
|
|
|
box-shadow: 0px 2px 3px rgba(0, 0, 0, 0.2);
|
|
|
|
}
|
|
|
|
</style>
|
|
|
|
|
2020-12-19 01:27:50 +00:00
|
|
|
<script>
|
2020-12-27 02:42:26 +00:00
|
|
|
import Block from '../components/Block.vue';
|
|
|
|
|
2020-12-19 01:27:50 +00:00
|
|
|
export default {
|
|
|
|
name: 'Editor',
|
2020-12-27 02:42:26 +00:00
|
|
|
components: { Block },
|
2021-01-02 01:52:44 +00:00
|
|
|
mounted() {
|
2020-12-27 02:42:26 +00:00
|
|
|
this.currentAsciibirdMeta = this.$store.state.asciibirdMeta[0];
|
2021-01-07 23:32:19 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2021-01-02 01:52:44 +00:00
|
|
|
},
|
|
|
|
created() {
|
|
|
|
|
2020-12-27 02:42:26 +00:00
|
|
|
},
|
|
|
|
data: () => ({
|
|
|
|
text: 'ASCII',
|
|
|
|
currentAsciibirdMeta: null,
|
2021-01-02 01:52:44 +00:00
|
|
|
data: {
|
|
|
|
message: 'Hello Vue!',
|
|
|
|
vueCanvas: null,
|
|
|
|
},
|
|
|
|
ctx: null,
|
|
|
|
selectionMode: false,
|
|
|
|
startPosition: {
|
|
|
|
x: null,
|
|
|
|
y: null,
|
|
|
|
},
|
2021-01-09 01:57:48 +00:00
|
|
|
canvas: {
|
|
|
|
width: 2048 ,
|
|
|
|
height: 2048
|
|
|
|
},
|
2020-12-27 02:42:26 +00:00
|
|
|
}),
|
|
|
|
computed: {
|
|
|
|
getFullPath() {
|
|
|
|
return this.$route.path;
|
|
|
|
},
|
2021-01-02 01:52:44 +00:00
|
|
|
generateCanvasId() {
|
2021-01-07 23:32:19 +00:00
|
|
|
return `canvas${this.currentAsciibirdMeta.key}`;
|
2021-01-02 01:52:44 +00:00
|
|
|
},
|
2020-12-27 02:42:26 +00:00
|
|
|
},
|
|
|
|
watch: {
|
|
|
|
getFullPath() {
|
2021-01-02 01:52:44 +00:00
|
|
|
// console.log(this);
|
2021-01-09 01:57:48 +00:00
|
|
|
this.onChangeTab();
|
2020-12-27 02:42:26 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
methods: {
|
2021-01-02 01:52:44 +00:00
|
|
|
dataFieldClass(event) {
|
|
|
|
this.ctx = event.currentTarget.id;
|
|
|
|
console.log(this.ctx);
|
|
|
|
},
|
2021-01-09 01:57:48 +00:00
|
|
|
onChangeTab() {
|
|
|
|
|
|
|
|
// Get the asciimeta index from the route URL
|
2021-01-02 01:52:44 +00:00
|
|
|
this.currentAsciibirdMeta = this.$store.state.asciibirdMeta[
|
|
|
|
this.$route.params.ascii.split('/').join('')
|
|
|
|
];
|
2021-01-07 23:32:19 +00:00
|
|
|
|
2021-01-08 00:47:08 +00:00
|
|
|
// I dono some routs bs or some bs needs -1 to make it all work
|
|
|
|
let currentRefCanvas =`canvas${this.currentAsciibirdMeta.key-1}`;
|
2021-01-07 23:32:19 +00:00
|
|
|
|
2021-01-09 01:57:48 +00:00
|
|
|
// this.canvas.width = this.currentAsciibirdMeta.blocks.length * this.currentAsciibirdMeta.blockWidth
|
|
|
|
// this.canvas.height = this.currentAsciibirdMeta.blocks.length * this.currentAsciibirdMeta.blockHeight
|
|
|
|
|
2021-01-08 00:47:08 +00:00
|
|
|
console.log({ generateCanvasId: this.generateCanvasId, all_refs: this.$refs, current_canvas_ref: this.$refs[currentRefCanvas] })
|
|
|
|
|
|
|
|
if (this.$refs[currentRefCanvas]) {
|
|
|
|
this.ctx = this.$refs[currentRefCanvas].getContext("2d")
|
2021-01-07 23:32:19 +00:00
|
|
|
console.log('current ctx', this.ctx)
|
2021-01-09 01:57:48 +00:00
|
|
|
|
|
|
|
this.redrawCanvas()
|
2021-01-07 23:53:28 +00:00
|
|
|
} else {
|
2021-01-08 00:47:08 +00:00
|
|
|
console.log("Warning: could not find asciibird meta key " + currentRefCanvas)
|
2021-01-07 23:32:19 +00:00
|
|
|
}
|
2021-01-02 01:52:44 +00:00
|
|
|
},
|
2021-01-09 01:57:48 +00:00
|
|
|
redrawCanvas() {
|
|
|
|
console.log("Canvas redraw")
|
|
|
|
|
|
|
|
this.ctx.clearRect(0, 0, this.canvas.width, this.canvas.height)
|
|
|
|
|
|
|
|
if (this.currentAsciibirdMeta.blocks.length) {
|
|
|
|
|
|
|
|
let blockWidth = this.currentAsciibirdMeta.blockWidth
|
|
|
|
let blockHeight = this.currentAsciibirdMeta.blockHeight
|
|
|
|
|
|
|
|
let h = 0;
|
|
|
|
let w = 0;
|
|
|
|
let x = 0;
|
|
|
|
let y = 0;
|
|
|
|
let blockX = 0;
|
|
|
|
let blockY = 0;
|
|
|
|
let curBlock = undefined;
|
|
|
|
|
|
|
|
this.ctx.font = "8px Mono";
|
|
|
|
|
|
|
|
for(y = 0; y < this.currentAsciibirdMeta.blocks.length; y++) {
|
|
|
|
blockY = y * blockHeight
|
|
|
|
w = blockWidth
|
|
|
|
|
|
|
|
for(x = 0; x < this.currentAsciibirdMeta.blocks[y].length; x++) {
|
|
|
|
// console.log({ x, y, meta: JSON.stringify(this.currentAsciibirdMeta.blocks[y][x]) });
|
|
|
|
|
|
|
|
curBlock = this.currentAsciibirdMeta.blocks[y][x];
|
|
|
|
|
|
|
|
blockX = x * blockWidth
|
|
|
|
h = blockHeight
|
|
|
|
|
|
|
|
this.ctx.fillStyle = curBlock.bg
|
|
|
|
this.ctx.fillRect(blockX, blockY, blockWidth, blockHeight);
|
|
|
|
this.ctx.fillStyle = curBlock.fg
|
|
|
|
this.ctx.fillText( curBlock.char, blockX + 2 , blockY - 3 );
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
console.log(JSON.stringify(this.currentAsciibirdMeta))
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
this.ctx.stroke()
|
|
|
|
|
|
|
|
},
|
2021-01-07 23:53:28 +00:00
|
|
|
processMouseDown(e) {
|
|
|
|
console.log("Mouse down")
|
2021-01-09 01:57:48 +00:00
|
|
|
// this.canvasClass(e)
|
2021-01-02 01:52:44 +00:00
|
|
|
this.selectionMode = true;
|
|
|
|
this.startPosition.x = e.clientX;
|
|
|
|
this.startPosition.y = e.clientY;
|
|
|
|
},
|
2021-01-07 23:53:28 +00:00
|
|
|
processMouseMove(e) {
|
|
|
|
console.log("Mouse move")
|
2021-01-02 01:52:44 +00:00
|
|
|
if (this.selectionMode) {
|
|
|
|
// console.log(this.startPosition);
|
2021-01-07 23:32:19 +00:00
|
|
|
|
2021-01-02 01:52:44 +00:00
|
|
|
this.ctx.beginPath();
|
|
|
|
this.ctx.rect(
|
|
|
|
this.startPosition.x,
|
|
|
|
this.startPosition.y,
|
|
|
|
e.clientX - this.startPosition.x,
|
|
|
|
e.clientY - this.startPosition.y,
|
|
|
|
);
|
|
|
|
this.ctx.closePath();
|
|
|
|
this.ctx.fillRect(0, 0, window.innerWidth, window.innerHeight);
|
|
|
|
this.ctx.clearRect(0, 0, window.innerWidth, window.innerHeight);
|
|
|
|
this.ctx.strokeStyle = '#f00';
|
|
|
|
this.ctx.stroke();
|
|
|
|
}
|
|
|
|
},
|
2021-01-09 01:57:48 +00:00
|
|
|
triangleTest(e) {
|
|
|
|
console.log("Mouse triangleTest")
|
2021-01-07 23:53:28 +00:00
|
|
|
// this.ctx = e.target;
|
2021-01-02 01:52:44 +00:00
|
|
|
|
|
|
|
this.ctx.strokeStyle = 'red';
|
|
|
|
this.ctx.beginPath();
|
|
|
|
this.ctx.moveTo(100, 100);
|
|
|
|
this.ctx.lineTo(200, 100);
|
|
|
|
this.ctx.lineTo(200, 150);
|
|
|
|
this.ctx.closePath();
|
|
|
|
this.ctx.stroke();
|
|
|
|
},
|
2021-01-07 23:53:28 +00:00
|
|
|
processMouseUp(e) {
|
|
|
|
console.log("Mouse up")
|
2021-01-02 01:52:44 +00:00
|
|
|
this.ctx.fillStyle = '#fff';
|
|
|
|
|
|
|
|
this.selectionMode = false;
|
|
|
|
this.startPosition.x = null;
|
|
|
|
this.startPosition.y = null;
|
2020-12-27 02:42:26 +00:00
|
|
|
},
|
|
|
|
},
|
2020-12-19 01:27:50 +00:00
|
|
|
};
|
|
|
|
</script>
|