camera is now properly focusing on target when zooming, if any

This commit is contained in:
Hanusiak Piotr 2022-01-12 12:58:27 +01:00
parent 58af1f05f7
commit 905bd079ec
3 changed files with 18 additions and 5 deletions

View File

@ -19,7 +19,6 @@ export class CameraManager extends Phaser.Events.EventEmitter {
private cameraMode: CameraMode = CameraMode.Free; private cameraMode: CameraMode = CameraMode.Free;
private cameraLockedDelayedCall: Phaser.Time.TimerEvent | undefined;
private restoreZoomTween?: Phaser.Tweens.Tween; private restoreZoomTween?: Phaser.Tweens.Tween;
private startFollowTween?: Phaser.Tweens.Tween; private startFollowTween?: Phaser.Tweens.Tween;
@ -85,7 +84,6 @@ export class CameraManager extends Phaser.Events.EventEmitter {
} }
public leaveFocusMode(player: Player, duration = 0): void { public leaveFocusMode(player: Player, duration = 0): void {
this.cameraLocked = false;
this.waScaleManager.setFocusTarget(); this.waScaleManager.setFocusTarget();
this.unlockCameraWithDelay(duration); this.unlockCameraWithDelay(duration);
this.startFollow(player, duration); this.startFollow(player, duration);

View File

@ -12,7 +12,7 @@ import { UserInputManager } from "../UserInput/UserInputManager";
import { gameManager } from "./GameManager"; import { gameManager } from "./GameManager";
import { touchScreenManager } from "../../Touch/TouchScreenManager"; import { touchScreenManager } from "../../Touch/TouchScreenManager";
import { PinchManager } from "../UserInput/PinchManager"; import { PinchManager } from "../UserInput/PinchManager";
import { waScaleManager } from "../Services/WaScaleManager"; import { waScaleManager, WaScaleManagerEvent } from "../Services/WaScaleManager";
import { EmoteManager } from "./EmoteManager"; import { EmoteManager } from "./EmoteManager";
import { soundManager } from "./SoundManager"; import { soundManager } from "./SoundManager";
import { SharedVariablesManager } from "./SharedVariablesManager"; import { SharedVariablesManager } from "./SharedVariablesManager";
@ -2125,7 +2125,7 @@ ${escapedMessage}
if (this.cameraManager.isCameraLocked()) { if (this.cameraManager.isCameraLocked()) {
return; return;
} }
waScaleManager.zoomModifier *= zoomFactor; waScaleManager.handleZoomByFactor(zoomFactor);
biggestAvailableAreaStore.recompute(); biggestAvailableAreaStore.recompute();
} }

View File

@ -5,6 +5,10 @@ import type { Game } from "../Game/Game";
import { ResizableScene } from "../Login/ResizableScene"; import { ResizableScene } from "../Login/ResizableScene";
import { HtmlUtils } from "../../WebRtc/HtmlUtils"; import { HtmlUtils } from "../../WebRtc/HtmlUtils";
export enum WaScaleManagerEvent {
RefreshFocusOnTarget = "wa-scale-manager:refresh-focus-on-target",
}
export class WaScaleManager { export class WaScaleManager {
private hdpiManager: HdpiManager; private hdpiManager: HdpiManager;
private scaleManager!: ScaleManager; private scaleManager!: ScaleManager;
@ -69,7 +73,7 @@ export class WaScaleManager {
return; return;
} }
this.zoomModifier = this.getTargetZoomModifierFor(this.focusTarget.width, this.focusTarget.height); this.zoomModifier = this.getTargetZoomModifierFor(this.focusTarget.width, this.focusTarget.height);
this.game.events.emit("wa-scale-manager:refresh-focus-on-target", this.focusTarget); this.game.events.emit(WaScaleManagerEvent.RefreshFocusOnTarget, this.focusTarget);
} }
public setFocusTarget(targetDimensions?: { x: number; y: number; width: number; height: number }): void { public setFocusTarget(targetDimensions?: { x: number; y: number; width: number; height: number }): void {
@ -98,6 +102,17 @@ export class WaScaleManager {
this.applyNewSize(); this.applyNewSize();
} }
public handleZoomByFactor(zoomFactor: number): void {
this.zoomModifier *= zoomFactor;
if (this.focusTarget) {
this.game.events.emit(WaScaleManagerEvent.RefreshFocusOnTarget, this.focusTarget);
}
}
public getFocusTarget(): { x: number; y: number; width: number; height: number } | undefined {
return this.focusTarget;
}
public saveZoom(): void { public saveZoom(): void {
this._saveZoom = this.hdpiManager.zoomModifier; this._saveZoom = this.hdpiManager.zoomModifier;
} }