WIP: Door class (breaking)

This commit is contained in:
Jörn-Michael Miehe 2023-02-01 16:53:24 +00:00
parent be78671ffe
commit 78f2b981e3
4 changed files with 28 additions and 13 deletions

View file

@ -12,6 +12,7 @@
<script lang="ts"> <script lang="ts">
import { Vue, Options } from "vue-class-component"; import { Vue, Options } from "vue-class-component";
import { Door } from "./door_map/calendar";
import { Rectangle } from "./rects/rectangles"; import { Rectangle } from "./rects/rectangles";
import BulmaBreadcrumb, { Step } from "./BulmaBreadcrumb.vue"; import BulmaBreadcrumb, { Step } from "./BulmaBreadcrumb.vue";
@ -32,6 +33,7 @@ export default class extends Vue {
{ label: "Überprüfen", icon: "fa-solid fa-check" }, { label: "Überprüfen", icon: "fa-solid fa-check" },
]; ];
private current_step = 0; private current_step = 0;
private doors: Door[] = [];
private rectangles: Rectangle[] = []; private rectangles: Rectangle[] = [];
} }
</script> </script>

View file

@ -9,14 +9,14 @@
</div> </div>
<figure class="image"> <figure class="image">
<img src="@/assets/adventskalender.jpg" /> <img src="@/assets/adventskalender.jpg" />
<RectangleCanvas ref="rect_pad" /> <RectangleCanvas v-model="rectangles" />
</figure> </figure>
</section> </section>
</template> </template>
<script lang="ts"> <script lang="ts">
import { Vue, Options } from "vue-class-component"; import { Vue, Options } from "vue-class-component";
import { Rectangle } from "../rects/rectangles"; import { Door } from "./calendar";
import RectangleCanvas from "./RectangleCanvas.vue"; import RectangleCanvas from "./RectangleCanvas.vue";
@Options({ @Options({
@ -24,23 +24,19 @@ import RectangleCanvas from "./RectangleCanvas.vue";
RectangleCanvas, RectangleCanvas,
}, },
props: { props: {
rectangles: Array, doors: Array,
}, },
emits: ["update:rectangles"], emits: ["update:doors"],
}) })
export default class extends Vue { export default class extends Vue {
private rectangles!: Rectangle[]; private doors!: Door[];
declare $refs: { private get rectangles() {
rect_pad: RectangleCanvas; return this.doors.filter((door) => door.position);
};
public mounted() {
this.$refs.rect_pad.rectangles = this.rectangles;
} }
public beforeUnmount() { public beforeUnmount() {
this.$emit("update:rectangles", this.rectangles); this.$emit("update:doors", this.doors);
} }
} }
</script> </script>

View file

@ -34,6 +34,10 @@ enum CanvasState {
ThouCanvas, ThouCanvas,
SVGRect, SVGRect,
}, },
props: {
rectangles: Array,
},
emits: ["add_rect", "edit_rect", "remove_rect"],
}) })
export default class extends Vue { export default class extends Vue {
private readonly min_rect_area = 300; private readonly min_rect_area = 300;
@ -41,7 +45,7 @@ export default class extends Vue {
private preview_rect = new Rectangle(); private preview_rect = new Rectangle();
private drag_rect?: Rectangle; private drag_rect?: Rectangle;
private drag_origin = new Vector2D(); private drag_origin = new Vector2D();
public rectangles: Rectangle[] = []; private rectangles: Rectangle[] = [];
private get preview_visible(): boolean { private get preview_visible(): boolean {
return this.state !== CanvasState.Idle; return this.state !== CanvasState.Idle;
@ -78,6 +82,7 @@ export default class extends Vue {
} }
this.rectangles.push(this.preview_rect); this.rectangles.push(this.preview_rect);
this.$emit("add_rect", this.preview_rect);
} }
private drag_start(event: MouseEvent, point: Vector2D) { private drag_start(event: MouseEvent, point: Vector2D) {
@ -107,6 +112,7 @@ export default class extends Vue {
this.state = CanvasState.Idle; this.state = CanvasState.Idle;
this.rectangles.push(this.preview_rect); this.rectangles.push(this.preview_rect);
this.$emit("edit_rect", this.drag_rect, this.preview_rect);
} }
private on_mousemove(event: MouseEvent, point: Vector2D) { private on_mousemove(event: MouseEvent, point: Vector2D) {

View file

@ -0,0 +1,11 @@
import { Rectangle } from "../rects/rectangles";
export class Door {
public day: number;
public readonly position: Rectangle;
constructor(day: number, position: Rectangle) {
this.day = day;
this.position = position;
}
}