ran prettier

This commit is contained in:
Hanusiak Piotr 2021-12-03 10:11:16 +01:00
parent a1a83775d6
commit 4bc21a95c5
5 changed files with 71 additions and 58 deletions

View file

@ -1,28 +1,27 @@
import { Easing } from '../../types'; import { Easing } from "../../types";
import { HtmlUtils } from '../../WebRtc/HtmlUtils'; import { HtmlUtils } from "../../WebRtc/HtmlUtils";
import type { Box } from '../../WebRtc/LayoutManager'; import type { Box } from "../../WebRtc/LayoutManager";
import type { Player } from '../Player/Player'; import type { Player } from "../Player/Player";
import type { WaScaleManager } from '../Services/WaScaleManager'; import type { WaScaleManager } from "../Services/WaScaleManager";
import type { GameScene } from './GameScene'; import type { GameScene } from "./GameScene";
export enum CameraMode { export enum CameraMode {
Free = 'Free', Free = "Free",
Follow = 'Follow', Follow = "Follow",
Focus = 'Focus', Focus = "Focus",
} }
export class CameraManager extends Phaser.Events.EventEmitter { export class CameraManager extends Phaser.Events.EventEmitter {
private scene: GameScene; private scene: GameScene;
private camera: Phaser.Cameras.Scene2D.Camera; private camera: Phaser.Cameras.Scene2D.Camera;
private cameraBounds: { x: number, y: number }; private cameraBounds: { x: number; y: number };
private waScaleManager: WaScaleManager; private waScaleManager: WaScaleManager;
private cameraMode: CameraMode = CameraMode.Free; private cameraMode: CameraMode = CameraMode.Free;
private restoreZoomTween?: Phaser.Tweens.Tween; private restoreZoomTween?: Phaser.Tweens.Tween;
constructor(scene: GameScene, cameraBounds: { x: number, y: number }, waScaleManager: WaScaleManager) { constructor(scene: GameScene, cameraBounds: { x: number; y: number }, waScaleManager: WaScaleManager) {
super(); super();
this.scene = scene; this.scene = scene;
@ -39,7 +38,8 @@ export class CameraManager extends Phaser.Events.EventEmitter {
} }
public enterFocusMode( public enterFocusMode(
focusOn: { x: number, y: number, width: number, height: number }, duration: number = 1000, focusOn: { x: number; y: number; width: number; height: number },
duration: number = 1000
): void { ): void {
this.setCameraMode(CameraMode.Focus); this.setCameraMode(CameraMode.Focus);
this.waScaleManager.saveZoom(); this.waScaleManager.saveZoom();
@ -53,9 +53,12 @@ export class CameraManager extends Phaser.Events.EventEmitter {
focusOn.x + focusOn.width * 0.5, focusOn.x + focusOn.width * 0.5,
focusOn.y + focusOn.height * 0.5, focusOn.y + focusOn.height * 0.5,
duration, duration,
Easing.SineEaseOut, false, (camera, progress, x, y) => { Easing.SineEaseOut,
false,
(camera, progress, x, y) => {
this.waScaleManager.zoomModifier = currentZoomModifier + progress * zoomModifierChange; this.waScaleManager.zoomModifier = currentZoomModifier + progress * zoomModifierChange;
}); }
);
} }
public leaveFocusMode(player: Player): void { public leaveFocusMode(player: Player): void {
@ -107,7 +110,7 @@ export class CameraManager extends Phaser.Events.EventEmitter {
ease: Easing.SineEaseOut, ease: Easing.SineEaseOut,
onUpdate: (tween: Phaser.Tweens.Tween) => { onUpdate: (tween: Phaser.Tweens.Tween) => {
this.waScaleManager.zoomModifier = tween.getValue(); this.waScaleManager.zoomModifier = tween.getValue();
} },
}); });
} }

View file

