moved focusable property handling away from gamescene

This commit is contained in:
Piotr 'pwh' Hanusiak 2022-04-12 12:47:45 +02:00
parent 54b6c3800e
commit d4f5dc6d35
3 changed files with 354 additions and 195 deletions

View File

@ -29,6 +29,8 @@ interface OpenCoWebsite {
export interface ITiledPlace { export interface ITiledPlace {
name: string; name: string;
properties?: ITiledMapProperty[]; properties?: ITiledMapProperty[];
x?: number;
y?: number;
width?: number; width?: number;
height?: number; height?: number;
} }
@ -207,11 +209,27 @@ export class GameMapPropertiesListener {
} }
private onEnterPlaceHandler(places: ITiledPlace[]): void { private onEnterPlaceHandler(places: ITiledPlace[]): void {
places.forEach((place) => {
this.handleOpenWebsitePropertiesOnEnter(place);
this.handleFocusablePropertiesOnEnter(place);
});
}
private onLeavePlaceHandler(places: ITiledPlace[]): void {
places.forEach((place) => { places.forEach((place) => {
if (!place.properties) { if (!place.properties) {
return; return;
} }
this.handleOpenWebsitePropertiesOnLeave(place);
this.handleFocusablePropertiesOnLeave(place);
});
}
private handleOpenWebsitePropertiesOnEnter(place: ITiledPlace): void {
if (!place.properties) {
return;
}
let openWebsiteProperty: string | undefined; let openWebsiteProperty: string | undefined;
let allowApiProperty: boolean | undefined; let allowApiProperty: boolean | undefined;
let websitePolicyProperty: string | undefined; let websitePolicyProperty: string | undefined;
@ -317,11 +335,31 @@ export class GameMapPropertiesListener {
if (!websiteTriggerProperty) { if (!websiteTriggerProperty) {
openCoWebsiteFunction(); openCoWebsiteFunction();
} }
});
} }
private onLeavePlaceHandler(places: ITiledPlace[]): void { private handleFocusablePropertiesOnEnter(place: ITiledPlace): void {
places.forEach((place) => { if (!place.properties) {
return;
}
if (place.x === undefined || place.y === undefined || !place.height || !place.width) {
return;
}
const focusable = place.properties.find((property) => property.name === GameMapProperties.FOCUSABLE);
if (focusable && focusable.value === true) {
const zoomMargin = place.properties.find((property) => property.name === GameMapProperties.ZOOM_MARGIN);
this.scene.getCameraManager().enterFocusMode(
{
x: place.x + place.width * 0.5,
y: place.y + place.height * 0.5,
width: place.width,
height: place.height,
},
zoomMargin ? Math.max(0, Number(zoomMargin.value)) : undefined
);
}
}
private handleOpenWebsitePropertiesOnLeave(place: ITiledPlace): void {
if (!place.properties) { if (!place.properties) {
return; return;
} }
@ -379,6 +417,15 @@ export class GameMapPropertiesListener {
} }
this.coWebsitesActionTriggerByPlace.delete(place); this.coWebsitesActionTriggerByPlace.delete(place);
}); }
private handleFocusablePropertiesOnLeave(place: ITiledPlace): void {
if (!place.properties) {
return;
}
const focusable = place.properties.find((property) => property.name === GameMapProperties.FOCUSABLE);
if (focusable && focusable.value === true) {
this.scene.getCameraManager().leaveFocusMode(this.scene.CurrentPlayer, 1000);
}
} }
} }

View File

