added zoom_margin optional property for zone definition

This commit is contained in:
Hanusiak Piotr 2021-12-08 13:03:25 +01:00
parent 082b33cf02
commit 03cf5c05ff
3 changed files with 27 additions and 13 deletions

View file

@ -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,

View file

@ -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) => {

View file

@ -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",