@ -1,9 +1,15 @@
import type { ITiledMap, ITiledMapLayer, ITiledMapObject, ITiledMapObjectLayer, ITiledMapProperty } from "../Map/ITiledMap"; import type {
ITiledMap,
ITiledMapLayer,
ITiledMapObject,
ITiledMapObjectLayer,
ITiledMapProperty,
} from "../Map/ITiledMap";
import { flattenGroupLayersMap } from "../Map/LayersFlattener"; import { flattenGroupLayersMap } from "../Map/LayersFlattener";
import TilemapLayer = Phaser.Tilemaps.TilemapLayer; import TilemapLayer = Phaser.Tilemaps.TilemapLayer;
import { DEPTH_OVERLAY_INDEX } from "./DepthIndexes"; import { DEPTH_OVERLAY_INDEX } from "./DepthIndexes";
import { GameMapProperties } from "./GameMapProperties"; import { GameMapProperties } from "./GameMapProperties";
import { MathUtils } from '../../Utils/MathUtils'; import { MathUtils } from "../../Utils/MathUtils";
export type PropertyChangeCallback = ( export type PropertyChangeCallback = (
newValue: string | number | boolean | undefined, newValue: string | number | boolean | undefined,
@ -37,11 +43,11 @@ export class GameMap {
/** /**
* oldPosition is the previous position of the player. * oldPosition is the previous position of the player.
*/ */
private oldPosition: { x: number, y: number } | undefined; private oldPosition: { x: number; y: number } | undefined;
/** /**
* position is the current position of the player. * position is the current position of the player.
*/ */
private position: { x: number, y: number } | undefined; private position: { x: number; y: number } | undefined;
private lastProperties = new Map<string, string | boolean | number>(); private lastProperties = new Map<string, string | boolean | number>();
private propertiesChangeCallbacks = new Map<string, Array<PropertyChangeCallback>>(); private propertiesChangeCallbacks = new Map<string, Array<PropertyChangeCallback>>();
@ -189,25 +195,27 @@ export class GameMap {
* We user Tiled Objects with type "zone" as zones with defined x, y, width and height for easier event triggering. * We user Tiled Objects with type "zone" as zones with defined x, y, width and height for easier event triggering.
*/ */
private triggerZonesChange(): void { private triggerZonesChange(): void {
const zones = this.tiledObjects.filter(object => object.type === "zone"); const zones = this.tiledObjects.filter((object) => object.type === "zone");
// P.H. NOTE: We could also get all of the zones and add properties of occupied tiles to them, so we could later on check collision by using tileKeys // P.H. NOTE: We could also get all of the zones and add properties of occupied tiles to them, so we could later on check collision by using tileKeys
// TODO: Change this to an array with currently occupied sone instead of doing elimination process // TODO: Change this to an array with currently occupied sone instead of doing elimination process
const zonesByOldPosition = this.oldPosition ? const zonesByOldPosition = this.oldPosition
zones.filter((zone) => { ? zones.filter((zone) => {
if (!this.oldPosition) { if (!this.oldPosition) {
return false; return false;
} }
return MathUtils.isOverlappingWithRectangle(this.oldPosition, zone); return MathUtils.isOverlappingWithRectangle(this.oldPosition, zone);
}) : []; })
: [];
const zonesByNewPosition = this.position ? const zonesByNewPosition = this.position
zones.filter((zone) => { ? zones.filter((zone) => {
if (!this.position) { if (!this.position) {
return false; return false;
} }
return MathUtils.isOverlappingWithRectangle(this.position, zone); return MathUtils.isOverlappingWithRectangle(this.position, zone);
}) : []; })
: [];
const enterZones = new Set(zonesByNewPosition); const enterZones = new Set(zonesByNewPosition);
const leaveZones = new Set(zonesByOldPosition); const leaveZones = new Set(zonesByOldPosition);
@ -459,7 +467,7 @@ export class GameMap {
private getObjectsFromLayers(layers: ITiledMapLayer[]): ITiledMapObject[] { private getObjectsFromLayers(layers: ITiledMapLayer[]): ITiledMapObject[] {
const objects: ITiledMapObject[] = []; const objects: ITiledMapObject[] = [];
const objectLayers = layers.filter(layer => layer.type === "objectgroup"); const objectLayers = layers.filter((layer) => layer.type === "objectgroup");
for (const objectLayer of objectLayers) { for (const objectLayer of objectLayers) {
if (this.isOfTypeITiledMapObjectLayer(objectLayer)) { if (this.isOfTypeITiledMapObjectLayer(objectLayer)) {
objects.push(...objectLayer.objects); objects.push(...objectLayer.objects);

View file

@ -60,7 +60,7 @@ import { PinchManager } from "../UserInput/PinchManager";
import { joystickBaseImg, joystickBaseKey, joystickThumbImg, joystickThumbKey } from "../Components/MobileJoystick"; import { joystickBaseImg, joystickBaseKey, joystickThumbImg, joystickThumbKey } from "../Components/MobileJoystick";
import { waScaleManager } from "../Services/WaScaleManager"; import { waScaleManager } from "../Services/WaScaleManager";
import { EmoteManager } from "./EmoteManager"; import { EmoteManager } from "./EmoteManager";
import { CameraManager } from './CameraManager'; import { CameraManager } from "./CameraManager";
import EVENT_TYPE = Phaser.Scenes.Events; import EVENT_TYPE = Phaser.Scenes.Events;
import type { HasPlayerMovedEvent } from "../../Api/Events/HasPlayerMovedEvent"; import type { HasPlayerMovedEvent } from "../../Api/Events/HasPlayerMovedEvent";
@ -551,7 +551,11 @@ export class GameScene extends DirtyScene {
this.createCurrentPlayer(); this.createCurrentPlayer();
this.removeAllRemotePlayers(); //cleanup the list of remote players in case the scene was rebooted this.removeAllRemotePlayers(); //cleanup the list of remote players in case the scene was rebooted
this.cameraManager = new CameraManager(this, { x: this.Map.widthInPixels, y: this.Map.heightInPixels }, waScaleManager); this.cameraManager = new CameraManager(
this,
{ x: this.Map.widthInPixels, y: this.Map.heightInPixels },
waScaleManager
);
biggestAvailableAreaStore.recompute(); biggestAvailableAreaStore.recompute();
this.cameraManager.startFollow(this.CurrentPlayer); this.cameraManager.startFollow(this.CurrentPlayer);
@ -787,7 +791,7 @@ export class GameScene extends DirtyScene {
this.gameMap.onEnterZone((zones) => { this.gameMap.onEnterZone((zones) => {
for (const zone of zones) { for (const zone of zones) {
for (const property of zone.properties ?? []) { for (const property of zone.properties ?? []) {
if (property.name === 'focusable' && property.value === true) { if (property.name === "focusable" && property.value === true) {
this.cameraManager.enterFocusMode(zone); this.cameraManager.enterFocusMode(zone);
break; break;
} }
@ -801,7 +805,7 @@ 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 ?? []) { for (const property of zone.properties ?? []) {
if (property.name === 'focusable' && property.value === true) { if (property.name === "focusable" && property.value === true) {
this.cameraManager.leaveFocusMode(this.CurrentPlayer); this.cameraManager.leaveFocusMode(this.CurrentPlayer);
break; break;
} }

View file

@ -1,6 +1,4 @@
export class MathUtils { export class MathUtils {
/** /**
* *
* @param p Position to check. * @param p Position to check.
@ -8,10 +6,10 @@ export class MathUtils {
* @returns true is overlapping * @returns true is overlapping
*/ */
public static isOverlappingWithRectangle( public static isOverlappingWithRectangle(
p: { x: number, y: number}, p: { x: number; y: number },
r: { x: number, y: number, width: number, height: number}, r: { x: number; y: number; width: number; height: number }
): boolean { ): boolean {
return (this.isBetween(p.x, r.x, r.x + r.width) && this.isBetween(p.y, r.y, r.y + r.height)); return this.isBetween(p.x, r.x, r.x + r.width) && this.isBetween(p.y, r.y, r.y + r.height);
} }
/** /**
@ -22,6 +20,6 @@ export class MathUtils {
* @returns true if value is in <min, max> * @returns true if value is in <min, max>
*/ */
public static isBetween(value: number, min: number, max: number): boolean { public static isBetween(value: number, min: number, max: number): boolean {
return (value >= min) && (value <= max); return value >= min && value <= max;
} }
} }

View file

@ -50,5 +50,5 @@ export enum Easing {
ExpoEaseInOut = "Expo.easeInOut", ExpoEaseInOut = "Expo.easeInOut",
CircEaseInOut = "Circ.easeInOut", CircEaseInOut = "Circ.easeInOut",
BackEaseInOut = "Back.easeInOut", BackEaseInOut = "Back.easeInOut",
BounceEaseInOut = "Bounce.easeInOut" BounceEaseInOut = "Bounce.easeInOut",
} }