@ -892,43 +892,13 @@ export class GameScene extends DirtyScene {
}); });
}); });
// TODO: Move to GameMapPropertiesListener?
this.gameMap.onEnterArea((areas) => { this.gameMap.onEnterArea((areas) => {
for (const area of areas) {
const focusable = area.properties?.find(
(property) => property.name === GameMapProperties.FOCUSABLE
);
if (focusable && focusable.value === true) {
const zoomMargin = area.properties?.find(
(property) => property.name === GameMapProperties.ZOOM_MARGIN
);
this.cameraManager.enterFocusMode(
{
x: area.x + area.width * 0.5,
y: area.y + area.height * 0.5,
width: area.width,
height: area.height,
},
zoomMargin ? Math.max(0, Number(zoomMargin.value)) : undefined
);
break;
}
}
areas.forEach((area) => { areas.forEach((area) => {
iframeListener.sendEnterAreaEvent(area.name); iframeListener.sendEnterAreaEvent(area.name);
}); });
}); });
this.gameMap.onLeaveArea((areas) => { this.gameMap.onLeaveArea((areas) => {
for (const area of areas) {
const focusable = area.properties?.find(
(property) => property.name === GameMapProperties.FOCUSABLE
);
if (focusable && focusable.value === true) {
this.cameraManager.leaveFocusMode(this.CurrentPlayer, 1000);
break;
}
}
areas.forEach((area) => { areas.forEach((area) => {
iframeListener.sendLeaveAreaEvent(area.name); iframeListener.sendLeaveAreaEvent(area.name);
}); });

View File

@ -27,7 +27,7 @@
"y":0 "y":0
}, },
{ {
"data":[201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 223, 223, 223, 223, 223, 223, 201, 201, 201, 201, 201, 234, 234, 234, 234, 234, 234, 201, 201, 201, 201, 201, 201, 201, 223, 223, 223, 201, 201, 201, 201, 223, 223, 223, 223, 223, 223, 201, 201, 201, 234, 234, 234, 234, 234, 234, 234, 234, 234, 234, 201, 201, 201, 201, 201, 223, 223, 223, 201, 201, 201, 201, 223, 223, 223, 223, 223, 223, 201, 201, 201, 234, 234, 234, 234, 234, 234, 234, 234, 234, 234, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 223, 223, 223, 223, 223, 223, 201, 201, 201, 201, 201, 234, 234, 234, 234, 234, 234, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 234, 234, 234, 234, 234, 234, 234, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 234, 234, 234, 234, 234, 234, 234, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 234, 234, 234, 234, 234, 234, 234, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201], "data":[201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 223, 223, 223, 223, 223, 223, 201, 201, 201, 201, 201, 234, 234, 234, 234, 234, 234, 201, 201, 201, 201, 201, 201, 201, 223, 223, 223, 201, 201, 201, 201, 223, 223, 223, 223, 223, 223, 201, 201, 201, 234, 234, 234, 234, 234, 234, 234, 234, 234, 234, 201, 201, 201, 201, 201, 223, 223, 223, 201, 201, 201, 201, 223, 223, 223, 223, 223, 223, 201, 201, 201, 234, 234, 234, 234, 234, 234, 234, 234, 234, 234, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 223, 223, 223, 223, 223, 223, 201, 201, 201, 201, 201, 234, 234, 234, 234, 234, 234, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 223, 223, 223, 223, 223, 223, 223, 223, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 223, 223, 223, 223, 223, 223, 223, 223, 201, 234, 234, 234, 234, 234, 234, 234, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 223, 223, 223, 223, 223, 223, 223, 223, 201, 234, 234, 234, 234, 234, 234, 234, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 223, 223, 223, 223, 223, 223, 223, 223, 201, 234, 234, 234, 234, 234, 234, 234, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201],
"height":17, "height":17,
"id":4, "id":4,
"name":"floor", "name":"floor",
@ -39,7 +39,7 @@
"y":0 "y":0
}, },
{ {
"data":[49, 58, 58, 58, 58, 58, 58, 42, 58, 58, 58, 58, 58, 58, 58, 58, 58, 58, 58, 58, 58, 58, 42, 57, 57, 57, 57, 57, 57, 57, 50, 45, 63, 63, 63, 63, 63, 63, 45, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 45, 63, 63, 63, 63, 63, 63, 63, 45, 45, 73, 73, 73, 73, 73, 73, 45, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 45, 73, 73, 73, 73, 73, 73, 73, 45, 45, 0, 0, 0, 0, 0, 0, 45, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 45, 0, 0, 0, 0, 0, 0, 0, 45, 45, 0, 0, 0, 0, 0, 0, 56, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 56, 0, 0, 0, 0, 0, 0, 0, 45, 45, 0, 0, 0, 0, 0, 0, 63, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 63, 0, 0, 0, 0, 0, 0, 0, 45, 45, 0, 0, 0, 0, 0, 0, 73, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 73, 0, 0, 0, 0, 0, 0, 0, 45, 45, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 45, 45, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 45, 45, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 45, 45, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 45, 45, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 46, 0, 0, 0, 0, 0, 0, 0, 45, 45, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 45, 0, 0, 0, 0, 0, 0, 0, 45, 45, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 45, 0, 0, 0, 0, 0, 0, 0, 45, 59, 58, 58, 58, 58, 58, 58, 58, 58, 58, 58, 58, 58, 58, 58, 58, 58, 58, 58, 58, 58, 58, 32, 58, 58, 58, 58, 58, 58, 58, 60, 83, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 84, 93, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 94], "data":[49, 58, 58, 58, 58, 58, 58, 42, 58, 58, 58, 58, 58, 58, 58, 58, 58, 58, 58, 58, 58, 58, 42, 57, 57, 57, 57, 57, 57, 57, 50, 45, 63, 63, 63, 63, 63, 63, 45, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 45, 63, 63, 63, 63, 63, 63, 63, 45, 45, 73, 73, 73, 73, 73, 73, 45, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 45, 73, 73, 73, 73, 73, 73, 73, 45, 45, 0, 0, 0, 0, 0, 0, 45, 0,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58, 58, 58, 58, 58, 58, 58, 58, 58, 58, 58, 58, 58, 32, 58, 58, 58, 58, 58, 58, 58, 60, 83, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 84, 93, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 94],
"height":17, "height":17,
"id":9, "id":9,
"name":"walls", "name":"walls",
@ -117,6 +117,11 @@
"id":13, "id":13,
"name":"", "name":"",
"properties":[ "properties":[
{
"name":"focusable",
"type":"bool",
"value":true
},
{ {
"name":"openWebsite", "name":"openWebsite",
"type":"string", "type":"string",
@ -128,6 +133,143 @@
"width":96.736386420597, "width":96.736386420597,
"x":799.205285942128, "x":799.205285942128,
"y":96.736386420597 "y":96.736386420597
},
{
"height":124.762816131237,
"id":15,
"name":"",
"properties":[
{
"name":"focusable",
"type":"bool",
"value":true
},
{
"name":"zoom_margin",
"type":"float",
"value":0.5
}],
"rotation":0,
"type":"area",
"visible":true,
"width":254.95010252905,
"x":448.422875370244,
"y":320.947824105719
},
{
"height":19,
"id":17,
"name":"",
"rotation":0,
"text":
{
"text":"FOCUSABLE ",
"wrap":true
},
"type":"",
"visible":true,
"width":93.848940533151,
"x":529.877534745956,
"y":358.459899749373
},
{
"height":19,
"id":18,
"name":"",
"rotation":0,
"text":
{
"text":"JITSI ON TRIGGER",
"wrap":true
},
"type":"",
"visible":true,
"width":164.367053998633,
"x":408.731032125769,
"y":150.521872863978
},
{
"height":19,
"id":19,
"name":"",
"rotation":0,
"text":
{
"text":"JITSI",
"wrap":true
},
"type":"",
"visible":true,
"width":43.2205513784461,
"x":100.440305308726,
"y":147.80963773069
},
{
"height":102.175210754158,
"id":20,
"name":"",
"rotation":0,
"text":
{
"halign":"center",
"text":"OPEN WEBSITE AND FOCUSABLE",
"wrap":true
},
"type":"",
"visible":true,
"width":99.2734107997265,
"x":796.580656185919,
"y":102.605718842561
},
{
"height":19,
"id":21,
"name":"",
"rotation":0,
"text":
{
"text":"SILENT ZONE",
"wrap":true
},
"type":"",
"visible":true,
"width":112.834586466165,
"x":799.292891319207,
"y":391.910799726589
},
{
"height":95.892082727209,
"id":22,
"name":"",
"properties":[
{
"name":"focusable",
"type":"bool",
"value":true
}],
"rotation":359.800363945476,
"type":"",
"visible":true,
"width":318.187448731897,
"x":32.4024392837801,
"y":352.890077348834
},
{
"height":43.4101161995899,
"id":23,
"name":"",
"rotation":0,
"text":
{
"halign":"center",
"text":"THIS SHOULD NOT TRIGGER ANYTHING (TYPE IS NOT 'AREA')",
"wrap":true
},
"type":"",
"visible":true,
"width":288.225791752108,
"x":41.6752107541581,
"y":381.965937571201
}], }],
"opacity":1, "opacity":1,
"type":"objectgroup", "type":"objectgroup",
@ -136,7 +278,7 @@
"y":0 "y":0
}], }],
"nextlayerid":39, "nextlayerid":39,
"nextobjectid":15, "nextobjectid":24,
"orientation":"orthogonal", "orientation":"orthogonal",
"properties":[ "properties":[
{ {