From 67f49722922fb49885c56879cda3e27f73b07e36 Mon Sep 17 00:00:00 2001 From: Piotr 'pwh' Hanusiak Date: Mon, 11 Apr 2022 13:12:19 +0200 Subject: [PATCH] little cleanup --- front/src/Phaser/Game/GameMap.ts | 42 ++++------ front/src/Phaser/Game/GameMapProperties.ts | 2 + .../Phaser/Game/GameMapPropertiesListener.ts | 2 - front/src/Phaser/Game/GameScene.ts | 9 ++- maps/starter/map.json | 80 ++++++++++++++----- 5 files changed, 83 insertions(+), 52 deletions(-) diff --git a/front/src/Phaser/Game/GameMap.ts b/front/src/Phaser/Game/GameMap.ts index 9f782aef..ce6e2711 100644 --- a/front/src/Phaser/Game/GameMap.ts +++ b/front/src/Phaser/Game/GameMap.ts @@ -77,7 +77,6 @@ export class GameMap { this.flatLayers = flattenGroupLayersMap(map); this.tiledObjects = this.getObjectsFromLayers(this.flatLayers); this.zones = this.tiledObjects.filter((object) => object.width > 0); - console.log(this.zones); let depth = -2; for (const layer of this.flatLayers) { @@ -424,23 +423,8 @@ export class GameMap { * We use Tiled Objects with type "zone" as zones with defined x, y, width and height for easier event triggering. */ private triggerZonesChange(): void { - const zonesByOldPosition = this.oldPosition - ? this.zones.filter((zone) => { - if (!this.oldPosition) { - return false; - } - return MathUtils.isOverlappingWithRectangle(this.oldPosition, zone); - }) - : []; - - const zonesByNewPosition = this.position - ? this.zones.filter((zone) => { - if (!this.position) { - return false; - } - return MathUtils.isOverlappingWithRectangle(this.position, zone); - }) - : []; + const zonesByOldPosition = this.getZonesOnPosition(this.oldPosition); + const zonesByNewPosition = this.getZonesOnPosition(this.position); const enterZones = new Set(zonesByNewPosition); const leaveZones = new Set(zonesByOldPosition); @@ -470,16 +454,7 @@ export class GameMap { private getProperties(key: number): Map { const properties = new Map(); - const zonesByNewPosition = this.position - ? this.zones.filter((zone) => { - if (!this.position) { - return false; - } - return MathUtils.isOverlappingWithRectangle(this.position, zone); - }) - : []; - - for (const zone of zonesByNewPosition) { + for (const zone of this.getZonesOnPosition(this.position)) { if (zone.properties !== undefined) { for (const property of zone.properties) { if (property.value === undefined) { @@ -528,6 +503,17 @@ export class GameMap { return properties; } + private getZonesOnPosition(position?: { x: number; y: number }): ITiledMapObject[] { + return position + ? this.zones.filter((zone) => { + if (!position) { + return false; + } + return MathUtils.isOverlappingWithRectangle(position, zone); + }) + : []; + } + private getTileProperty(index: number): Array { if (this.tileSetPropertyMap[index]) { return this.tileSetPropertyMap[index]; diff --git a/front/src/Phaser/Game/GameMapProperties.ts b/front/src/Phaser/Game/GameMapProperties.ts index b77bd02b..1c2a78b6 100644 --- a/front/src/Phaser/Game/GameMapProperties.ts +++ b/front/src/Phaser/Game/GameMapProperties.ts @@ -7,6 +7,7 @@ export enum GameMapProperties { EXIT_URL = "exitUrl", EXIT_SCENE_URL = "exitSceneUrl", FONT_FAMILY = "font-family", + FOCUSABLE = "focusable", JITSI_ADMIN_ROOM_TAG = "jitsiRoomAdminTag", JITSI_CONFIG = "jitsiConfig", JITSI_INTERFACE_CONFIG = "jitsiInterfaceConfig", @@ -35,4 +36,5 @@ export enum GameMapProperties { URL = "url", WRITABLE_BY = "writableBy", ZONE = "zone", + ZOOM_MARGIN = "zoom_margin", } diff --git a/front/src/Phaser/Game/GameMapPropertiesListener.ts b/front/src/Phaser/Game/GameMapPropertiesListener.ts index ae1699c4..103cc4bc 100644 --- a/front/src/Phaser/Game/GameMapPropertiesListener.ts +++ b/front/src/Phaser/Game/GameMapPropertiesListener.ts @@ -66,8 +66,6 @@ export class GameMapPropertiesListener { } }); } else { - console.log("START JITSI"); - console.log(newValue, oldValue, allProps); const openJitsiRoomFunction = () => { const roomName = jitsiFactory.getRoomName(newValue.toString(), this.scene.instance); const jitsiUrl = allProps.get(GameMapProperties.JITSI_URL) as string | undefined; diff --git a/front/src/Phaser/Game/GameScene.ts b/front/src/Phaser/Game/GameScene.ts index 21bd036b..210cfba1 100644 --- a/front/src/Phaser/Game/GameScene.ts +++ b/front/src/Phaser/Game/GameScene.ts @@ -893,11 +893,14 @@ export class GameScene extends DirtyScene { }); this.gameMap.onEnterZone((zones) => { - console.log("ZONE ENTERED"); for (const zone of zones) { - const focusable = zone.properties?.find((property) => property.name === "focusable"); + const focusable = zone.properties?.find( + (property) => property.name === GameMapProperties.FOCUSABLE + ); if (focusable && focusable.value === true) { - const zoomMargin = zone.properties?.find((property) => property.name === "zoom_margin"); + const zoomMargin = zone.properties?.find( + (property) => property.name === GameMapProperties.ZOOM_MARGIN + ); this.cameraManager.enterFocusMode( { x: zone.x + zone.width * 0.5, diff --git a/maps/starter/map.json b/maps/starter/map.json index beee3669..b6ea80b9 100644 --- a/maps/starter/map.json +++ b/maps/starter/map.json @@ -26,24 +26,6 @@ "x":0, "y":0 }, - { - "data":[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 454, 454, 454, 454, 454, 454, 454, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 454, 454, 454, 454, 454, 454, 454, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 454, 454, 454, 454, 454, 454, 454, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 454, 454, 454, 454, 454, 454, 454, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 454, 454, 454, 454, 454, 454, 454, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 454, 454, 454, 454, 454, 454, 454, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 454, 454, 454, 454, 454, 454, 454, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 454, 454, 454, 454, 454, 454, 454, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 454, 454, 454, 454, 454, 454, 454, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 454, 454, 454, 454, 454, 454, 454, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 454, 454, 454, 454, 454, 454, 454, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], - "height":17, - "id":29, - "name":"jitsiMeetingRoom", - "opacity":1, - "properties":[ - { - "name":"jitsiRoom", - "type":"string", - "value":"MeetingRoom" - }], - "type":"tilelay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 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], "height":17, @@ -147,6 +129,66 @@ "width":76.5390990955655, "x":59.0274706237854, "y":91.8390566468795 + }, + { + "height":179.413785031117, + "id":10, + "name":"focusableChillZone", + "properties":[ + { + "name":"focusOn", + "type":"bool", + "value":true + }, + { + "name":"focusable", + "type":"bool", + "value":true + }, + { + "name":"jitsiRoom", + "type":"string", + "value":"MeetingRoom" + }, + { + "name":"jitsiTrigger", + "type":"string", + "value":"onaction" + }], + "rotation":0.513254, + "type":"", + "visible":true, + "width":283.802849832786, + "x":316.73045, + "y":255.367599999999 + }, + { + "height":119, + "id":11, + "name":"", + "properties":[ + { + "name":"silent", + "type":"bool", + "value":true + }], + "rotation":0, + "type":"", + "visible":true, + "width":214, + "x":745, + "y":329 + }, + { + "height":0, + "id":13, + "name":"", + "rotation":0, + "type":"", + "visible":true, + "width":0, + "x":358, + "y":629 }], "opacity":1, "type":"objectgroup", @@ -191,7 +233,7 @@ "y":0 }], "nextlayerid":39, - "nextobjectid":10, + "nextobjectid":14, "orientation":"orthogonal", "properties":[ {