diff --git a/front/src/Phaser/Game/CameraManager.ts b/front/src/Phaser/Game/CameraManager.ts index 04ff208c..19c4821a 100644 --- a/front/src/Phaser/Game/CameraManager.ts +++ b/front/src/Phaser/Game/CameraManager.ts @@ -49,6 +49,7 @@ export class CameraManager extends Phaser.Events.EventEmitter { public enterFocusMode( focusOn: { x: number; y: number; width: number; height: number }, + margin: number = 0, duration: number = 1000 ): void { this.setCameraMode(CameraMode.Focus); @@ -57,14 +58,18 @@ export class CameraManager extends Phaser.Events.EventEmitter { this.restoreZoomTween?.stop(); this.startFollowTween?.stop(); - const targetZoomModifier = this.waScaleManager.getTargetZoomModifierFor(focusOn.width, focusOn.height); + const marginMult = 1 + margin; + const targetZoomModifier = this.waScaleManager.getTargetZoomModifierFor( + focusOn.width * marginMult, + focusOn.height * marginMult + ); const currentZoomModifier = this.waScaleManager.zoomModifier; const zoomModifierChange = targetZoomModifier - currentZoomModifier; this.camera.stopFollow(); this.cameraFollowTarget = undefined; this.camera.pan( - focusOn.x + focusOn.width * 0.5, - focusOn.y + focusOn.height * 0.5, + focusOn.x + focusOn.width * 0.5 * marginMult, + focusOn.y + focusOn.height * 0.5 * marginMult, duration, Easing.SineEaseOut, true, diff --git a/front/src/Phaser/Game/GameScene.ts b/front/src/Phaser/Game/GameScene.ts index aff4acc1..c1e5c1a2 100644 --- a/front/src/Phaser/Game/GameScene.ts +++ b/front/src/Phaser/Game/GameScene.ts @@ -791,11 +791,11 @@ export class GameScene extends DirtyScene { // P.H. TODO: Send those events to the iframe? this.gameMap.onEnterZone((zones) => { for (const zone of zones) { - for (const property of zone.properties ?? []) { - if (property.name === "focusable" && property.value === true) { - this.cameraManager.enterFocusMode(zone); - break; - } + const focusable = zone.properties?.find((property) => property.name === "focusable"); + if (focusable && focusable.value === true) { + const zoomMargin = zone.properties?.find((property) => property.name === "zoom_margin"); + this.cameraManager.enterFocusMode(zone, Number(zoomMargin?.value)); + break; } } // zones.forEach((zone) => { @@ -805,11 +805,10 @@ export class GameScene extends DirtyScene { this.gameMap.onLeaveZone((zones) => { for (const zone of zones) { - for (const property of zone.properties ?? []) { - if (property.name === "focusable" && property.value === true) { - this.cameraManager.leaveFocusMode(this.CurrentPlayer); - break; - } + const focusable = zone.properties?.find((property) => property.name === "focusable"); + if (focusable && focusable.value === true) { + this.cameraManager.leaveFocusMode(this.CurrentPlayer); + break; } } // zones.forEach((zone) => { diff --git a/maps/tests/focusable_zone_map.json b/maps/tests/focusable_zone_map.json index b747d7a0..469b8c6d 100644 --- a/maps/tests/focusable_zone_map.json +++ b/maps/tests/focusable_zone_map.json @@ -163,6 +163,11 @@ "name":"focusable", "type":"bool", "value":true + }, + { + "name":"zoom_margin", + "type":"float", + "value":0.5 }], "rotation":0, "type":"zone", @@ -185,6 +190,11 @@ "name":"focusable", "type":"bool", "value":true + }, + { + "name":"zoom_margin", + "type":"float", + "value":0 }], "rotation":0, "type":"zone",