Skip to content

Commit 682dccd

Browse files
committed
Fixed 2 bugs with the camera module
First was that starting state of the camera toggle was ignored depending on the order in which the modules were loaded. Second was that when resizing the player, the camera would zoom way to much
1 parent e87ae56 commit 682dccd

File tree

2 files changed

+14
-17
lines changed

2 files changed

+14
-17
lines changed

engine/community-modules/camera/src/main/resources/view/camera-module/CameraModule.js

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import {easeOut} from '../core/transitions.js'
44
import {lerpPosition} from '../core/utils.js'
55

66
export class CameraModule {
7-
constructor(assets) {
7+
constructor(_assets) {
88
CameraModule.instance = this
99
this.container = {id: -1, sizeX: -1, sizeY: -1}
1010
this.cameraOffset = 0
@@ -19,7 +19,6 @@ export class CameraModule {
1919
this.oldCameraState = {scale: {x: -1, y: -1}, position: {x: 0, y: 0}}
2020
this.currentCameraState = {scale: {x: -1, y: -1}, position: {x: 0, y: 0}}
2121
this.previousUpdateData = this.currentUpdateFrame = this.currentUpdateProgress = undefined
22-
this.viewerActive = true
2322
this.active = true
2423

2524
}
@@ -28,11 +27,12 @@ export class CameraModule {
2827
return 'c'
2928
}
3029

31-
setActive(active) {
32-
this.viewerActive = active
33-
this.lastFrame = -2
34-
if (this.previousUpdateData !== undefined) {
35-
this.updateScene(this.previousUpdateData, this.currentUpdateFrame, this.currentUpdateProgress || 1)
30+
static setActive(active) {
31+
CameraModule.viewerActive = active
32+
const module = CameraModule.instance
33+
module.lastFrame = -2
34+
if (module.previousUpdateData !== undefined) {
35+
module.updateScene(module.previousUpdateData, module.currentUpdateFrame, module.currentUpdateProgress || 1)
3636
}
3737
}
3838

@@ -59,7 +59,7 @@ export class CameraModule {
5959
this.currentUpdateProgress = progress
6060
this.previousUpdateData = previousData
6161
const isActive = (currentData.registered.size !== 0) && (currentData.container.entity !== null)
62-
if (!(currentData.active && this.viewerActive)) {
62+
if (!(currentData.active && CameraModule.viewerActive)) {
6363
if (isActive) {
6464
currentData.container.entity.graphics.scale = {x: 1, y: 1}
6565
currentData.container.entity.graphics.position = {x: 0, y: 0}
@@ -170,11 +170,8 @@ export class CameraModule {
170170
}
171171

172172
reinitScene() {
173-
if (this.currentUpdateProgress !== undefined) {
174-
this.lastFrame = -2
175-
this.updateScene(this.previousUpdateData, this.currentUpdateFrame, 1)
176-
}
177-
178173
}
179174

180175
}
176+
177+
CameraModule.viewerActive = true

engine/community-modules/camera/src/main/resources/view/camera-module/CameraToggleModule.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,16 @@ import { DuplicateToggleValueError } from "./errors/DuplicateToggleValueError.js
44

55
export class CameraToggleModule {
66

7-
constructor(assets) {
7+
constructor(_assets) {
88
this.previousFrame = {}
99
this.missingToggles = {}
1010
this.d = false
1111
CameraToggleModule.refreshContent = () => {
1212
this.d = !this.d
1313
if (CameraToggleModule.toggles.cameraMode) {
14-
CameraModule.instance.setActive(true)
14+
CameraModule.setActive(true)
1515
} else {
16-
CameraModule.instance.setActive(false)
16+
CameraModule.setActive(false)
1717
}
1818
}
1919
pushDuplicateErrors()
@@ -51,7 +51,7 @@ export class CameraToggleModule {
5151
handleFrameData(frameInfo, data) {
5252
}
5353

54-
reinitScene(container, canvasData) {
54+
reinitScene(_container, _canvasData) {
5555
CameraToggleModule.refreshContent()
5656
}
5757
}

0 commit comments

Comments
 (0)