Fix removing of co-website action trigger
This commit is contained in:
parent
6a7385947d
commit
24640d13bb
@ -4,10 +4,8 @@ import { scriptUtils } from "../../Api/ScriptUtils";
|
|||||||
import type { CoWebsite } from "../../WebRtc/CoWebsiteManager";
|
import type { CoWebsite } from "../../WebRtc/CoWebsiteManager";
|
||||||
import { coWebsiteManager } from "../../WebRtc/CoWebsiteManager";
|
import { coWebsiteManager } from "../../WebRtc/CoWebsiteManager";
|
||||||
import { layoutManagerActionStore } from "../../Stores/LayoutManagerStore";
|
import { layoutManagerActionStore } from "../../Stores/LayoutManagerStore";
|
||||||
import { get } from 'svelte/store';
|
import { get } from "svelte/store";
|
||||||
import {
|
import { ON_ACTION_TRIGGER_BUTTON } from "../../WebRtc/LayoutManager";
|
||||||
ON_ACTION_TRIGGER_BUTTON,
|
|
||||||
} from "../../WebRtc/LayoutManager";
|
|
||||||
import type { ITiledMapLayer } from "../Map/ITiledMap";
|
import type { ITiledMapLayer } from "../Map/ITiledMap";
|
||||||
import { GameMapProperties } from "./GameMapProperties";
|
import { GameMapProperties } from "./GameMapProperties";
|
||||||
|
|
||||||
@ -18,8 +16,8 @@ enum OpenCoWebsiteState {
|
|||||||
}
|
}
|
||||||
|
|
||||||
interface OpenCoWebsite {
|
interface OpenCoWebsite {
|
||||||
coWebsite: CoWebsite | undefined,
|
coWebsite: CoWebsite | undefined;
|
||||||
state: OpenCoWebsiteState
|
state: OpenCoWebsiteState;
|
||||||
}
|
}
|
||||||
|
|
||||||
export class GameMapPropertiesListener {
|
export class GameMapPropertiesListener {
|
||||||
@ -29,7 +27,7 @@ export class GameMapPropertiesListener {
|
|||||||
constructor(private scene: GameScene, private gameMap: GameMap) {}
|
constructor(private scene: GameScene, private gameMap: GameMap) {}
|
||||||
|
|
||||||
register() {
|
register() {
|
||||||
this.gameMap.onPropertyChange(GameMapProperties.OPEN_TAB, (newValue, oldvalue, allProps) => {
|
this.gameMap.onPropertyChange(GameMapProperties.OPEN_TAB, (newValue, oldValue, allProps) => {
|
||||||
if (newValue === undefined) {
|
if (newValue === undefined) {
|
||||||
layoutManagerActionStore.removeAction("openTab");
|
layoutManagerActionStore.removeAction("openTab");
|
||||||
}
|
}
|
||||||
@ -53,10 +51,10 @@ export class GameMapPropertiesListener {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Open a new co-website by the property.
|
// Open a new co-website by the property.
|
||||||
this.gameMap.onEnterLayer((newLayers) => {
|
this.gameMap.onEnterLayer((newLayers) => {
|
||||||
const handler = () => {
|
const handler = () => {
|
||||||
newLayers.forEach(layer => {
|
newLayers.forEach((layer) => {
|
||||||
if (!layer.properties) {
|
if (!layer.properties) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -69,8 +67,8 @@ export class GameMapPropertiesListener {
|
|||||||
let websiteTriggerProperty: string | undefined;
|
let websiteTriggerProperty: string | undefined;
|
||||||
let websiteTriggerMessageProperty: string | undefined;
|
let websiteTriggerMessageProperty: string | undefined;
|
||||||
|
|
||||||
layer.properties.forEach(property => {
|
layer.properties.forEach((property) => {
|
||||||
switch(property.name) {
|
switch (property.name) {
|
||||||
case GameMapProperties.OPEN_WEBSITE:
|
case GameMapProperties.OPEN_WEBSITE:
|
||||||
openWebsiteProperty = property.value as string | undefined;
|
openWebsiteProperty = property.value as string | undefined;
|
||||||
break;
|
break;
|
||||||
@ -111,26 +109,28 @@ export class GameMapPropertiesListener {
|
|||||||
});
|
});
|
||||||
|
|
||||||
const openWebsiteFunction = () => {
|
const openWebsiteFunction = () => {
|
||||||
coWebsiteManager.loadCoWebsite(
|
coWebsiteManager
|
||||||
openWebsiteProperty as string,
|
.loadCoWebsite(
|
||||||
this.scene.MapUrlFile,
|
openWebsiteProperty as string,
|
||||||
allowApiProperty,
|
this.scene.MapUrlFile,
|
||||||
websitePolicyProperty,
|
allowApiProperty,
|
||||||
websiteWidthProperty,
|
websitePolicyProperty,
|
||||||
websitePositionProperty,
|
websiteWidthProperty,
|
||||||
).then(coWebsite => {
|
websitePositionProperty
|
||||||
const coWebsiteOpen = this.coWebsitesOpenByLayer.get(layer);
|
)
|
||||||
if (coWebsiteOpen && coWebsiteOpen.state === OpenCoWebsiteState.MUST_BE_CLOSE) {
|
.then((coWebsite) => {
|
||||||
coWebsiteManager.closeCoWebsite(coWebsite);
|
const coWebsiteOpen = this.coWebsitesOpenByLayer.get(layer);
|
||||||
this.coWebsitesOpenByLayer.delete(layer);
|
if (coWebsiteOpen && coWebsiteOpen.state === OpenCoWebsiteState.MUST_BE_CLOSE) {
|
||||||
this.coWebsitesActionTriggerByLayer.delete(layer);
|
coWebsiteManager.closeCoWebsite(coWebsite);
|
||||||
} else {
|
this.coWebsitesOpenByLayer.delete(layer);
|
||||||
this.coWebsitesOpenByLayer.set(layer, {
|
this.coWebsitesActionTriggerByLayer.delete(layer);
|
||||||
coWebsite,
|
} else {
|
||||||
state: OpenCoWebsiteState.OPENED
|
this.coWebsitesOpenByLayer.set(layer, {
|
||||||
});
|
coWebsite,
|
||||||
}
|
state: OpenCoWebsiteState.OPENED,
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
layoutManagerActionStore.removeAction(actionUuid);
|
layoutManagerActionStore.removeAction(actionUuid);
|
||||||
};
|
};
|
||||||
@ -161,7 +161,7 @@ export class GameMapPropertiesListener {
|
|||||||
// Close opened co-websites on leave the layer who contain the property.
|
// Close opened co-websites on leave the layer who contain the property.
|
||||||
this.gameMap.onLeaveLayer((oldLayers) => {
|
this.gameMap.onLeaveLayer((oldLayers) => {
|
||||||
const handler = () => {
|
const handler = () => {
|
||||||
oldLayers.forEach(layer => {
|
oldLayers.forEach((layer) => {
|
||||||
if (!layer.properties) {
|
if (!layer.properties) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -169,8 +169,8 @@ export class GameMapPropertiesListener {
|
|||||||
let openWebsiteProperty: string | undefined;
|
let openWebsiteProperty: string | undefined;
|
||||||
let websiteTriggerProperty: string | undefined;
|
let websiteTriggerProperty: string | undefined;
|
||||||
|
|
||||||
layer.properties.forEach(property => {
|
layer.properties.forEach((property) => {
|
||||||
switch(property.name) {
|
switch (property.name) {
|
||||||
case GameMapProperties.OPEN_WEBSITE:
|
case GameMapProperties.OPEN_WEBSITE:
|
||||||
openWebsiteProperty = property.value as string | undefined;
|
openWebsiteProperty = property.value as string | undefined;
|
||||||
break;
|
break;
|
||||||
@ -192,11 +192,6 @@ export class GameMapPropertiesListener {
|
|||||||
|
|
||||||
if (coWebsiteOpen.state === OpenCoWebsiteState.LOADING) {
|
if (coWebsiteOpen.state === OpenCoWebsiteState.LOADING) {
|
||||||
coWebsiteOpen.state = OpenCoWebsiteState.MUST_BE_CLOSE;
|
coWebsiteOpen.state = OpenCoWebsiteState.MUST_BE_CLOSE;
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (coWebsiteOpen.state !== OpenCoWebsiteState.OPENED) {
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (coWebsiteOpen.coWebsite !== undefined) {
|
if (coWebsiteOpen.coWebsite !== undefined) {
|
||||||
@ -216,9 +211,10 @@ export class GameMapPropertiesListener {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const action = actionStore && actionStore.length > 0 ?
|
const action =
|
||||||
actionStore.find(action => action.uuid === actionTriggerUuid) : undefined;
|
actionStore && actionStore.length > 0
|
||||||
|
? actionStore.find((action) => action.uuid === actionTriggerUuid)
|
||||||
|
: undefined;
|
||||||
|
|
||||||
if (action) {
|
if (action) {
|
||||||
layoutManagerActionStore.removeAction(actionTriggerUuid);
|
layoutManagerActionStore.removeAction(actionTriggerUuid);
|
||||||
|
Loading…
Reference in New Issue
Block a user