Merge branch 'update-game-tiles' into metadataScriptingApi

This commit is contained in:
GRL 2021-05-21 15:56:35 +02:00
commit 796a9418d3
6 changed files with 79 additions and 42 deletions

View file

@ -17,6 +17,7 @@ import type { LayerEvent } from './LayerEvent';
import type { SetPropertyEvent } from "./setPropertyEvent";
import type { TagEvent } from "./TagEvent";
import type { TilesetEvent } from "./TilesetEvent";
import type { UpdateTileEvent } from "./UpdateTileEvent";
export interface TypedMessageEvent<T> extends MessageEvent {
data: T
@ -43,7 +44,8 @@ export type IframeEventMap = {
setProperty: SetPropertyEvent
getDataLayer: undefined
getTag: undefined
tilsetEvent: TilesetEvent
tilesetEvent: TilesetEvent
updateTileEvent: UpdateTileEvent
}
export interface IframeEvent<T extends keyof IframeEventMap> {
type: T;

View file

@ -0,0 +1,15 @@
import * as tg from "generic-type-guard";
export const isUpdateTileEvent = tg.isArray(
new tg.IsInterface().withProperties({
x: tg.isNumber,
y: tg.isNumber,
tile: tg.isUnion(tg.isNumber, tg.isString),
layer: 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 UpdateTileEvent = tg.GuardedType<typeof isUpdateTileEvent>;

View file

@ -21,6 +21,7 @@ import { isMenuItemRegisterEvent } from './Events/MenuItemRegisterEvent';
import type { MenuItemClickedEvent } from './Events/MenuItemClickedEvent';
import type { TagEvent } from "./Events/TagEvent";
import { isTilesetEvent, TilesetEvent } from "./Events/TilesetEvent";
import { isUpdateTileEvent, UpdateTileEvent } from './Events/UpdateTileEvent';
/**
@ -35,12 +36,6 @@ class IframeListener {
private readonly _openPopupStream: Subject<OpenPopupEvent> = new Subject();
public readonly openPopupStream = this._openPopupStream.asObservable();
private readonly _openTabStream: Subject<OpenTabEvent> = new Subject();
public readonly openTabStream = this._openTabStream.asObservable();
private readonly _goToPageStream: Subject<GoToPageEvent> = new Subject();
public readonly goToPageStream = this._goToPageStream.asObservable();
private readonly _openCoWebSiteStream: Subject<OpenCoWebSiteEvent> = new Subject();
public readonly openCoWebSiteStream = this._openCoWebSiteStream.asObservable();
@ -86,6 +81,9 @@ class IframeListener {
private readonly _tilesetLoaderStream: Subject<TilesetEvent> = new Subject();
public readonly tilesetLoaderStream = this._tilesetLoaderStream.asObservable();
private readonly _updateTileStream: Subject<UpdateTileEvent> = new Subject();
public readonly updateTileStream = this._updateTileStream.asObservable();
private readonly iframes = new Set<HTMLIFrameElement>();
private readonly scripts = new Map<string, HTMLIFrameElement>();
private sendPlayerMove: boolean = false;
@ -156,8 +154,10 @@ class IframeListener {
this._registerMenuCommandStream.next(payload.data.menutItem)
} else if (payload.type == "getTag") {
this._tagListStream.next();
} else if (payload.type == "tilsetEvent" && isTilesetEvent(payload.data)) {
} else if (payload.type == "tilesetEvent" && isTilesetEvent(payload.data)) {
this._tilesetLoaderStream.next(payload.data);
} else if (payload.type == "updateTileEvent" && isUpdateTileEvent(payload.data)) {
this._updateTileStream.next(payload.data)
}
}
}, false);