advent22/ui/src/components/door_map/DoorPlacer.vue

83 lines
1.8 KiB
Vue
Raw Normal View History

2023-01-19 17:59:18 +00:00
<template>
<section>
<div class="content">
2023-02-02 18:06:55 +00:00
<p class="title is-5">Steuerung</p>
2023-01-19 17:59:18 +00:00
<ul>
<li>Linksklick + Ziehen: Neues Türchen erstellen</li>
<li>Rechtsklick + Ziehen: Türchen verschieben</li>
<li>Doppel- oder Mittelklick: Türchen löschen</li>
</ul>
</div>
<figure class="image">
2023-09-04 21:23:27 +00:00
<img :src="$advent22.api_url('general/background')" />
2023-02-02 14:12:44 +00:00
<RectangleCanvas
:rectangles="rectangles"
@draw="on_draw"
@drag="on_drag"
@remove="on_remove"
/>
2023-01-19 17:59:18 +00:00
</figure>
</section>
</template>
<script lang="ts">
import { Vue, Options } from "vue-class-component";
2023-02-02 14:12:44 +00:00
import { Rectangle } from "../rects/rectangles";
2023-02-01 16:53:24 +00:00
import { Door } from "./calendar";
2023-01-27 00:23:41 +00:00
import RectangleCanvas from "./RectangleCanvas.vue";
2023-01-19 17:59:18 +00:00
@Options({
components: {
2023-01-27 00:23:41 +00:00
RectangleCanvas,
2023-01-19 17:59:18 +00:00
},
2023-01-23 23:37:23 +00:00
props: {
2023-02-01 16:53:24 +00:00
doors: Array,
2023-01-23 23:37:23 +00:00
},
2023-02-01 16:53:24 +00:00
emits: ["update:doors"],
2023-01-19 17:59:18 +00:00
})
2023-01-24 23:19:25 +00:00
export default class extends Vue {
2023-02-01 16:53:24 +00:00
private doors!: Door[];
2023-01-23 23:37:23 +00:00
2023-02-01 16:53:24 +00:00
private get rectangles() {
2023-02-02 15:28:30 +00:00
return this.doors.map((door) => door.position);
2023-01-23 23:37:23 +00:00
}
2023-02-02 14:12:44 +00:00
private on_draw(position: Rectangle) {
2023-02-02 18:06:55 +00:00
this.doors.push(new Door(position));
2023-02-02 14:12:44 +00:00
}
private find_door_index(position: Rectangle): number {
return this.doors.findIndex((door) => door.position.equals(position));
}
private on_drag(old_pos: Rectangle, new_pos: Rectangle) {
const idx = this.find_door_index(old_pos);
if (idx === -1) {
return;
}
this.doors[idx].position = new_pos;
}
private on_remove(position: Rectangle) {
const idx = this.find_door_index(position);
if (idx === -1) {
return;
}
this.doors.splice(idx, 1);
}
2023-01-23 23:37:23 +00:00
public beforeUnmount() {
2023-02-01 16:53:24 +00:00
this.$emit("update:doors", this.doors);
2023-01-23 23:37:23 +00:00
}
}
2023-01-19 17:59:18 +00:00
</script>
<style lang="scss" scoped>
section > figure {
user-select: none;
}
</style>