cleanup
This commit is contained in:
parent
b00d24dbf7
commit
29ccb52c93
@ -32,13 +32,12 @@ export class CameraManager extends Phaser.Events.EventEmitter {
|
||||
|
||||
this.initCamera();
|
||||
|
||||
this.scene.game.events.on("wa-scale-manager:refresh-focus-on-target", () => {
|
||||
const focusOn = this.waScaleManager.getFocusTarget();
|
||||
if (!focusOn) {
|
||||
return;
|
||||
this.bindEventHandlers();
|
||||
}
|
||||
this.camera.centerOn(focusOn.x + focusOn.width * 0.5, focusOn.y + focusOn.height * 0.5);
|
||||
});
|
||||
|
||||
public destroy(): void {
|
||||
this.scene.game.events.off("wa-scale-manager:refresh-focus-on-target");
|
||||
super.destroy();
|
||||
}
|
||||
|
||||
public getCamera(): Phaser.Cameras.Scene2D.Camera {
|
||||
@ -128,4 +127,16 @@ export class CameraManager extends Phaser.Events.EventEmitter {
|
||||
this.camera = this.scene.cameras.main;
|
||||
this.camera.setBounds(0, 0, this.cameraBounds.x, this.cameraBounds.y);
|
||||
}
|
||||
|
||||
private bindEventHandlers(): void {
|
||||
this.scene.game.events.on(
|
||||
"wa-scale-manager:refresh-focus-on-target",
|
||||
(focusOn: { x: number; y: number; width: number; height: number }) => {
|
||||
if (!focusOn) {
|
||||
return;
|
||||
}
|
||||
this.camera.centerOn(focusOn.x + focusOn.width * 0.5, focusOn.y + focusOn.height * 0.5);
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -1410,6 +1410,7 @@ ${escapedMessage}
|
||||
this.userInputManager.destroy();
|
||||
this.pinchManager?.destroy();
|
||||
this.emoteManager.destroy();
|
||||
this.cameraManager.destroy();
|
||||
this.peerStoreUnsubscribe();
|
||||
this.emoteUnsubscribe();
|
||||
this.emoteMenuUnsubscribe();
|
||||
|
@ -65,17 +65,13 @@ export class WaScaleManager {
|
||||
return;
|
||||
}
|
||||
this.zoomModifier = this.getTargetZoomModifierFor(this.focusTarget.width, this.focusTarget.height);
|
||||
this.game.events.emit("wa-scale-manager:refresh-focus-on-target");
|
||||
this.game.events.emit("wa-scale-manager:refresh-focus-on-target", this.focusTarget);
|
||||
}
|
||||
|
||||
public setFocusTarget(targetDimensions?: { x: number; y: number; width: number; height: number }): void {
|
||||
this.focusTarget = targetDimensions;
|
||||
}
|
||||
|
||||
public getFocusTarget(): { x: number; y: number; width: number; height: number } | undefined {
|
||||
return this.focusTarget;
|
||||
}
|
||||
|
||||
public getTargetZoomModifierFor(viewportWidth: number, viewportHeight: number) {
|
||||
const { width: gameWidth, height: gameHeight } = coWebsiteManager.getGameSize();
|
||||
const devicePixelRatio = window.devicePixelRatio ?? 1;
|
||||
|
Loading…
Reference in New Issue
Block a user