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( public enterFocusMode(
focusOn: { x: number; y: number; width: number; height: number }, focusOn: { x: number; y: number; width: number; height: number },
margin: number = 0,
duration: number = 1000 duration: number = 1000
): void { ): void {
this.setCameraMode(CameraMode.Focus); this.setCameraMode(CameraMode.Focus);
@ -57,14 +58,18 @@ export class CameraManager extends Phaser.Events.EventEmitter {
this.restoreZoomTween?.stop(); this.restoreZoomTween?.stop();
this.startFollowTween?.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 currentZoomModifier = this.waScaleManager.zoomModifier;
const zoomModifierChange = targetZoomModifier - currentZoomModifier; const zoomModifierChange = targetZoomModifier - currentZoomModifier;
this.camera.stopFollow(); this.camera.stopFollow();
this.cameraFollowTarget = undefined; this.cameraFollowTarget = undefined;
this.camera.pan( this.camera.pan(
focusOn.x + focusOn.width * 0.5, focusOn.x + focusOn.width * 0.5 * marginMult,
focusOn.y + focusOn.height * 0.5, focusOn.y + focusOn.height * 0.5 * marginMult,
duration, duration,
Easing.SineEaseOut, Easing.SineEaseOut,
true, true,

View file

@ -791,11 +791,11 @@ export class GameScene extends DirtyScene {
// P.H. TODO: Send those events to the iframe? // P.H. TODO: Send those events to the iframe?
this.gameMap.onEnterZone((zones) => { this.gameMap.onEnterZone((zones) => {
for (const zone of zones) { for (const zone of zones) {
for (const property of zone.properties ?? []) { const focusable = zone.properties?.find((property) => property.name === "focusable");
if (property.name === "focusable" && property.value === true) { if (focusable && focusable.value === true) {
this.cameraManager.enterFocusMode(zone); const zoomMargin = zone.properties?.find((property) => property.name === "zoom_margin");
break; this.cameraManager.enterFocusMode(zone, Number(zoomMargin?.value));
} break;
} }
} }
// zones.forEach((zone) => { // zones.forEach((zone) => {
@ -805,11 +805,10 @@ export class GameScene extends DirtyScene {
this.gameMap.onLeaveZone((zones) => { this.gameMap.onLeaveZone((zones) => {
for (const zone of zones) { for (const zone of zones) {
for (const property of zone.properties ?? []) { const focusable = zone.properties?.find((property) => property.name === "focusable");
if (property.name === "focusable" && property.value === true) { if (focusable && focusable.value === true) {
this.cameraManager.leaveFocusMode(this.CurrentPlayer); this.cameraManager.leaveFocusMode(this.CurrentPlayer);
break; break;
}
} }
} }
// zones.forEach((zone) => { // zones.forEach((zone) => {

View file

@ -163,6 +163,11 @@
"name":"focusable", "name":"focusable",
"type":"bool", "type":"bool",
"value":true "value":true
},
{
"name":"zoom_margin",
"type":"float",
"value":0.5
}], }],
"rotation":0, "rotation":0,
"type":"zone", "type":"zone",
@ -185,6 +190,11 @@
"name":"focusable", "name":"focusable",
"type":"bool", "type":"bool",
"value":true "value":true
},
{
"name":"zoom_margin",
"type":"float",
"value":0
}], }],
"rotation":0, "rotation":0,
"type":"zone", "type":"zone",