2020-12-19 01:27:50 +00:00
|
|
|
<template>
|
2020-12-27 02:42:26 +00:00
|
|
|
<div>
|
2021-05-22 02:49:19 +00:00
|
|
|
<div
|
|
|
|
id="canvas-area"
|
|
|
|
@mouseleave="isMouseOnCanvas = false"
|
|
|
|
@mouseenter="isMouseOnCanvas = true"
|
|
|
|
>
|
2021-03-20 03:45:10 +00:00
|
|
|
<vue-draggable-resizable
|
2021-08-15 00:57:37 +00:00
|
|
|
ref="canvasdrag"
|
2021-08-14 06:41:42 +00:00
|
|
|
:grid="[blockWidth, blockHeight]"
|
2021-08-15 00:57:37 +00:00
|
|
|
:w="currentAsciiWidth * blockWidth"
|
|
|
|
:h="currentAsciiHeight * blockHeight"
|
2021-08-12 03:19:06 +00:00
|
|
|
:draggable="isDefault"
|
2021-04-03 03:13:03 +00:00
|
|
|
@resizestop="onCanvasResize"
|
2021-04-01 23:01:36 +00:00
|
|
|
@dragstop="onCavasDragStop"
|
2021-04-03 03:13:03 +00:00
|
|
|
:x="currentAscii.x"
|
|
|
|
:y="currentAscii.y"
|
2021-03-20 03:45:10 +00:00
|
|
|
>
|
2021-04-03 03:13:03 +00:00
|
|
|
<canvas
|
2021-08-14 06:41:42 +00:00
|
|
|
ref="canvas"
|
|
|
|
id="canvas"
|
|
|
|
class="canvas"
|
2021-08-15 00:57:37 +00:00
|
|
|
:width="currentAsciiWidth * blockWidth"
|
|
|
|
:height="currentAsciiHeight * blockHeight"
|
2021-08-04 03:21:06 +00:00
|
|
|
/>
|
2021-03-31 23:29:55 +00:00
|
|
|
|
2021-03-20 03:45:10 +00:00
|
|
|
<canvas
|
2021-08-14 06:41:42 +00:00
|
|
|
ref="canvastools"
|
|
|
|
id="canvastools"
|
|
|
|
class="canvastools"
|
2021-08-15 00:57:37 +00:00
|
|
|
:width="currentAsciiWidth * blockWidth"
|
|
|
|
:height="currentAsciiHeight * blockHeight"
|
2021-03-27 02:07:33 +00:00
|
|
|
@mousemove="canvasMouseMove"
|
|
|
|
@mousedown="canvasMouseDown"
|
|
|
|
@mouseup="canvasMouseUp"
|
2021-08-04 03:21:06 +00:00
|
|
|
/>
|
2021-03-20 03:45:10 +00:00
|
|
|
</vue-draggable-resizable>
|
2020-12-27 02:42:26 +00:00
|
|
|
</div>
|
2020-12-19 01:27:50 +00:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
2021-08-07 05:36:32 +00:00
|
|
|
import {
|
|
|
|
toolbarIcons,
|
|
|
|
mircColours99,
|
|
|
|
filterNullBlocks,
|
|
|
|
blockWidth,
|
|
|
|
blockHeight,
|
2021-08-12 01:52:40 +00:00
|
|
|
maxBrushSize,
|
|
|
|
fillNullBlocks,
|
2021-08-12 03:19:06 +00:00
|
|
|
emptyBlock,
|
|
|
|
getBlocksWidth,
|
2021-08-14 06:41:42 +00:00
|
|
|
checkVisible,
|
2021-08-07 05:36:32 +00:00
|
|
|
} from "../ascii";
|
2020-12-27 02:42:26 +00:00
|
|
|
|
2020-12-19 01:27:50 +00:00
|
|
|
export default {
|
2021-08-07 05:36:32 +00:00
|
|
|
name: "Editor",
|
2021-01-02 01:52:44 +00:00
|
|
|
mounted() {
|
2021-08-14 06:41:42 +00:00
|
|
|
this.ctx = this.canvasRef.getContext("2d");
|
|
|
|
this.toolCtx = this.$refs.canvastools.getContext("2d");
|
|
|
|
this.delayRedrawCanvas();
|
|
|
|
},
|
|
|
|
created() {
|
|
|
|
window.addEventListener("load", () => {
|
|
|
|
// Fixes the font on load issue
|
|
|
|
this.delayRedrawCanvas();
|
|
|
|
});
|
2021-04-03 03:13:03 +00:00
|
|
|
|
2021-08-14 09:09:36 +00:00
|
|
|
if (this.currentAsciiLayerBlocks) {
|
2021-08-15 00:57:37 +00:00
|
|
|
this.canvas.width = this.currentAsciiWidth * blockWidth;
|
|
|
|
this.canvas.height = this.currentAsciiHeight * blockHeight;
|
2021-04-03 03:13:03 +00:00
|
|
|
|
2021-03-27 02:07:33 +00:00
|
|
|
this.delayRedrawCanvas();
|
2021-08-16 04:10:06 +00:00
|
|
|
this.$emit("textediting", this.textEditing);
|
2021-03-13 05:27:07 +00:00
|
|
|
}
|
2020-12-27 02:42:26 +00:00
|
|
|
},
|
|
|
|
data: () => ({
|
2021-01-02 01:52:44 +00:00
|
|
|
ctx: null,
|
2021-04-03 03:13:03 +00:00
|
|
|
toolCtx: null,
|
2021-01-09 01:57:48 +00:00
|
|
|
canvas: {
|
2021-03-26 11:36:37 +00:00
|
|
|
width: 512,
|
|
|
|
height: 512,
|
2021-01-09 01:57:48 +00:00
|
|
|
},
|
2021-03-29 00:39:42 +00:00
|
|
|
x: 0, // Ascii X and Y
|
|
|
|
y: 0, // Ascii X and Y
|
2021-08-14 06:41:42 +00:00
|
|
|
top: false,
|
2021-03-29 00:39:42 +00:00
|
|
|
redraw: true, // Used to limit canvas redraw
|
2021-03-27 04:16:15 +00:00
|
|
|
canTool: false,
|
2021-04-03 03:13:03 +00:00
|
|
|
textEditing: {
|
|
|
|
startX: null,
|
|
|
|
startY: null,
|
|
|
|
},
|
|
|
|
selecting: {
|
|
|
|
startX: null,
|
|
|
|
startY: null,
|
|
|
|
endX: null,
|
|
|
|
endY: null,
|
|
|
|
canSelect: false,
|
|
|
|
},
|
2021-05-22 02:49:19 +00:00
|
|
|
isMouseOnCanvas: false,
|
2021-08-03 04:59:12 +00:00
|
|
|
selectedBlocks: [],
|
2020-12-27 02:42:26 +00:00
|
|
|
}),
|
2021-08-16 04:10:06 +00:00
|
|
|
props: ["updateCanvas"],
|
2020-12-27 02:42:26 +00:00
|
|
|
computed: {
|
2021-08-14 06:41:42 +00:00
|
|
|
canvasRef() {
|
|
|
|
return this.$refs.canvas;
|
|
|
|
},
|
|
|
|
blockWidth() {
|
|
|
|
return blockWidth * this.blockSizeMultiplier;
|
|
|
|
},
|
|
|
|
blockHeight() {
|
|
|
|
return blockHeight * this.blockSizeMultiplier;
|
|
|
|
},
|
|
|
|
blockSizeMultiplier() {
|
|
|
|
return this.$store.getters.blockSizeMultiplier;
|
|
|
|
},
|
2021-04-03 03:13:03 +00:00
|
|
|
currentAscii() {
|
2021-03-13 05:27:07 +00:00
|
|
|
return this.$store.getters.currentAscii;
|
2021-02-06 01:57:35 +00:00
|
|
|
},
|
2021-08-14 06:41:42 +00:00
|
|
|
currentAsciiLayers() {
|
|
|
|
return this.$store.getters.currentAsciiLayers;
|
|
|
|
},
|
2021-08-17 00:24:41 +00:00
|
|
|
selectedLayerIndex() {
|
|
|
|
return this.currentAscii.selectedLayer || 0
|
|
|
|
},
|
2021-08-15 00:57:37 +00:00
|
|
|
currentSelectedLayer() {
|
2021-08-17 00:24:41 +00:00
|
|
|
return this.currentAsciiLayers[this.selectedLayerIndex];
|
2021-08-15 00:57:37 +00:00
|
|
|
},
|
2021-08-14 06:41:42 +00:00
|
|
|
currentAsciiLayerBlocks() {
|
2021-08-15 00:57:37 +00:00
|
|
|
return this.currentSelectedLayer.data;
|
2021-08-14 06:41:42 +00:00
|
|
|
},
|
2021-04-03 03:13:03 +00:00
|
|
|
currentTool() {
|
2021-08-03 07:33:25 +00:00
|
|
|
return toolbarIcons[this.$store.getters.currentTool];
|
2021-04-03 03:13:03 +00:00
|
|
|
},
|
2021-05-08 01:51:30 +00:00
|
|
|
canFg() {
|
2021-08-03 03:00:32 +00:00
|
|
|
return this.$store.getters.isTargettingFg;
|
2021-05-08 01:51:30 +00:00
|
|
|
},
|
|
|
|
canBg() {
|
2021-08-03 03:00:32 +00:00
|
|
|
return this.$store.getters.isTargettingBg;
|
2021-05-08 01:51:30 +00:00
|
|
|
},
|
|
|
|
canText() {
|
2021-08-03 03:00:32 +00:00
|
|
|
return this.$store.getters.isTargettingChar;
|
2021-05-08 01:51:30 +00:00
|
|
|
},
|
2021-07-17 01:44:27 +00:00
|
|
|
currentFg() {
|
2021-08-03 03:00:32 +00:00
|
|
|
return this.$store.getters.currentFg;
|
2021-07-17 01:44:27 +00:00
|
|
|
},
|
|
|
|
currentBg() {
|
2021-08-03 03:00:32 +00:00
|
|
|
return this.$store.getters.currentBg;
|
2021-07-17 01:44:27 +00:00
|
|
|
},
|
|
|
|
currentChar() {
|
2021-08-06 01:51:58 +00:00
|
|
|
return this.$store.getters.currentChar;
|
2021-07-17 01:44:27 +00:00
|
|
|
},
|
2021-08-03 03:00:32 +00:00
|
|
|
isTextEditing() {
|
2021-08-07 05:36:32 +00:00
|
|
|
return this.currentTool.name === "text";
|
2021-04-03 03:13:03 +00:00
|
|
|
},
|
2021-08-12 01:52:40 +00:00
|
|
|
isTextEditingValues() {
|
2021-08-12 03:19:06 +00:00
|
|
|
return (
|
|
|
|
this.textEditing.startX !== null && this.textEditing.startY !== null
|
|
|
|
);
|
2021-08-12 01:52:40 +00:00
|
|
|
},
|
2021-04-03 03:13:03 +00:00
|
|
|
isSelecting() {
|
2021-08-07 05:36:32 +00:00
|
|
|
return this.currentTool.name === "select";
|
2021-04-03 03:13:03 +00:00
|
|
|
},
|
2021-08-11 23:47:36 +00:00
|
|
|
isDefault() {
|
2021-08-16 06:14:49 +00:00
|
|
|
return this.currentTool.name === "default" || false;
|
2021-08-11 23:47:36 +00:00
|
|
|
},
|
2021-08-08 03:24:06 +00:00
|
|
|
isBrushing() {
|
|
|
|
return this.currentTool.name === "brush";
|
|
|
|
},
|
2021-06-05 01:25:23 +00:00
|
|
|
isSelected() {
|
|
|
|
return (
|
2021-08-12 09:36:35 +00:00
|
|
|
this.selecting.startX !== null &&
|
|
|
|
this.selecting.startY !== null &&
|
|
|
|
this.selecting.endX !== null &&
|
|
|
|
this.selecting.endY !== null
|
2021-06-05 01:25:23 +00:00
|
|
|
);
|
|
|
|
},
|
2021-06-29 01:49:39 +00:00
|
|
|
brushBlocks() {
|
|
|
|
return this.$store.getters.brushBlocks;
|
2021-07-10 01:41:17 +00:00
|
|
|
},
|
2021-07-24 01:55:44 +00:00
|
|
|
canvasX() {
|
2021-08-08 00:36:17 +00:00
|
|
|
return this.x * blockWidth;
|
2021-07-24 01:55:44 +00:00
|
|
|
},
|
|
|
|
canvasY() {
|
2021-08-08 00:36:17 +00:00
|
|
|
return this.y * blockHeight;
|
2021-07-24 01:55:44 +00:00
|
|
|
},
|
2021-07-31 02:12:11 +00:00
|
|
|
toolbarState() {
|
2021-08-03 03:00:32 +00:00
|
|
|
return this.$store.getters.toolbarState;
|
2021-07-31 02:12:11 +00:00
|
|
|
},
|
|
|
|
mirrorX() {
|
|
|
|
return this.toolbarState.mirrorX;
|
|
|
|
},
|
|
|
|
mirrorY() {
|
|
|
|
return this.toolbarState.mirrorY;
|
|
|
|
},
|
2021-08-03 03:00:32 +00:00
|
|
|
debugPanelState() {
|
2021-08-03 04:59:12 +00:00
|
|
|
return this.$store.getters.debugPanel;
|
|
|
|
},
|
|
|
|
selectBlocks() {
|
|
|
|
return this.$store.getters.selectBlocks;
|
|
|
|
},
|
|
|
|
options() {
|
|
|
|
return this.$store.getters.options;
|
2021-08-03 03:00:32 +00:00
|
|
|
},
|
2021-08-03 04:59:12 +00:00
|
|
|
haveSelectBlocks() {
|
2021-08-04 03:21:06 +00:00
|
|
|
return !!this.selectBlocks.length;
|
2021-08-03 07:33:25 +00:00
|
|
|
},
|
|
|
|
mircColours() {
|
|
|
|
return mircColours99;
|
2021-08-04 03:21:06 +00:00
|
|
|
},
|
2021-08-07 02:41:47 +00:00
|
|
|
brushLibraryState() {
|
|
|
|
return this.$store.getters.brushLibraryState;
|
2021-08-07 05:36:32 +00:00
|
|
|
},
|
2021-08-08 00:36:17 +00:00
|
|
|
gridView() {
|
2021-08-14 06:41:42 +00:00
|
|
|
return this.toolbarState.gridView;
|
2021-08-08 03:24:06 +00:00
|
|
|
},
|
2021-08-11 23:47:36 +00:00
|
|
|
asciiBlockAtXy() {
|
2021-08-14 09:09:36 +00:00
|
|
|
return this.currentAsciiLayerBlocks[this.y] &&
|
|
|
|
this.currentAsciiLayerBlocks[this.y][this.x]
|
|
|
|
? this.currentAsciiLayerBlocks[this.y][this.x]
|
2021-08-11 23:47:36 +00:00
|
|
|
: false;
|
|
|
|
},
|
2021-08-12 01:52:40 +00:00
|
|
|
maxBrushSize() {
|
|
|
|
return maxBrushSize;
|
|
|
|
},
|
2021-08-15 00:57:37 +00:00
|
|
|
currentAsciiWidth() {
|
2021-08-15 01:20:58 +00:00
|
|
|
return this.currentSelectedLayer.width;
|
2021-08-15 00:57:37 +00:00
|
|
|
},
|
|
|
|
currentAsciiHeight() {
|
2021-08-15 01:20:58 +00:00
|
|
|
return this.currentSelectedLayer.height;
|
|
|
|
},
|
2020-12-27 02:42:26 +00:00
|
|
|
},
|
|
|
|
watch: {
|
2021-04-03 03:13:03 +00:00
|
|
|
currentAscii(val, old) {
|
2021-07-10 01:41:17 +00:00
|
|
|
if (val !== old) {
|
2021-08-15 00:57:37 +00:00
|
|
|
this.canvas.width = this.currentAsciiWidth * blockWidth;
|
|
|
|
this.canvas.height = this.currentAsciiHeight * blockHeight;
|
2021-07-10 01:41:17 +00:00
|
|
|
|
|
|
|
this.delayRedrawCanvas();
|
2021-08-12 03:19:06 +00:00
|
|
|
|
|
|
|
document.title = `asciibird - ${this.currentAscii.title}`;
|
2021-07-10 01:41:17 +00:00
|
|
|
}
|
2021-04-03 03:13:03 +00:00
|
|
|
},
|
2021-08-14 09:09:36 +00:00
|
|
|
currentAsciiLayerBlocks() {
|
|
|
|
this.delayRedrawCanvas();
|
|
|
|
},
|
2021-08-14 06:41:42 +00:00
|
|
|
currentAsciiLayers() {
|
|
|
|
this.delayRedrawCanvas();
|
|
|
|
},
|
2021-08-16 04:10:06 +00:00
|
|
|
currentSelectedLayer(val, old) {
|
2021-08-16 02:39:30 +00:00
|
|
|
this.delayRedrawCanvas();
|
2021-08-16 04:10:06 +00:00
|
|
|
|
|
|
|
if (old.visible) {
|
|
|
|
this.warnInvisibleLayer();
|
|
|
|
}
|
2021-08-16 02:39:30 +00:00
|
|
|
},
|
2021-04-03 03:13:03 +00:00
|
|
|
currentTool() {
|
2021-08-16 02:39:30 +00:00
|
|
|
this.warnInvisibleLayer();
|
|
|
|
|
2021-08-03 04:59:12 +00:00
|
|
|
switch (this.currentTool.name) {
|
2021-08-07 05:36:32 +00:00
|
|
|
case "default":
|
2021-08-03 03:00:32 +00:00
|
|
|
// Reset default values for tools
|
2021-08-03 04:59:12 +00:00
|
|
|
this.textEditing = {
|
2021-04-03 03:13:03 +00:00
|
|
|
startX: null,
|
|
|
|
startY: null,
|
2021-08-03 04:59:12 +00:00
|
|
|
};
|
2021-04-03 03:13:03 +00:00
|
|
|
|
2021-08-12 04:19:01 +00:00
|
|
|
this.resetSelect();
|
2021-04-03 03:13:03 +00:00
|
|
|
break;
|
|
|
|
}
|
2021-03-27 02:07:33 +00:00
|
|
|
},
|
2021-05-22 02:49:19 +00:00
|
|
|
isMouseOnCanvas() {
|
2021-07-17 01:44:27 +00:00
|
|
|
if (!this.isSelecting) {
|
|
|
|
this.clearToolCanvas();
|
2021-08-03 03:00:32 +00:00
|
|
|
this.canTool = false;
|
2021-07-17 01:44:27 +00:00
|
|
|
}
|
2021-05-22 02:49:19 +00:00
|
|
|
},
|
2021-08-08 03:24:06 +00:00
|
|
|
gridView(val, old) {
|
2021-08-08 00:36:17 +00:00
|
|
|
if (val !== old) {
|
2021-08-08 03:24:06 +00:00
|
|
|
this.delayRedrawCanvas();
|
2021-08-08 00:36:17 +00:00
|
|
|
}
|
2021-08-08 03:24:06 +00:00
|
|
|
},
|
|
|
|
brushBlocks() {
|
|
|
|
this.clearToolCanvas();
|
2021-08-11 23:47:36 +00:00
|
|
|
|
|
|
|
// This was supposed to update the brush preview real time
|
|
|
|
if (this.isMouseOnCanvas && this.isBrushing) {
|
2021-08-08 03:24:06 +00:00
|
|
|
this.drawBrush();
|
|
|
|
}
|
|
|
|
},
|
2021-08-14 06:41:42 +00:00
|
|
|
blockSizeMultiplier() {
|
|
|
|
this.delayRedrawCanvas();
|
|
|
|
},
|
2021-08-15 01:20:58 +00:00
|
|
|
// Save text to store when finished
|
|
|
|
isTextEditing(val, old) {
|
|
|
|
if (val !== old && val === false) {
|
2021-08-16 02:10:09 +00:00
|
|
|
this.$store.commit("updateAsciiBlocks", this.currentAsciiLayerBlocks);
|
2021-08-15 01:20:58 +00:00
|
|
|
}
|
2021-08-16 02:10:09 +00:00
|
|
|
},
|
2021-08-16 04:10:06 +00:00
|
|
|
textEditing(val, old) {
|
|
|
|
this.$emit("textediting", val);
|
|
|
|
},
|
|
|
|
updateCanvas(val, old) {
|
|
|
|
if (val !== old) {
|
|
|
|
// This comes from KeyboardShortcuts.vue
|
|
|
|
this.clearToolCanvas();
|
|
|
|
this.drawTextIndicator();
|
|
|
|
this.drawIndicator();
|
|
|
|
|
|
|
|
this.delayRedrawCanvas();
|
|
|
|
}
|
|
|
|
},
|
2021-08-17 00:24:41 +00:00
|
|
|
selecting(val) {
|
|
|
|
this.$emit("selecting", val);
|
|
|
|
},
|
2020-12-27 02:42:26 +00:00
|
|
|
},
|
|
|
|
methods: {
|
2021-08-16 02:39:30 +00:00
|
|
|
warnInvisibleLayer() {
|
|
|
|
if (!this.currentSelectedLayer.visible) {
|
|
|
|
this.$toasted.show("You are trying to edit an invisible layer!!", {
|
|
|
|
type: "error",
|
|
|
|
icon: "fa-check-cross",
|
|
|
|
singleton: true,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
2021-08-14 06:41:42 +00:00
|
|
|
checkVisible(top) {
|
|
|
|
return checkVisible(top, top - this.blockHeight);
|
|
|
|
},
|
2021-05-15 01:52:20 +00:00
|
|
|
undo() {
|
2021-08-07 05:36:32 +00:00
|
|
|
this.$store.commit("undoBlocks");
|
2021-05-22 02:49:19 +00:00
|
|
|
this.delayRedrawCanvas();
|
|
|
|
},
|
|
|
|
redo() {
|
2021-08-07 05:36:32 +00:00
|
|
|
this.$store.commit("redoBlocks");
|
2021-05-22 02:49:19 +00:00
|
|
|
this.delayRedrawCanvas();
|
2021-05-15 01:52:20 +00:00
|
|
|
},
|
2021-08-12 03:19:06 +00:00
|
|
|
resetSelect() {
|
|
|
|
this.selecting = {
|
|
|
|
startX: null,
|
|
|
|
startY: null,
|
|
|
|
endX: null,
|
|
|
|
endY: null,
|
|
|
|
canSelect: false,
|
|
|
|
};
|
2021-08-17 00:24:41 +00:00
|
|
|
this.$emit("selecting", this.selecting);
|
2021-08-12 03:19:06 +00:00
|
|
|
},
|
2021-06-05 01:25:23 +00:00
|
|
|
redrawSelect() {
|
2021-08-14 09:09:36 +00:00
|
|
|
if (this.currentAsciiLayerBlocks.length) {
|
2021-04-03 03:13:03 +00:00
|
|
|
this.clearToolCanvas();
|
2021-08-03 03:00:32 +00:00
|
|
|
this.toolCtx.fillStyle = this.mircColours[0];
|
2021-04-03 03:13:03 +00:00
|
|
|
|
2021-05-01 02:17:49 +00:00
|
|
|
this.toolCtx.fillRect(
|
2021-07-24 01:55:44 +00:00
|
|
|
this.selecting.startX,
|
|
|
|
this.selecting.startY,
|
|
|
|
this.selecting.endX - this.selecting.startX,
|
2021-08-07 05:36:32 +00:00
|
|
|
this.selecting.endY - this.selecting.startY
|
2021-04-17 00:12:02 +00:00
|
|
|
);
|
2021-08-08 00:36:17 +00:00
|
|
|
|
|
|
|
this.toolCtx.setLineDash([6]);
|
|
|
|
this.toolCtx.strokeRect(
|
|
|
|
this.selecting.startX,
|
|
|
|
this.selecting.startY,
|
|
|
|
this.selecting.endX - this.selecting.startX,
|
|
|
|
this.selecting.endY - this.selecting.startY
|
|
|
|
);
|
2021-04-03 03:13:03 +00:00
|
|
|
}
|
|
|
|
},
|
2021-01-09 01:57:48 +00:00
|
|
|
redrawCanvas() {
|
2021-08-14 06:41:42 +00:00
|
|
|
if (this.currentAsciiLayers.length) {
|
2021-08-08 00:36:17 +00:00
|
|
|
this.ctx.clearRect(0, 0, this.canvas.width, this.canvas.height);
|
|
|
|
|
2021-03-20 03:45:10 +00:00
|
|
|
// Position of the meta array
|
|
|
|
let x = 0;
|
|
|
|
let y = 0;
|
2021-01-23 02:50:32 +00:00
|
|
|
|
2021-08-14 06:41:42 +00:00
|
|
|
let i = 0;
|
|
|
|
|
2021-03-20 03:45:10 +00:00
|
|
|
// Draws the actual rectangle
|
|
|
|
let canvasX = 0;
|
|
|
|
let canvasY = 0;
|
|
|
|
let curBlock = {};
|
2021-03-06 02:03:22 +00:00
|
|
|
|
2021-03-29 00:39:42 +00:00
|
|
|
// hack font for ascii shout outs 2 beenz
|
2021-08-07 05:36:32 +00:00
|
|
|
this.ctx.font = "13px Hack";
|
2021-03-06 02:03:22 +00:00
|
|
|
|
2021-08-15 00:57:37 +00:00
|
|
|
for (y = 0; y < this.currentAsciiHeight + 1; y++) {
|
2021-08-12 01:52:40 +00:00
|
|
|
canvasY = blockHeight * y;
|
2021-01-09 01:57:48 +00:00
|
|
|
|
2021-08-14 06:41:42 +00:00
|
|
|
// Experimental code to not rows blocks off screen
|
2021-08-16 02:10:09 +00:00
|
|
|
if (this.top !== false && !this.checkVisible(this.top + canvasY)) {
|
|
|
|
continue;
|
|
|
|
}
|
2021-08-14 06:41:42 +00:00
|
|
|
|
2021-08-15 00:57:37 +00:00
|
|
|
for (x = 0; x < this.currentAsciiWidth + 1; x++) {
|
2021-08-17 00:24:41 +00:00
|
|
|
canvasX = blockWidth * x;
|
|
|
|
|
|
|
|
if (this.gridView) {
|
|
|
|
this.ctx.setLineDash([1]);
|
|
|
|
this.ctx.strokeStyle = "rgba(0, 0, 0, 1)";
|
|
|
|
this.ctx.strokeRect(canvasX, canvasY, blockWidth, blockHeight);
|
|
|
|
}
|
|
|
|
|
2021-08-14 06:41:42 +00:00
|
|
|
// Loop layers
|
|
|
|
for (i = this.currentAsciiLayers.length - 1; i >= 0; i--) {
|
2021-08-14 09:09:36 +00:00
|
|
|
// for (i = 0; i >= this.currentAsciiLayers.length - 1; i++) {
|
2021-08-14 06:41:42 +00:00
|
|
|
// If this layer is invisble, skip it
|
2021-08-14 09:09:36 +00:00
|
|
|
if (this.currentAsciiLayers[i].visible === true) {
|
|
|
|
// If this block on this layer has no data, skip to next row
|
|
|
|
if (
|
|
|
|
this.currentAsciiLayers[i] &&
|
|
|
|
this.currentAsciiLayers[i].data &&
|
|
|
|
this.currentAsciiLayers[i].data[y] &&
|
|
|
|
this.currentAsciiLayers[i].data[y][x] &&
|
|
|
|
i > 0 &&
|
|
|
|
JSON.stringify(this.currentAsciiLayers[i].data[y][x]) ===
|
|
|
|
JSON.stringify(emptyBlock)
|
|
|
|
) {
|
|
|
|
continue;
|
|
|
|
} else if (
|
|
|
|
// Otherwise if we are on the very first layer we need to render it
|
|
|
|
this.currentAsciiLayers[i] &&
|
|
|
|
this.currentAsciiLayers[i].data &&
|
|
|
|
this.currentAsciiLayers[i].data[y] &&
|
|
|
|
this.currentAsciiLayers[i].data[y][x]
|
|
|
|
) {
|
|
|
|
curBlock = { ...this.currentAsciiLayers[i].data[y][x] };
|
2021-08-14 06:41:42 +00:00
|
|
|
|
2021-08-14 09:09:36 +00:00
|
|
|
// break;
|
|
|
|
}
|
2021-03-27 02:07:33 +00:00
|
|
|
|
2021-08-14 09:09:36 +00:00
|
|
|
// Background block
|
|
|
|
if (curBlock.bg !== null) {
|
|
|
|
this.ctx.fillStyle = this.mircColours[curBlock.bg];
|
|
|
|
this.ctx.fillRect(canvasX, canvasY, blockWidth, blockHeight);
|
|
|
|
}
|
2021-03-13 05:27:07 +00:00
|
|
|
|
2021-08-14 09:09:36 +00:00
|
|
|
if (curBlock.char) {
|
|
|
|
if (curBlock.fg !== null) {
|
|
|
|
this.ctx.fillStyle = this.mircColours[curBlock.fg];
|
|
|
|
} else {
|
|
|
|
this.ctx.fillStyle = "#000000";
|
|
|
|
}
|
|
|
|
|
|
|
|
this.ctx.fillText(
|
|
|
|
curBlock.char,
|
|
|
|
canvasX,
|
|
|
|
canvasY + blockHeight - 3
|
|
|
|
);
|
2021-03-13 05:27:07 +00:00
|
|
|
}
|
2021-03-20 03:45:10 +00:00
|
|
|
|
2021-08-14 09:09:36 +00:00
|
|
|
break;
|
2021-03-06 02:03:22 +00:00
|
|
|
}
|
2021-01-23 02:50:32 +00:00
|
|
|
}
|
2021-01-30 02:33:11 +00:00
|
|
|
}
|
2021-01-09 01:57:48 +00:00
|
|
|
}
|
2021-03-20 03:45:10 +00:00
|
|
|
}
|
2021-03-27 04:16:15 +00:00
|
|
|
},
|
|
|
|
onCanvasResize(left, top, width, height) {
|
2021-08-08 03:24:06 +00:00
|
|
|
const canvasBlockHeight = Math.floor(height / blockHeight);
|
2021-08-08 00:36:17 +00:00
|
|
|
const canvasBlockWidth = Math.floor(width / blockWidth);
|
2021-08-15 01:20:58 +00:00
|
|
|
let layers = fillNullBlocks(canvasBlockHeight, canvasBlockWidth);
|
2021-04-03 03:13:03 +00:00
|
|
|
|
2021-08-14 06:41:42 +00:00
|
|
|
this.top = top;
|
2021-03-27 04:16:15 +00:00
|
|
|
this.canvas.width = width;
|
|
|
|
this.canvas.height = height;
|
2021-04-01 23:01:36 +00:00
|
|
|
|
2021-08-07 05:36:32 +00:00
|
|
|
this.$store.commit("changeAsciiWidthHeight", {
|
2021-04-03 03:13:03 +00:00
|
|
|
width: canvasBlockWidth,
|
|
|
|
height: canvasBlockHeight,
|
2021-08-15 01:20:58 +00:00
|
|
|
layers: [...layers],
|
2021-04-03 03:13:03 +00:00
|
|
|
});
|
2021-04-01 23:01:36 +00:00
|
|
|
|
2021-08-15 01:20:58 +00:00
|
|
|
this.$refs.canvasdrag.width = width;
|
2021-08-19 00:23:12 +00:00
|
|
|
this.$refs.canvasdrag.height = height;
|
2021-08-15 00:57:37 +00:00
|
|
|
|
2021-03-27 04:16:15 +00:00
|
|
|
this.delayRedrawCanvas();
|
|
|
|
},
|
2021-04-01 23:01:36 +00:00
|
|
|
onCavasDragStop(x, y) {
|
2021-03-27 04:16:15 +00:00
|
|
|
// Update left and top in panel
|
2021-08-14 06:41:42 +00:00
|
|
|
this.top = y;
|
2021-08-07 05:36:32 +00:00
|
|
|
this.$store.commit("changeAsciiCanvasState", { x, y });
|
2021-08-14 06:41:42 +00:00
|
|
|
this.delayRedrawCanvas();
|
|
|
|
},
|
|
|
|
onCanvasDrag(x, y) {
|
|
|
|
this.top = y;
|
|
|
|
this.delayRedrawCanvas();
|
2021-03-27 04:16:15 +00:00
|
|
|
},
|
|
|
|
// Mouse Up, Down and Move
|
|
|
|
canvasMouseUp() {
|
2021-08-11 23:47:36 +00:00
|
|
|
if (this.isDefault) return;
|
2021-08-03 06:33:06 +00:00
|
|
|
|
2021-04-17 00:12:02 +00:00
|
|
|
switch (this.currentTool.name) {
|
2021-08-07 05:36:32 +00:00
|
|
|
case "brush":
|
2021-03-27 04:16:15 +00:00
|
|
|
this.canTool = false;
|
2021-05-15 01:52:20 +00:00
|
|
|
|
2021-08-14 09:09:36 +00:00
|
|
|
this.$store.commit("updateAsciiBlocks", this.currentAsciiLayerBlocks);
|
2021-05-22 02:49:19 +00:00
|
|
|
|
2021-03-27 04:16:15 +00:00
|
|
|
break;
|
|
|
|
|
2021-08-07 05:36:32 +00:00
|
|
|
case "eraser":
|
2021-03-27 04:16:15 +00:00
|
|
|
this.canTool = false;
|
2021-08-14 09:09:36 +00:00
|
|
|
this.$store.commit("updateAsciiBlocks", this.currentAsciiLayerBlocks);
|
2021-03-27 04:16:15 +00:00
|
|
|
break;
|
|
|
|
|
2021-08-11 23:47:36 +00:00
|
|
|
case "fill-eraser":
|
2021-08-07 05:36:32 +00:00
|
|
|
case "fill":
|
2021-08-08 00:36:17 +00:00
|
|
|
this.canTool = false;
|
2021-03-27 04:16:15 +00:00
|
|
|
break;
|
2021-04-03 03:13:03 +00:00
|
|
|
|
2021-08-07 05:36:32 +00:00
|
|
|
case "select":
|
2021-04-03 03:13:03 +00:00
|
|
|
this.selecting.canSelect = false;
|
2021-08-03 03:00:32 +00:00
|
|
|
this.processSelect();
|
2021-04-03 03:13:03 +00:00
|
|
|
break;
|
|
|
|
|
2021-08-07 05:36:32 +00:00
|
|
|
case "text":
|
2021-05-22 02:49:19 +00:00
|
|
|
this.textEditing.startX = this.x;
|
|
|
|
this.textEditing.startY = this.y;
|
2021-04-03 03:13:03 +00:00
|
|
|
break;
|
2021-03-27 04:16:15 +00:00
|
|
|
}
|
2021-03-31 23:29:55 +00:00
|
|
|
|
|
|
|
this.delayRedrawCanvas();
|
2021-03-27 04:16:15 +00:00
|
|
|
},
|
|
|
|
canvasMouseDown() {
|
2021-08-11 23:47:36 +00:00
|
|
|
if (this.isDefault) return;
|
2021-08-03 06:33:06 +00:00
|
|
|
|
2021-08-11 23:47:36 +00:00
|
|
|
if (this.asciiBlockAtXy && this.currentTool) {
|
|
|
|
const targetBlock = this.asciiBlockAtXy;
|
2021-04-02 04:43:11 +00:00
|
|
|
|
2021-04-17 00:12:02 +00:00
|
|
|
switch (this.currentTool.name) {
|
2021-08-07 05:36:32 +00:00
|
|
|
case "select":
|
2021-07-31 02:12:11 +00:00
|
|
|
this.selecting.startX = this.canvasX;
|
|
|
|
this.selecting.startY = this.canvasY;
|
|
|
|
this.selecting.canSelect = true;
|
2021-08-07 22:36:00 +00:00
|
|
|
this.clearToolCanvas();
|
2021-04-03 03:13:03 +00:00
|
|
|
break;
|
|
|
|
|
2021-08-07 05:36:32 +00:00
|
|
|
case "fill":
|
2021-04-02 04:43:11 +00:00
|
|
|
this.fill();
|
2021-08-14 09:09:36 +00:00
|
|
|
this.$store.commit(
|
|
|
|
"updateAsciiBlocks",
|
|
|
|
this.currentAsciiLayerBlocks
|
|
|
|
);
|
2021-08-05 00:54:40 +00:00
|
|
|
this.canTool = false;
|
2021-03-29 00:39:42 +00:00
|
|
|
break;
|
|
|
|
|
2021-08-11 23:47:36 +00:00
|
|
|
case "fill-eraser":
|
|
|
|
this.fill(true);
|
2021-08-14 09:09:36 +00:00
|
|
|
this.$store.commit(
|
|
|
|
"updateAsciiBlocks",
|
|
|
|
this.currentAsciiLayerBlocks
|
|
|
|
);
|
2021-08-11 23:47:36 +00:00
|
|
|
this.canTool = false;
|
|
|
|
break;
|
|
|
|
|
2021-08-07 05:36:32 +00:00
|
|
|
case "brush":
|
2021-03-29 00:39:42 +00:00
|
|
|
this.canTool = true;
|
2021-05-22 02:49:19 +00:00
|
|
|
this.drawBrush();
|
2021-03-29 00:39:42 +00:00
|
|
|
break;
|
|
|
|
|
2021-08-07 05:36:32 +00:00
|
|
|
case "eraser":
|
2021-03-29 00:39:42 +00:00
|
|
|
this.canTool = true;
|
2021-05-22 02:49:19 +00:00
|
|
|
this.eraser();
|
2021-03-29 00:39:42 +00:00
|
|
|
break;
|
|
|
|
|
2021-08-07 05:36:32 +00:00
|
|
|
case "dropper":
|
2021-07-24 04:34:49 +00:00
|
|
|
if (this.canFg) {
|
2021-08-07 05:36:32 +00:00
|
|
|
this.$store.commit("changeColourFg", targetBlock.fg);
|
2021-03-29 00:39:42 +00:00
|
|
|
}
|
2021-03-27 04:16:15 +00:00
|
|
|
|
2021-07-24 04:34:49 +00:00
|
|
|
if (this.canBg) {
|
2021-08-07 05:36:32 +00:00
|
|
|
this.$store.commit("changeColourBg", targetBlock.bg);
|
2021-03-29 00:39:42 +00:00
|
|
|
}
|
2021-03-27 04:16:15 +00:00
|
|
|
|
2021-07-24 04:34:49 +00:00
|
|
|
if (this.canText) {
|
2021-08-07 05:36:32 +00:00
|
|
|
this.$store.commit("changeChar", targetBlock.char);
|
2021-03-29 08:21:23 +00:00
|
|
|
}
|
|
|
|
|
2021-08-07 05:36:32 +00:00
|
|
|
this.$store.commit("changeTool", 0);
|
2021-03-29 00:39:42 +00:00
|
|
|
break;
|
|
|
|
}
|
2021-03-27 04:16:15 +00:00
|
|
|
}
|
2021-01-09 01:57:48 +00:00
|
|
|
},
|
2021-03-27 02:07:33 +00:00
|
|
|
canvasMouseMove(e) {
|
2021-08-11 23:47:36 +00:00
|
|
|
if (this.isDefault) return;
|
2021-08-03 06:33:06 +00:00
|
|
|
|
2021-08-07 22:36:00 +00:00
|
|
|
let lastX = this.x;
|
|
|
|
let lastY = this.y;
|
|
|
|
|
2021-03-13 03:30:58 +00:00
|
|
|
if (e.offsetX >= 0) {
|
|
|
|
this.x = e.offsetX;
|
|
|
|
}
|
2021-03-13 05:27:07 +00:00
|
|
|
|
2021-03-13 03:30:58 +00:00
|
|
|
if (e.offsetY >= 0) {
|
|
|
|
this.y = e.offsetY;
|
|
|
|
}
|
|
|
|
|
2021-08-08 00:36:17 +00:00
|
|
|
this.x = Math.floor(this.x / blockWidth);
|
|
|
|
this.y = Math.floor(this.y / blockHeight);
|
2021-03-29 00:39:42 +00:00
|
|
|
|
2021-08-08 00:36:17 +00:00
|
|
|
if (this.x === lastX && this.y === lastY) {
|
2021-08-07 22:36:00 +00:00
|
|
|
return;
|
|
|
|
}
|
2021-08-07 05:36:32 +00:00
|
|
|
this.$emit("coordsupdate", { x: this.x, y: this.y });
|
2021-03-29 05:10:31 +00:00
|
|
|
|
2021-08-11 23:47:36 +00:00
|
|
|
if (this.asciiBlockAtXy) {
|
2021-08-03 04:59:12 +00:00
|
|
|
switch (this.currentTool.name) {
|
2021-08-07 05:36:32 +00:00
|
|
|
case "brush":
|
2021-05-22 02:49:19 +00:00
|
|
|
if (this.isMouseOnCanvas) {
|
2021-08-12 01:52:40 +00:00
|
|
|
this.clearToolCanvas();
|
2021-05-22 02:49:19 +00:00
|
|
|
this.drawBrush();
|
|
|
|
}
|
2021-03-29 00:39:42 +00:00
|
|
|
break;
|
2021-03-27 02:07:33 +00:00
|
|
|
|
2021-08-07 05:36:32 +00:00
|
|
|
case "eraser":
|
2021-08-12 01:52:40 +00:00
|
|
|
this.clearToolCanvas();
|
|
|
|
|
2021-05-22 02:49:19 +00:00
|
|
|
if (this.isMouseOnCanvas) {
|
|
|
|
this.drawBrush(true);
|
2021-03-27 02:07:33 +00:00
|
|
|
}
|
2021-05-22 02:49:19 +00:00
|
|
|
this.eraser();
|
2021-03-29 00:39:42 +00:00
|
|
|
break;
|
2021-04-03 03:13:03 +00:00
|
|
|
|
2021-08-07 05:36:32 +00:00
|
|
|
case "select":
|
2021-04-03 03:13:03 +00:00
|
|
|
if (this.selecting.canSelect) {
|
2021-07-24 01:55:44 +00:00
|
|
|
this.selecting.endX = this.canvasX;
|
|
|
|
this.selecting.endY = this.canvasY;
|
2021-06-05 01:25:23 +00:00
|
|
|
|
|
|
|
this.redrawSelect();
|
2021-07-10 01:41:17 +00:00
|
|
|
}
|
2021-06-05 01:25:23 +00:00
|
|
|
|
|
|
|
if (!this.isSelected) {
|
|
|
|
this.redrawSelect();
|
2021-07-10 01:41:17 +00:00
|
|
|
}
|
2021-04-03 03:13:03 +00:00
|
|
|
|
|
|
|
break;
|
2021-05-22 02:49:19 +00:00
|
|
|
|
2021-08-07 05:36:32 +00:00
|
|
|
case "text":
|
2021-08-12 01:52:40 +00:00
|
|
|
this.clearToolCanvas();
|
2021-05-22 02:49:19 +00:00
|
|
|
this.drawIndicator();
|
2021-08-12 01:52:40 +00:00
|
|
|
|
|
|
|
if (this.isTextEditingValues) {
|
|
|
|
this.drawTextIndicator();
|
|
|
|
}
|
2021-05-22 02:49:19 +00:00
|
|
|
break;
|
|
|
|
|
2021-08-07 05:36:32 +00:00
|
|
|
case "dropper":
|
2021-08-12 01:52:40 +00:00
|
|
|
this.clearToolCanvas();
|
2021-05-22 02:49:19 +00:00
|
|
|
this.drawIndicator();
|
|
|
|
break;
|
|
|
|
|
2021-08-07 05:36:32 +00:00
|
|
|
case "fill":
|
2021-08-11 23:47:36 +00:00
|
|
|
case "fill-eraser":
|
2021-08-12 01:52:40 +00:00
|
|
|
this.clearToolCanvas();
|
2021-05-22 02:49:19 +00:00
|
|
|
this.drawIndicator();
|
|
|
|
break;
|
2021-03-29 00:39:42 +00:00
|
|
|
}
|
2021-03-27 02:07:33 +00:00
|
|
|
}
|
|
|
|
|
2021-03-29 00:39:42 +00:00
|
|
|
this.delayRedrawCanvas();
|
2021-03-13 03:30:58 +00:00
|
|
|
},
|
2021-04-03 03:13:03 +00:00
|
|
|
clearToolCanvas() {
|
2021-05-01 02:17:49 +00:00
|
|
|
if (this.toolCtx) {
|
2021-08-07 22:36:00 +00:00
|
|
|
this.toolCtx.clearRect(0, 0, this.canvas.width, this.canvas.height);
|
2021-04-03 03:13:03 +00:00
|
|
|
}
|
|
|
|
},
|
2021-03-27 02:07:33 +00:00
|
|
|
delayRedrawCanvas() {
|
|
|
|
if (this.redraw) {
|
|
|
|
this.redraw = false;
|
2021-08-07 22:36:00 +00:00
|
|
|
requestAnimationFrame(() => {
|
2021-03-29 00:39:42 +00:00
|
|
|
this.redraw = true;
|
2021-03-27 02:07:33 +00:00
|
|
|
this.redrawCanvas();
|
2021-08-07 22:36:00 +00:00
|
|
|
});
|
2021-03-27 02:07:33 +00:00
|
|
|
}
|
2021-03-26 11:36:37 +00:00
|
|
|
},
|
2021-08-07 02:41:47 +00:00
|
|
|
getBlocksWidth(blocks) {
|
2021-08-07 05:36:32 +00:00
|
|
|
return getBlocksWidth(blocks);
|
2021-08-07 02:41:47 +00:00
|
|
|
},
|
|
|
|
filterNullBlocks(blocks) {
|
2021-08-07 05:36:32 +00:00
|
|
|
return filterNullBlocks(blocks);
|
2021-08-07 02:41:47 +00:00
|
|
|
},
|
2021-04-03 03:13:03 +00:00
|
|
|
//
|
|
|
|
// TOOLS
|
|
|
|
//
|
2021-08-03 03:00:32 +00:00
|
|
|
processSelect() {
|
2021-08-03 04:59:12 +00:00
|
|
|
//
|
|
|
|
let x = 0;
|
|
|
|
let y = 0;
|
2021-08-03 03:00:32 +00:00
|
|
|
|
2021-08-03 04:59:12 +00:00
|
|
|
let curBlock = {};
|
|
|
|
this.selectedBlocks = [];
|
2021-08-03 03:00:32 +00:00
|
|
|
|
2021-08-07 05:36:32 +00:00
|
|
|
// If we select from the bottom right towards top left
|
|
|
|
// we need to swap the values
|
2021-08-07 02:41:47 +00:00
|
|
|
if (this.selecting.endY < this.selecting.startY) {
|
|
|
|
let end = this.selecting.endY;
|
|
|
|
let start = this.selecting.startY;
|
|
|
|
|
|
|
|
this.selecting.startY = end;
|
|
|
|
this.selecting.endY = start;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.selecting.endX < this.selecting.startX) {
|
|
|
|
let end = this.selecting.endX;
|
|
|
|
let start = this.selecting.startX;
|
|
|
|
|
|
|
|
this.selecting.startX = end;
|
|
|
|
this.selecting.endX = start;
|
|
|
|
}
|
|
|
|
|
2021-08-15 00:57:37 +00:00
|
|
|
for (y = 0; y < this.currentAsciiHeight; y++) {
|
2021-08-03 04:59:12 +00:00
|
|
|
if (
|
2021-08-08 03:24:06 +00:00
|
|
|
y > Math.floor(this.selecting.startY / blockHeight) - 1 &&
|
2021-08-08 00:36:17 +00:00
|
|
|
y < Math.floor(this.selecting.endY / blockHeight)
|
2021-08-03 04:59:12 +00:00
|
|
|
) {
|
|
|
|
if (!this.selectedBlocks[y]) {
|
|
|
|
this.selectedBlocks[y] = [];
|
|
|
|
}
|
|
|
|
|
2021-08-15 00:57:37 +00:00
|
|
|
for (x = 0; x < this.currentAsciiWidth; x++) {
|
2021-08-03 03:00:32 +00:00
|
|
|
if (
|
2021-08-08 03:24:06 +00:00
|
|
|
x > Math.ceil(this.selecting.startX / blockWidth) - 1 &&
|
|
|
|
x <= Math.ceil(this.selecting.endX / blockWidth) - 1
|
2021-08-03 03:00:32 +00:00
|
|
|
) {
|
2021-08-14 09:09:36 +00:00
|
|
|
if (
|
|
|
|
this.currentAsciiLayerBlocks[y] &&
|
|
|
|
this.currentAsciiLayerBlocks[y][x]
|
|
|
|
) {
|
|
|
|
curBlock = { ...this.currentAsciiLayerBlocks[y][x] };
|
2021-08-03 03:00:32 +00:00
|
|
|
|
2021-08-03 04:59:12 +00:00
|
|
|
if (!this.selectedBlocks[y][x]) {
|
|
|
|
this.selectedBlocks[y][x] = { ...curBlock };
|
2021-08-03 03:00:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-08-03 04:59:12 +00:00
|
|
|
}
|
|
|
|
}
|
2021-08-16 04:10:06 +00:00
|
|
|
|
|
|
|
this.$emit("selectedblocks", this.selectedBlocks);
|
2021-08-17 00:24:41 +00:00
|
|
|
this.$emit("selecting", this.selecting);
|
2021-08-03 03:00:32 +00:00
|
|
|
},
|
2021-08-12 01:52:40 +00:00
|
|
|
drawRectangleBlock(x, y) {
|
|
|
|
let indicatorColour = this.asciiBlockAtXy.bg === 0 ? 1 : 0;
|
2021-05-29 00:45:16 +00:00
|
|
|
|
2021-08-12 01:52:40 +00:00
|
|
|
if (this.asciiBlockAtXy.bg === 8) {
|
2021-05-29 00:45:16 +00:00
|
|
|
indicatorColour = 1;
|
|
|
|
}
|
|
|
|
|
2021-08-03 03:00:32 +00:00
|
|
|
this.toolCtx.fillStyle = this.mircColours[indicatorColour];
|
2021-06-05 01:25:23 +00:00
|
|
|
|
2021-05-22 02:49:19 +00:00
|
|
|
this.toolCtx.fillRect(
|
2021-08-12 01:52:40 +00:00
|
|
|
x * blockWidth,
|
|
|
|
y * blockHeight,
|
|
|
|
blockWidth,
|
|
|
|
blockHeight
|
2021-05-22 02:49:19 +00:00
|
|
|
);
|
|
|
|
|
2021-08-12 01:52:40 +00:00
|
|
|
this.toolCtx.setLineDash([1, 2]);
|
|
|
|
this.toolCtx.strokeRect(
|
|
|
|
x * blockWidth,
|
|
|
|
y * blockHeight,
|
|
|
|
blockWidth,
|
|
|
|
blockHeight
|
|
|
|
);
|
|
|
|
},
|
|
|
|
drawIndicator() {
|
|
|
|
this.drawRectangleBlock(this.x, this.y);
|
|
|
|
|
2021-08-15 01:20:58 +00:00
|
|
|
// We can draw icons on the tool canvas with the font awesome CSS
|
|
|
|
// it needs more work though to not conflict with the brush preview chars
|
|
|
|
// if (this.isTextEditing) {
|
|
|
|
// this.toolCtx.font = '600 22px "Font Awesome 5 Free"';
|
|
|
|
// this.toolCtx.fillText(
|
|
|
|
// "\uf031",
|
|
|
|
// this.x * blockWidth,
|
|
|
|
// this.y * blockHeight + blockHeight * 2
|
|
|
|
// );
|
|
|
|
// // this.toolCtx.font = "13px Hack";
|
|
|
|
// }
|
2021-08-11 23:47:36 +00:00
|
|
|
|
2021-07-31 02:12:11 +00:00
|
|
|
if (this.isTextEditing) {
|
|
|
|
if (this.mirrorX) {
|
2021-08-15 00:57:37 +00:00
|
|
|
this.drawRectangleBlock(this.currentAsciiWidth - this.x, this.y);
|
2021-07-31 02:12:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (this.mirrorY) {
|
2021-08-15 00:57:37 +00:00
|
|
|
this.drawRectangleBlock(this.x, this.currentAsciiHeight - this.y);
|
2021-07-31 02:12:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (this.mirrorY && this.mirrorX) {
|
2021-08-12 01:52:40 +00:00
|
|
|
this.drawRectangleBlock(
|
2021-08-15 00:57:37 +00:00
|
|
|
this.currentAsciiWidth - this.x,
|
|
|
|
this.currentAsciiHeight - this.y
|
2021-07-31 02:12:11 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2021-05-22 02:49:19 +00:00
|
|
|
},
|
|
|
|
drawTextIndicator() {
|
2021-08-12 01:52:40 +00:00
|
|
|
this.drawRectangleBlock(this.textEditing.startX, this.textEditing.startY);
|
2021-05-22 02:49:19 +00:00
|
|
|
|
2021-07-31 02:12:11 +00:00
|
|
|
if (this.mirrorX) {
|
2021-08-12 01:52:40 +00:00
|
|
|
this.drawRectangleBlock(
|
2021-08-15 00:57:37 +00:00
|
|
|
this.currentAsciiWidth - this.textEditing.startX,
|
2021-08-12 01:52:40 +00:00
|
|
|
this.textEditing.startY
|
2021-07-31 02:12:11 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.mirrorY) {
|
2021-08-12 01:52:40 +00:00
|
|
|
this.drawRectangleBlock(
|
|
|
|
this.textEditing.startX,
|
2021-08-15 00:57:37 +00:00
|
|
|
this.currentAsciiHeight - this.textEditing.startY
|
2021-07-31 02:12:11 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.mirrorY && this.mirrorX) {
|
2021-08-12 01:52:40 +00:00
|
|
|
this.drawRectangleBlock(
|
2021-08-15 00:57:37 +00:00
|
|
|
this.currentAsciiWidth - this.textEditing.startX,
|
|
|
|
this.currentAsciiHeight - this.textEditing.startY
|
2021-07-31 02:12:11 +00:00
|
|
|
);
|
|
|
|
}
|
2021-05-22 02:49:19 +00:00
|
|
|
},
|
2021-07-31 02:12:11 +00:00
|
|
|
//
|
2021-08-16 02:10:09 +00:00
|
|
|
// Functions related to drawBrush function bellow
|
|
|
|
//
|
2021-08-16 02:39:30 +00:00
|
|
|
drawBrushBlocks(brushX, brushY, brushBlock, target = null, plain = false) {
|
2021-08-16 02:10:09 +00:00
|
|
|
const arrayY = brushY / blockHeight;
|
|
|
|
const arrayX = brushX / blockWidth;
|
|
|
|
const asciiWidth = this.currentAsciiWidth;
|
|
|
|
const asciiHeight = this.currentAsciiHeight;
|
|
|
|
let targetBlock = this.currentAsciiLayerBlocks[arrayY][arrayX];
|
|
|
|
|
|
|
|
if (plain) {
|
|
|
|
// Used for eraser preview and other non brushs
|
|
|
|
let indicatorColour = targetBlock.bg === 0 ? 1 : 0;
|
|
|
|
|
|
|
|
if (targetBlock.bg === 8) {
|
|
|
|
indicatorColour = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.toolCtx.fillStyle = this.mircColours[indicatorColour];
|
|
|
|
|
|
|
|
this.toolCtx.fillRect(brushX, brushY, blockWidth, blockHeight);
|
|
|
|
|
|
|
|
if (this.mirrorX) {
|
|
|
|
this.toolCtx.fillRect(
|
|
|
|
(asciiWidth - arrayX) * blockWidth,
|
|
|
|
brushY,
|
|
|
|
blockWidth,
|
|
|
|
blockHeight
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.mirrorY) {
|
|
|
|
this.toolCtx.fillRect(
|
|
|
|
brushX,
|
|
|
|
(asciiHeight - arrayY) * blockHeight,
|
|
|
|
blockWidth,
|
|
|
|
blockHeight
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.mirrorY && this.mirrorX) {
|
|
|
|
this.toolCtx.fillRect(
|
|
|
|
(asciiWidth - arrayX) * blockWidth,
|
|
|
|
(asciiHeight - arrayY) * blockHeight,
|
|
|
|
blockWidth,
|
|
|
|
blockHeight
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (target) {
|
|
|
|
case "bg":
|
|
|
|
this.toolCtx.fillStyle =
|
|
|
|
brushBlock.bg !== null
|
|
|
|
? this.mircColours[brushBlock.bg]
|
|
|
|
: "rgba(255,255,255,0.4)";
|
|
|
|
|
|
|
|
break;
|
|
|
|
case "fg":
|
|
|
|
this.toolCtx.fillStyle =
|
|
|
|
brushBlock.fg !== null
|
|
|
|
? this.mircColours[brushBlock.fg]
|
|
|
|
: "#000000";
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
// If no target is specified we assume we are rendering the text
|
|
|
|
default:
|
|
|
|
if (this.canText && brushBlock.char !== null) {
|
|
|
|
this.toolCtx.font = "Hack 13px";
|
|
|
|
|
|
|
|
this.toolCtx.fillStyle = this.canFg
|
|
|
|
? this.mircColours[brushBlock.fg]
|
|
|
|
: "#000000";
|
|
|
|
|
|
|
|
this.toolCtx.fillText(
|
|
|
|
brushBlock.char,
|
|
|
|
brushX,
|
|
|
|
brushY + blockHeight - 3
|
|
|
|
);
|
|
|
|
|
|
|
|
if (this.mirrorX) {
|
|
|
|
this.toolCtx.fillText(
|
|
|
|
brushBlock.char,
|
|
|
|
(asciiWidth - arrayX) * blockWidth,
|
|
|
|
brushY + blockHeight - 4
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.mirrorY) {
|
|
|
|
this.toolCtx.fillText(
|
|
|
|
brushBlock.char,
|
|
|
|
brushX,
|
|
|
|
(asciiHeight - arrayY) * blockHeight + 10
|
|
|
|
);
|
|
|
|
}
|
|
|
|
if (this.mirrorY && this.mirrorX) {
|
|
|
|
this.toolCtx.fillText(
|
|
|
|
brushBlock.char,
|
|
|
|
(asciiWidth - arrayX) * blockWidth,
|
|
|
|
(asciiHeight - arrayY) * blockHeight + 10
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Apply text to ascii blocks
|
|
|
|
if (this.canText && this.canTool && brushBlock.char !== null) {
|
|
|
|
targetBlock.char = brushBlock.char;
|
|
|
|
|
|
|
|
if (
|
|
|
|
this.mirrorX &&
|
|
|
|
this.currentAsciiLayerBlocks[arrayY] &&
|
|
|
|
this.currentAsciiLayerBlocks[arrayY][asciiWidth - arrayX]
|
|
|
|
) {
|
|
|
|
this.currentAsciiLayerBlocks[arrayY][asciiWidth - arrayX].char =
|
|
|
|
brushBlock.char;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (
|
|
|
|
this.mirrorY &&
|
|
|
|
this.currentAsciiLayerBlocks[asciiHeight - arrayY] &&
|
|
|
|
this.currentAsciiLayerBlocks[asciiHeight - arrayY][arrayX]
|
|
|
|
) {
|
|
|
|
this.currentAsciiLayerBlocks[asciiHeight - arrayY][arrayX].char =
|
|
|
|
brushBlock.char;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (
|
|
|
|
this.mirrorY &&
|
|
|
|
this.mirrorX &&
|
|
|
|
this.currentAsciiLayerBlocks[asciiHeight - arrayY] &&
|
|
|
|
this.currentAsciiLayerBlocks[asciiHeight - arrayY][
|
|
|
|
asciiWidth - arrayX
|
|
|
|
]
|
|
|
|
) {
|
|
|
|
this.currentAsciiLayerBlocks[asciiHeight - arrayY][
|
|
|
|
asciiWidth - arrayX
|
|
|
|
].char = brushBlock.char;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.canBg && target == "bg") {
|
|
|
|
this.toolCtx.setLineDash([1, 2]);
|
|
|
|
this.toolCtx.strokeRect(brushX, brushY, blockWidth, blockHeight);
|
|
|
|
this.toolCtx.fillRect(brushX, brushY, blockWidth, blockHeight);
|
|
|
|
|
|
|
|
if (this.mirrorX) {
|
|
|
|
this.toolCtx.fillRect(
|
|
|
|
(asciiWidth - arrayX) * blockWidth,
|
|
|
|
brushY,
|
|
|
|
blockWidth,
|
|
|
|
blockHeight
|
|
|
|
);
|
|
|
|
|
|
|
|
this.toolCtx.setLineDash([1, 2]);
|
|
|
|
this.toolCtx.strokeRect(
|
|
|
|
(asciiWidth - arrayX) * blockWidth,
|
|
|
|
brushY,
|
|
|
|
blockWidth,
|
|
|
|
blockHeight
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.mirrorY) {
|
|
|
|
this.toolCtx.fillRect(
|
|
|
|
brushX,
|
|
|
|
(asciiHeight - arrayY) * blockHeight,
|
|
|
|
blockWidth,
|
|
|
|
blockHeight
|
|
|
|
);
|
|
|
|
|
|
|
|
this.toolCtx.setLineDash([1, 2]);
|
|
|
|
this.toolCtx.strokeRect(
|
|
|
|
brushX,
|
|
|
|
(asciiHeight - arrayY) * blockHeight,
|
|
|
|
blockWidth,
|
|
|
|
blockHeight
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.mirrorY && this.mirrorX) {
|
|
|
|
this.toolCtx.fillRect(
|
|
|
|
(asciiWidth - arrayX) * blockWidth,
|
|
|
|
(asciiHeight - arrayY) * blockHeight,
|
|
|
|
blockWidth,
|
|
|
|
blockHeight
|
|
|
|
);
|
|
|
|
|
|
|
|
this.toolCtx.setLineDash([1, 2]);
|
|
|
|
this.toolCtx.strokeRect(
|
|
|
|
(asciiWidth - arrayX) * blockWidth,
|
|
|
|
(asciiHeight - arrayY) * blockHeight,
|
|
|
|
blockWidth,
|
|
|
|
blockHeight
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Apply the actual brush block to the ascii block
|
|
|
|
if (this.canTool && brushBlock[target] !== null) {
|
|
|
|
targetBlock[target] = brushBlock[target];
|
|
|
|
|
|
|
|
if (
|
|
|
|
this.mirrorX &&
|
|
|
|
this.currentAsciiLayerBlocks[arrayY] &&
|
|
|
|
this.currentAsciiLayerBlocks[arrayY][asciiWidth - arrayX]
|
|
|
|
) {
|
|
|
|
this.currentAsciiLayerBlocks[arrayY][asciiWidth - arrayX][target] =
|
|
|
|
brushBlock[target];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (
|
|
|
|
this.mirrorY &&
|
|
|
|
this.currentAsciiLayerBlocks[asciiHeight - arrayY] &&
|
|
|
|
this.currentAsciiLayerBlocks[asciiHeight - arrayY][arrayX]
|
|
|
|
) {
|
|
|
|
this.currentAsciiLayerBlocks[asciiHeight - arrayY][arrayX][target] =
|
|
|
|
brushBlock[target];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (
|
|
|
|
this.mirrorY &&
|
|
|
|
this.mirrorX &&
|
|
|
|
this.currentAsciiLayerBlocks[asciiHeight - arrayY] &&
|
|
|
|
this.currentAsciiLayerBlocks[asciiHeight - arrayY][
|
|
|
|
asciiWidth - arrayX
|
|
|
|
]
|
|
|
|
) {
|
|
|
|
this.currentAsciiLayerBlocks[asciiHeight - arrayY][
|
|
|
|
asciiWidth - arrayX
|
|
|
|
][target] = brushBlock[target];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
//
|
2021-07-31 02:12:11 +00:00
|
|
|
// drawBrush
|
|
|
|
// - draws brush
|
|
|
|
// - draws preview for all toolbar things that need it
|
|
|
|
// - also works with the copy / paste
|
2021-05-22 02:49:19 +00:00
|
|
|
drawBrush(plain = false) {
|
|
|
|
this.clearToolCanvas();
|
2021-07-24 04:34:49 +00:00
|
|
|
let brushDiffX = 0;
|
|
|
|
let xLength = 0;
|
|
|
|
|
|
|
|
// If the first row isn't selected then we cannot get the width
|
|
|
|
// with the 0 index
|
|
|
|
for (let i = 0; i <= this.brushBlocks.length; i++) {
|
|
|
|
if (this.brushBlocks[i]) {
|
2021-08-12 01:52:40 +00:00
|
|
|
brushDiffX = Math.floor(this.brushBlocks[i].length / 2) * blockWidth;
|
2021-07-24 04:34:49 +00:00
|
|
|
xLength = this.brushBlocks[i].length;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2021-05-08 01:51:30 +00:00
|
|
|
|
2021-08-12 01:52:40 +00:00
|
|
|
const brushDiffY = Math.floor(this.brushBlocks.length / 2) * blockHeight;
|
2021-05-29 00:28:30 +00:00
|
|
|
|
2021-06-29 01:49:39 +00:00
|
|
|
for (let y = 0; y < this.brushBlocks.length; y++) {
|
2021-07-24 01:55:44 +00:00
|
|
|
if (!this.brushBlocks[y]) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2021-07-24 04:34:49 +00:00
|
|
|
for (let x = 0; x < xLength; x++) {
|
2021-07-24 01:55:44 +00:00
|
|
|
if (!this.brushBlocks[y][x]) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2021-08-04 03:21:06 +00:00
|
|
|
const brushBlock = this.brushBlocks[y][x];
|
2021-05-08 01:51:30 +00:00
|
|
|
|
2021-08-12 01:52:40 +00:00
|
|
|
const brushX = this.x * blockWidth + x * blockWidth - brushDiffX;
|
|
|
|
const brushY = this.y * blockHeight + y * blockHeight - brushDiffY;
|
2021-05-22 02:49:19 +00:00
|
|
|
|
2021-08-12 01:52:40 +00:00
|
|
|
const arrayY = brushY / blockHeight;
|
|
|
|
const arrayX = brushX / blockWidth;
|
2021-05-29 01:09:09 +00:00
|
|
|
|
2021-08-19 01:42:33 +00:00
|
|
|
if (this.currentAsciiLayerBlocks[arrayY] && this.currentAsciiLayerBlocks[arrayY][arrayX]) {
|
2021-05-22 02:49:19 +00:00
|
|
|
if (!plain) {
|
2021-06-05 01:25:23 +00:00
|
|
|
if (this.canBg) {
|
2021-08-16 02:39:30 +00:00
|
|
|
this.drawBrushBlocks(brushX, brushY, brushBlock, "bg");
|
2021-05-22 02:49:19 +00:00
|
|
|
}
|
|
|
|
|
2021-06-05 01:25:23 +00:00
|
|
|
if (this.canFg) {
|
2021-08-16 02:39:30 +00:00
|
|
|
this.drawBrushBlocks(brushX, brushY, brushBlock, "fg");
|
2021-07-31 02:12:11 +00:00
|
|
|
}
|
|
|
|
|
2021-08-16 02:39:30 +00:00
|
|
|
this.drawBrushBlocks(brushX, brushY, brushBlock, null);
|
2021-08-16 02:10:09 +00:00
|
|
|
} else {
|
2021-08-16 02:39:30 +00:00
|
|
|
this.drawBrushBlocks(brushX, brushY, brushBlock, null, true);
|
2021-05-22 02:49:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
eraser() {
|
|
|
|
if (this.canTool) {
|
2021-08-11 23:47:36 +00:00
|
|
|
let targetBlock = this.asciiBlockAtXy;
|
2021-05-22 02:49:19 +00:00
|
|
|
|
2021-08-07 05:36:32 +00:00
|
|
|
const brushDiffX =
|
2021-08-12 01:52:40 +00:00
|
|
|
Math.floor(this.brushBlocks[0].length / 2) * blockWidth;
|
2021-08-07 05:36:32 +00:00
|
|
|
const brushDiffY =
|
2021-08-12 01:52:40 +00:00
|
|
|
Math.floor(this.brushBlocks.length / 2) * blockHeight;
|
2021-05-29 01:09:09 +00:00
|
|
|
|
2021-08-03 04:59:12 +00:00
|
|
|
for (let y = 0; y < this.brushBlocks.length; y++) {
|
|
|
|
for (let x = 0; x < this.brushBlocks[0].length; x++) {
|
2021-08-12 01:52:40 +00:00
|
|
|
const brushX = this.x * blockWidth + x * blockWidth - brushDiffX;
|
2021-08-12 03:19:06 +00:00
|
|
|
const brushY = this.y * blockHeight + y * blockHeight - brushDiffY;
|
2021-05-22 02:49:19 +00:00
|
|
|
|
2021-08-12 01:52:40 +00:00
|
|
|
const arrayY = brushY / blockHeight;
|
|
|
|
const arrayX = brushX / blockWidth;
|
2021-07-31 02:12:11 +00:00
|
|
|
|
2021-08-11 23:47:36 +00:00
|
|
|
if (this.asciiBlockAtXy) {
|
2021-08-14 09:09:36 +00:00
|
|
|
targetBlock = this.currentAsciiLayerBlocks[arrayY][arrayX];
|
2021-05-22 02:49:19 +00:00
|
|
|
|
2021-07-31 02:12:11 +00:00
|
|
|
if (this.canFg) {
|
2021-05-22 02:49:19 +00:00
|
|
|
targetBlock.fg = null;
|
2021-05-08 01:51:30 +00:00
|
|
|
}
|
|
|
|
|
2021-07-31 02:12:11 +00:00
|
|
|
if (this.canBg) {
|
2021-05-22 02:49:19 +00:00
|
|
|
targetBlock.bg = null;
|
|
|
|
}
|
|
|
|
|
2021-07-31 02:12:11 +00:00
|
|
|
if (this.canText) {
|
2021-05-22 02:49:19 +00:00
|
|
|
targetBlock.char = null;
|
|
|
|
}
|
2021-06-05 01:25:23 +00:00
|
|
|
}
|
2021-07-31 02:12:11 +00:00
|
|
|
|
|
|
|
if (this.mirrorX) {
|
|
|
|
if (
|
2021-08-14 09:09:36 +00:00
|
|
|
this.currentAsciiLayerBlocks[arrayY] &&
|
|
|
|
this.currentAsciiLayerBlocks[arrayY][
|
2021-08-15 00:57:37 +00:00
|
|
|
this.currentAsciiWidth - arrayX
|
2021-07-31 02:12:11 +00:00
|
|
|
]
|
|
|
|
) {
|
2021-08-07 05:36:32 +00:00
|
|
|
targetBlock =
|
2021-08-14 09:09:36 +00:00
|
|
|
this.currentAsciiLayerBlocks[arrayY][
|
2021-08-15 00:57:37 +00:00
|
|
|
this.currentAsciiWidth - arrayX
|
2021-08-07 05:36:32 +00:00
|
|
|
];
|
2021-07-31 02:12:11 +00:00
|
|
|
|
|
|
|
if (this.canFg) {
|
|
|
|
targetBlock.fg = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.canBg) {
|
|
|
|
targetBlock.bg = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.canText) {
|
|
|
|
targetBlock.char = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.mirrorY) {
|
|
|
|
if (
|
2021-08-14 09:09:36 +00:00
|
|
|
this.currentAsciiLayerBlocks[
|
2021-08-15 00:57:37 +00:00
|
|
|
this.currentAsciiHeight - arrayY
|
2021-08-14 09:09:36 +00:00
|
|
|
] &&
|
2021-08-15 00:57:37 +00:00
|
|
|
this.currentAsciiLayerBlocks[this.currentAsciiHeight - arrayY][
|
2021-07-31 02:12:11 +00:00
|
|
|
arrayX
|
|
|
|
]
|
|
|
|
) {
|
2021-08-07 05:36:32 +00:00
|
|
|
targetBlock =
|
2021-08-14 09:09:36 +00:00
|
|
|
this.currentAsciiLayerBlocks[
|
2021-08-15 00:57:37 +00:00
|
|
|
this.currentAsciiHeight - arrayY
|
2021-08-14 09:09:36 +00:00
|
|
|
][arrayX];
|
2021-07-31 02:12:11 +00:00
|
|
|
|
|
|
|
if (this.canFg) {
|
|
|
|
targetBlock.fg = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.canBg) {
|
|
|
|
targetBlock.bg = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.canText) {
|
|
|
|
targetBlock.char = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.mirrorY && this.mirrorX) {
|
|
|
|
if (
|
2021-08-14 09:09:36 +00:00
|
|
|
this.currentAsciiLayerBlocks[
|
2021-08-15 00:57:37 +00:00
|
|
|
this.currentAsciiHeight - arrayY
|
2021-08-14 09:09:36 +00:00
|
|
|
] &&
|
2021-08-15 00:57:37 +00:00
|
|
|
this.currentAsciiLayerBlocks[this.currentAsciiHeight - arrayY][
|
|
|
|
this.currentAsciiWidth - arrayX
|
2021-07-31 02:12:11 +00:00
|
|
|
]
|
|
|
|
) {
|
2021-08-07 05:36:32 +00:00
|
|
|
targetBlock =
|
2021-08-14 09:09:36 +00:00
|
|
|
this.currentAsciiLayerBlocks[
|
2021-08-15 00:57:37 +00:00
|
|
|
this.currentAsciiHeight - arrayY
|
|
|
|
][this.currentAsciiWidth - arrayX];
|
2021-07-31 02:12:11 +00:00
|
|
|
|
|
|
|
if (this.canFg) {
|
|
|
|
targetBlock.fg = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.canBg) {
|
|
|
|
targetBlock.bg = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.canText) {
|
|
|
|
targetBlock.char = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-05-22 02:49:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-05-08 01:51:30 +00:00
|
|
|
},
|
2021-05-22 02:49:19 +00:00
|
|
|
// Fill tool
|
2021-08-11 23:47:36 +00:00
|
|
|
fill(eraser = false) {
|
2021-08-03 03:00:32 +00:00
|
|
|
const newColor = this.currentBg;
|
2021-08-11 23:47:36 +00:00
|
|
|
const current = this.asciiBlockAtXy.bg;
|
2021-04-02 04:43:11 +00:00
|
|
|
|
2021-04-03 03:13:03 +00:00
|
|
|
// If the newColor is same as the existing
|
|
|
|
// Then return the original image.
|
2021-08-11 23:47:36 +00:00
|
|
|
if (current === newColor && !eraser) {
|
2021-08-14 06:41:42 +00:00
|
|
|
return;
|
2021-04-02 04:43:11 +00:00
|
|
|
}
|
2021-03-27 04:24:05 +00:00
|
|
|
|
2021-08-14 09:09:36 +00:00
|
|
|
this.fillTool(
|
|
|
|
this.currentAsciiLayerBlocks,
|
|
|
|
this.y,
|
|
|
|
this.x,
|
|
|
|
current,
|
|
|
|
eraser
|
|
|
|
);
|
2021-04-02 04:43:11 +00:00
|
|
|
},
|
2021-08-11 23:47:36 +00:00
|
|
|
fillTool(fillBlocks, y, x, current, eraser) {
|
2021-08-19 00:23:12 +00:00
|
|
|
if(fillBlocks[y] === undefined || fillBlocks[y][x] === undefined) {
|
2021-04-02 04:43:11 +00:00
|
|
|
return;
|
|
|
|
}
|
2021-04-02 00:19:33 +00:00
|
|
|
|
2021-04-03 03:13:03 +00:00
|
|
|
// If the current pixel is not which needs to be replaced
|
2021-04-02 04:43:11 +00:00
|
|
|
if (fillBlocks[y][x].bg !== current) {
|
|
|
|
return;
|
|
|
|
}
|
2021-04-02 03:44:08 +00:00
|
|
|
|
2021-08-11 23:47:36 +00:00
|
|
|
// We can eraser or fill
|
2021-07-17 01:44:27 +00:00
|
|
|
if (this.canBg) {
|
2021-08-11 23:47:36 +00:00
|
|
|
fillBlocks[y][x].bg = eraser ? null : this.currentBg;
|
2021-07-17 01:44:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (this.canFg) {
|
2021-08-11 23:47:36 +00:00
|
|
|
fillBlocks[y][x].fg = eraser ? null : this.currentFg;
|
2021-07-17 01:44:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (this.canText) {
|
2021-08-11 23:47:36 +00:00
|
|
|
fillBlocks[y][x].char = eraser ? null : this.currentChar;
|
2021-07-17 01:44:27 +00:00
|
|
|
}
|
2021-04-02 03:44:08 +00:00
|
|
|
|
2021-04-03 03:13:03 +00:00
|
|
|
// Fill in all four directions
|
|
|
|
// Fill Prev row
|
2021-08-11 23:47:36 +00:00
|
|
|
this.fillTool(fillBlocks, y, x - 1, current, eraser);
|
2021-04-02 03:44:08 +00:00
|
|
|
|
2021-04-03 03:13:03 +00:00
|
|
|
// Fill Next row
|
2021-08-11 23:47:36 +00:00
|
|
|
this.fillTool(fillBlocks, y, x + 1, current, eraser);
|
2021-04-02 03:44:08 +00:00
|
|
|
|
2021-04-03 03:13:03 +00:00
|
|
|
// Fill Prev col
|
2021-08-11 23:47:36 +00:00
|
|
|
this.fillTool(fillBlocks, y - 1, x, current, eraser);
|
2021-04-02 03:36:00 +00:00
|
|
|
|
2021-04-03 03:13:03 +00:00
|
|
|
// Fill next col
|
2021-08-11 23:47:36 +00:00
|
|
|
this.fillTool(fillBlocks, y + 1, x, current, eraser);
|
2021-01-10 03:06:46 +00:00
|
|
|
},
|
2020-12-27 02:42:26 +00:00
|
|
|
},
|
2020-12-19 01:27:50 +00:00
|
|
|
};
|
|
|
|
</script>
|