From a6e6d8eb1910f4e09cdb77682d7b30e0de53e6cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn-Michael=20Miehe?= Date: Thu, 7 Sep 2023 03:30:21 +0000 Subject: [PATCH] (de-)serializing of "Door" class --- ui/src/components/DoorMapEditor.vue | 22 ++++++++++++++++++++-- ui/src/lib/door.ts | 29 +++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+), 2 deletions(-) diff --git a/ui/src/components/DoorMapEditor.vue b/ui/src/components/DoorMapEditor.vue index 3b608e7..7891951 100644 --- a/ui/src/components/DoorMapEditor.vue +++ b/ui/src/components/DoorMapEditor.vue @@ -6,12 +6,15 @@ - + diff --git a/ui/src/lib/door.ts b/ui/src/lib/door.ts index 17b244e..aff4492 100644 --- a/ui/src/lib/door.ts +++ b/ui/src/lib/door.ts @@ -1,4 +1,13 @@ import { Rectangle } from "./rectangle"; +import { Vector2D } from "./vector2d"; + +export interface DoorSerialized { + day: number; + x1: number; + y1: number; + x2: number; + y2: number; +} export class Door { private _day = -1; @@ -25,4 +34,24 @@ export class Door { this._day = Math.max(Math.floor(result), -1); } } + + public static deserialize(serialized: DoorSerialized): Door { + return new Door( + new Rectangle( + new Vector2D(serialized.x1, serialized.y1), + new Vector2D(serialized.x2, serialized.y2), + ), + serialized.day, + ); + } + + public get serialized(): DoorSerialized { + return { + day: this.day, + x1: this.position.origin.x, + y1: this.position.origin.y, + x2: this.position.corner.x, + y2: this.position.corner.y, + }; + } }