enter and leave zone events
This commit is contained in:
parent
03cf5c05ff
commit
4d473480cf
11
front/src/Api/Events/ChangeZoneEvent.ts
Normal file
11
front/src/Api/Events/ChangeZoneEvent.ts
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
import * as tg from "generic-type-guard";
|
||||||
|
|
||||||
|
export const isChangeZoneEvent = new tg.IsInterface()
|
||||||
|
.withProperties({
|
||||||
|
name: tg.isString,
|
||||||
|
})
|
||||||
|
.get();
|
||||||
|
/**
|
||||||
|
* A message sent from the game to the iFrame when a user enters or leaves a layer.
|
||||||
|
*/
|
||||||
|
export type ChangeZoneEvent = tg.GuardedType<typeof isChangeZoneEvent>;
|
@ -28,6 +28,7 @@ import type { MessageReferenceEvent } from "./ui/TriggerActionMessageEvent";
|
|||||||
import { isMessageReferenceEvent, isTriggerActionMessageEvent } from "./ui/TriggerActionMessageEvent";
|
import { isMessageReferenceEvent, isTriggerActionMessageEvent } from "./ui/TriggerActionMessageEvent";
|
||||||
import type { MenuRegisterEvent, UnregisterMenuEvent } from "./ui/MenuRegisterEvent";
|
import type { MenuRegisterEvent, UnregisterMenuEvent } from "./ui/MenuRegisterEvent";
|
||||||
import type { ChangeLayerEvent } from "./ChangeLayerEvent";
|
import type { ChangeLayerEvent } from "./ChangeLayerEvent";
|
||||||
|
import type { ChangeZoneEvent } from "./ChangeZoneEvent";
|
||||||
|
|
||||||
export interface TypedMessageEvent<T> extends MessageEvent {
|
export interface TypedMessageEvent<T> extends MessageEvent {
|
||||||
data: T;
|
data: T;
|
||||||
@ -76,6 +77,8 @@ export interface IframeResponseEventMap {
|
|||||||
leaveEvent: EnterLeaveEvent;
|
leaveEvent: EnterLeaveEvent;
|
||||||
enterLayerEvent: ChangeLayerEvent;
|
enterLayerEvent: ChangeLayerEvent;
|
||||||
leaveLayerEvent: ChangeLayerEvent;
|
leaveLayerEvent: ChangeLayerEvent;
|
||||||
|
enterZoneEvent: ChangeZoneEvent;
|
||||||
|
leaveZoneEvent: ChangeZoneEvent;
|
||||||
buttonClickedEvent: ButtonClickedEvent;
|
buttonClickedEvent: ButtonClickedEvent;
|
||||||
hasPlayerMoved: HasPlayerMovedEvent;
|
hasPlayerMoved: HasPlayerMovedEvent;
|
||||||
menuItemClicked: MenuItemClickedEvent;
|
menuItemClicked: MenuItemClickedEvent;
|
||||||
|
@ -31,6 +31,7 @@ import type { SetVariableEvent } from "./Events/SetVariableEvent";
|
|||||||
import { ModifyEmbeddedWebsiteEvent, isEmbeddedWebsiteEvent } from "./Events/EmbeddedWebsiteEvent";
|
import { ModifyEmbeddedWebsiteEvent, isEmbeddedWebsiteEvent } from "./Events/EmbeddedWebsiteEvent";
|
||||||
import { handleMenuRegistrationEvent, handleMenuUnregisterEvent } from "../Stores/MenuStore";
|
import { handleMenuRegistrationEvent, handleMenuUnregisterEvent } from "../Stores/MenuStore";
|
||||||
import type { ChangeLayerEvent } from "./Events/ChangeLayerEvent";
|
import type { ChangeLayerEvent } from "./Events/ChangeLayerEvent";
|
||||||
|
import type { ChangeZoneEvent } from "./Events/ChangeZoneEvent";
|
||||||
|
|
||||||
type AnswererCallback<T extends keyof IframeQueryMap> = (
|
type AnswererCallback<T extends keyof IframeQueryMap> = (
|
||||||
query: IframeQueryMap[T]["query"],
|
query: IframeQueryMap[T]["query"],
|
||||||
@ -414,6 +415,24 @@ class IframeListener {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sendEnterZoneEvent(zoneName: string) {
|
||||||
|
this.postMessage({
|
||||||
|
type: "enterZoneEvent",
|
||||||
|
data: {
|
||||||
|
name: zoneName,
|
||||||
|
} as ChangeZoneEvent,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
sendLeaveZoneEvent(zoneName: string) {
|
||||||
|
this.postMessage({
|
||||||
|
type: "leaveZoneEvent",
|
||||||
|
data: {
|
||||||
|
name: zoneName,
|
||||||
|
} as ChangeZoneEvent,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
hasPlayerMoved(event: HasPlayerMovedEvent) {
|
hasPlayerMoved(event: HasPlayerMovedEvent) {
|
||||||
if (this.sendPlayerMove) {
|
if (this.sendPlayerMove) {
|
||||||
this.postMessage({
|
this.postMessage({
|
||||||
|
@ -196,9 +196,6 @@ export class GameMap {
|
|||||||
*/
|
*/
|
||||||
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
|
|
||||||
// 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) {
|
||||||
|
@ -798,9 +798,9 @@ export class GameScene extends DirtyScene {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// zones.forEach((zone) => {
|
zones.forEach((zone) => {
|
||||||
// iframeListener.sendEnterLayerEvent(zone.name);
|
iframeListener.sendEnterZoneEvent(zone.name);
|
||||||
// });
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
this.gameMap.onLeaveZone((zones) => {
|
this.gameMap.onLeaveZone((zones) => {
|
||||||
@ -811,9 +811,9 @@ export class GameScene extends DirtyScene {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// zones.forEach((zone) => {
|
zones.forEach((zone) => {
|
||||||
// iframeListener.sendEnterLayerEvent(zone.name);
|
iframeListener.sendLeaveZoneEvent(zone.name);
|
||||||
// });
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
// this.gameMap.onLeaveLayer((layers) => {
|
// this.gameMap.onLeaveLayer((layers) => {
|
||||||
|
Loading…
Reference in New Issue
Block a user