From a164cedf3f05d5ee2865b2c1c352e8dcaa41c699 Mon Sep 17 00:00:00 2001 From: Hanusiak Piotr Date: Thu, 13 Jan 2022 16:43:58 +0100 Subject: [PATCH] Camera FocusTarget width and height are now optional --- .../src/Api/Events/CameraSetViewportEvent.ts | 4 +-- front/src/Api/IframeListener.ts | 1 + front/src/Api/iframe/camera.ts | 5 ++-- front/src/Phaser/Game/CameraManager.ts | 30 +++++++++---------- front/src/Phaser/Services/WaScaleManager.ts | 12 +++++--- maps/tests/CameraApi/script.php | 4 +-- 6 files changed, 31 insertions(+), 25 deletions(-) diff --git a/front/src/Api/Events/CameraSetViewportEvent.ts b/front/src/Api/Events/CameraSetViewportEvent.ts index 70a6d62c..b1d1df0e 100644 --- a/front/src/Api/Events/CameraSetViewportEvent.ts +++ b/front/src/Api/Events/CameraSetViewportEvent.ts @@ -4,8 +4,8 @@ export const isCameraSetViewportEvent = new tg.IsInterface() .withProperties({ x: tg.isNumber, y: tg.isNumber, - width: tg.isNumber, - height: tg.isNumber, + width: tg.isOptional(tg.isNumber), + height: tg.isOptional(tg.isNumber), lock: tg.isBoolean, smooth: tg.isBoolean, }) diff --git a/front/src/Api/IframeListener.ts b/front/src/Api/IframeListener.ts index 49d8b37b..b1484920 100644 --- a/front/src/Api/IframeListener.ts +++ b/front/src/Api/IframeListener.ts @@ -211,6 +211,7 @@ class IframeListener { } else if (payload.type === "setProperty" && isSetPropertyEvent(payload.data)) { this._setPropertyStream.next(payload.data); } else if (payload.type === "cameraSetViewport" && isCameraSetViewportEvent(payload.data)) { + console.log(payload.data); this._cameraSetViewportStream.next(payload.data); } else if (payload.type === "cameraFollowPlayer" && isCameraFollowPlayerEvent(payload.data)) { this._cameraFollowPlayerStream.next(payload.data); diff --git a/front/src/Api/iframe/camera.ts b/front/src/Api/iframe/camera.ts index 9dc9e0bb..60fd79a3 100644 --- a/front/src/Api/iframe/camera.ts +++ b/front/src/Api/iframe/camera.ts @@ -20,11 +20,12 @@ export class WorkAdventureCameraCommands extends IframeApiContribution { if (!focusOn) { return; diff --git a/front/src/Phaser/Services/WaScaleManager.ts b/front/src/Phaser/Services/WaScaleManager.ts index 0cf189b1..f17e5326 100644 --- a/front/src/Phaser/Services/WaScaleManager.ts +++ b/front/src/Phaser/Services/WaScaleManager.ts @@ -9,6 +9,8 @@ export enum WaScaleManagerEvent { RefreshFocusOnTarget = "wa-scale-manager:refresh-focus-on-target", } +export type WaScaleManagerFocusTarget = { x: number; y: number; width?: number; height?: number }; + export class WaScaleManager { private hdpiManager: HdpiManager; private scaleManager!: ScaleManager; @@ -16,7 +18,7 @@ export class WaScaleManager { private actualZoom: number = 1; private _saveZoom: number = 1; - private focusTarget?: { x: number; y: number; width: number; height: number }; + private focusTarget?: WaScaleManagerFocusTarget; public constructor(private minGamePixelsNumber: number, private absoluteMinPixelNumber: number) { this.hdpiManager = new HdpiManager(minGamePixelsNumber, absoluteMinPixelNumber); @@ -72,11 +74,13 @@ export class WaScaleManager { if (!this.focusTarget) { return; } - this.zoomModifier = this.getTargetZoomModifierFor(this.focusTarget.width, this.focusTarget.height); + if (this.focusTarget.width && this.focusTarget.height) { + this.zoomModifier = this.getTargetZoomModifierFor(this.focusTarget.width, this.focusTarget.height); + } this.game.events.emit(WaScaleManagerEvent.RefreshFocusOnTarget, this.focusTarget); } - public setFocusTarget(targetDimensions?: { x: number; y: number; width: number; height: number }): void { + public setFocusTarget(targetDimensions?: WaScaleManagerFocusTarget): void { this.focusTarget = targetDimensions; } @@ -109,7 +113,7 @@ export class WaScaleManager { } } - public getFocusTarget(): { x: number; y: number; width: number; height: number } | undefined { + public getFocusTarget(): WaScaleManagerFocusTarget | undefined { return this.focusTarget; } diff --git a/maps/tests/CameraApi/script.php b/maps/tests/CameraApi/script.php index 94146a0c..992ad4b7 100644 --- a/maps/tests/CameraApi/script.php +++ b/maps/tests/CameraApi/script.php @@ -21,8 +21,8 @@ WA.camera.setViewport( parseInt(xField.value), parseInt(yField.value), - parseInt(widthField.value), - parseInt(heightField.value), + widthField.value ? parseInt(widthField.value) : undefined, + heightField.value ? parseInt(heightField.value) : undefined, lockField.checked, smoothField.checked, );