Merge branch 'correct-merge' into metadataScriptAPIV2
This commit is contained in:
commit
9cd3ff1d31
8 changed files with 326 additions and 22 deletions
13
front/src/Api/Events/ChangeTileEvent.ts
Normal file
13
front/src/Api/Events/ChangeTileEvent.ts
Normal file
|
@ -0,0 +1,13 @@
|
|||
import * as tg from "generic-type-guard";
|
||||
|
||||
export const isChangeTileEvent =
|
||||
new tg.IsInterface().withProperties({
|
||||
x: tg.isNumber,
|
||||
y: tg.isNumber,
|
||||
tile: tg.isUnion(tg.isNumber, tg.isString),
|
||||
layer: tg.isUnion(tg.isNumber, tg.isString)
|
||||
}).get();
|
||||
/**
|
||||
* A message sent from the game to the iFrame when a user enters or leaves a zone marked with the "zone" property.
|
||||
*/
|
||||
export type ChangeTileEvent = tg.GuardedType<typeof isChangeTileEvent>;
|
|
@ -15,8 +15,9 @@ import type { UserInputChatEvent } from './UserInputChatEvent';
|
|||
import type { DataLayerEvent } from "./DataLayerEvent";
|
||||
import type { LayerEvent } from './LayerEvent';
|
||||
import type { SetPropertyEvent } from "./setPropertyEvent";
|
||||
import type {LoadSoundEvent} from "./LoadSoundEvent";
|
||||
import type {PlaySoundEvent} from "./PlaySoundEvent";
|
||||
import type { LoadSoundEvent } from "./LoadSoundEvent";
|
||||
import type { PlaySoundEvent } from "./PlaySoundEvent";
|
||||
import type { ChangeTileEvent } from "./ChangeTileEvent";
|
||||
|
||||
|
||||
export interface TypedMessageEvent<T> extends MessageEvent {
|
||||
|
@ -46,6 +47,7 @@ export type IframeEventMap = {
|
|||
loadSound: LoadSoundEvent
|
||||
playSound: PlaySoundEvent
|
||||
stopSound: null
|
||||
changeTile: ChangeTileEvent
|
||||
}
|
||||
export interface IframeEvent<T extends keyof IframeEventMap> {
|
||||
type: T;
|
||||
|
|
|
@ -24,6 +24,7 @@ import type { MenuItemClickedEvent } from './Events/MenuItemClickedEvent';
|
|||
import { isPlaySoundEvent, PlaySoundEvent } from "./Events/PlaySoundEvent";
|
||||
import { isStopSoundEvent, StopSoundEvent } from "./Events/StopSoundEvent";
|
||||
import { isLoadSoundEvent, LoadSoundEvent } from "./Events/LoadSoundEvent";
|
||||
import { isChangeTileEvent, ChangeTileEvent } from './Events/ChangeTileEvent';
|
||||
/**
|
||||
* Listens to messages from iframes and turn those messages into easy to use observables.
|
||||
* Also allows to send messages to those iframes.
|
||||
|
@ -93,6 +94,9 @@ class IframeListener {
|
|||
private readonly _loadSoundStream: Subject<LoadSoundEvent> = new Subject();
|
||||
public readonly loadSoundStream = this._loadSoundStream.asObservable();
|
||||
|
||||
private readonly _changeTileStream: Subject<ChangeTileEvent> = new Subject();
|
||||
public readonly changeTileStream = this._changeTileStream.asObservable();
|
||||
|
||||
private readonly iframes = new Set<HTMLIFrameElement>();
|
||||
private readonly scripts = new Map<string, HTMLIFrameElement>();
|
||||
private sendPlayerMove: boolean = false;
|
||||
|
@ -172,8 +176,8 @@ class IframeListener {
|
|||
this._dataLayerChangeStream.next();
|
||||
} else if (payload.type == "registerMenuCommand" && isMenuItemRegisterEvent(payload.data)) {
|
||||
this._registerMenuCommandStream.next(payload.data.menutItem)
|
||||
/* } else if (payload.type == "tilsetEvent" && isTilesetEvent(payload.data)) {
|
||||
this._tilesetLoaderStream.next(payload.data);*/
|
||||
} else if (payload.type == "changeTile" && isChangeTileEvent(payload.data)) {
|
||||
this._changeTileStream.next(payload.data);
|
||||
}
|
||||
}
|
||||
}, false);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue