added zoom_margin optional property for zone definition
This commit is contained in:
parent
082b33cf02
commit
03cf5c05ff
@ -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,
|
||||
|
@ -791,13 +791,13 @@ 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);
|
||||
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) => {
|
||||
// iframeListener.sendEnterLayerEvent(zone.name);
|
||||
// });
|
||||
@ -805,13 +805,12 @@ 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) {
|
||||
const focusable = zone.properties?.find((property) => property.name === "focusable");
|
||||
if (focusable && focusable.value === true) {
|
||||
this.cameraManager.leaveFocusMode(this.CurrentPlayer);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
// zones.forEach((zone) => {
|
||||
// iframeListener.sendEnterLayerEvent(zone.name);
|
||||
// });
|
||||
|
@ -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",
|
||||
|
Loading…
Reference in New Issue
Block a user