Migrating WA.player.getCurrentUser and WA.room.getCurrentRoom to direct property access and WA.room.getMap
This commit is contained in:
parent
ea1460abaf
commit
62a4814961
11 changed files with 220 additions and 159 deletions
|
@ -4,10 +4,11 @@ export const isGameStateEvent = new tg.IsInterface()
|
|||
.withProperties({
|
||||
roomId: tg.isString,
|
||||
mapUrl: tg.isString,
|
||||
nickname: tg.isUnion(tg.isString, tg.isNull),
|
||||
nickname: tg.isString,
|
||||
uuid: tg.isUnion(tg.isString, tg.isUndefined),
|
||||
startLayerName: tg.isUnion(tg.isString, tg.isNull),
|
||||
tags: tg.isArray(tg.isString),
|
||||
variables: tg.isObject,
|
||||
})
|
||||
.get();
|
||||
/**
|
||||
|
|
|
@ -9,7 +9,7 @@ import type { OpenCoWebSiteEvent } from "./OpenCoWebSiteEvent";
|
|||
import type { OpenPopupEvent } from "./OpenPopupEvent";
|
||||
import type { OpenTabEvent } from "./OpenTabEvent";
|
||||
import type { UserInputChatEvent } from "./UserInputChatEvent";
|
||||
import type { DataLayerEvent } from "./DataLayerEvent";
|
||||
import type { MapDataEvent } from "./MapDataEvent";
|
||||
import type { LayerEvent } from "./LayerEvent";
|
||||
import type { SetPropertyEvent } from "./setPropertyEvent";
|
||||
import type { LoadSoundEvent } from "./LoadSoundEvent";
|
||||
|
@ -19,8 +19,6 @@ import type { MenuItemRegisterEvent } from "./ui/MenuItemRegisterEvent";
|
|||
import type { HasPlayerMovedEvent } from "./HasPlayerMovedEvent";
|
||||
import type { SetTilesEvent } from "./SetTilesEvent";
|
||||
import type { SetVariableEvent } from "./SetVariableEvent";
|
||||
import type {InitEvent} from "./InitEvent";
|
||||
|
||||
|
||||
export interface TypedMessageEvent<T> extends MessageEvent {
|
||||
data: T;
|
||||
|
@ -46,7 +44,6 @@ export type IframeEventMap = {
|
|||
showLayer: LayerEvent;
|
||||
hideLayer: LayerEvent;
|
||||
setProperty: SetPropertyEvent;
|
||||
getDataLayer: undefined;
|
||||
loadSound: LoadSoundEvent;
|
||||
playSound: PlaySoundEvent;
|
||||
stopSound: null;
|
||||
|
@ -54,8 +51,6 @@ export type IframeEventMap = {
|
|||
registerMenuCommand: MenuItemRegisterEvent;
|
||||
setTiles: SetTilesEvent;
|
||||
setVariable: SetVariableEvent;
|
||||
// A script/iframe is ready to receive events
|
||||
ready: null;
|
||||
};
|
||||
export interface IframeEvent<T extends keyof IframeEventMap> {
|
||||
type: T;
|
||||
|
@ -72,10 +67,8 @@ export interface IframeResponseEventMap {
|
|||
leaveEvent: EnterLeaveEvent;
|
||||
buttonClickedEvent: ButtonClickedEvent;
|
||||
hasPlayerMoved: HasPlayerMovedEvent;
|
||||
dataLayer: DataLayerEvent;
|
||||
menuItemClicked: MenuItemClickedEvent;
|
||||
setVariable: SetVariableEvent;
|
||||
init: InitEvent;
|
||||
}
|
||||
export interface IframeResponseEvent<T extends keyof IframeResponseEventMap> {
|
||||
type: T;
|
||||
|
@ -94,8 +87,14 @@ export const isIframeResponseEventWrapper = (event: {
|
|||
export type IframeQueryMap = {
|
||||
getState: {
|
||||
query: undefined,
|
||||
answer: GameStateEvent
|
||||
answer: GameStateEvent,
|
||||
callback: () => GameStateEvent|PromiseLike<GameStateEvent>
|
||||
},
|
||||
getMapData: {
|
||||
query: undefined,
|
||||
answer: MapDataEvent,
|
||||
callback: () => MapDataEvent|PromiseLike<GameStateEvent>
|
||||
}
|
||||
}
|
||||
|
||||
export interface IframeQuery<T extends keyof IframeQueryMap> {
|
||||
|
|
|
@ -1,10 +0,0 @@
|
|||
import * as tg from "generic-type-guard";
|
||||
|
||||
export const isInitEvent =
|
||||
new tg.IsInterface().withProperties({
|
||||
variables: tg.isObject
|
||||
}).get();
|
||||
/**
|
||||
* A message sent from the game just after an iFrame opens, to send all important data (like variables)
|
||||
*/
|
||||
export type InitEvent = tg.GuardedType<typeof isInitEvent>;
|
|
@ -1,6 +1,6 @@
|
|||
import * as tg from "generic-type-guard";
|
||||
|
||||
export const isDataLayerEvent = new tg.IsInterface()
|
||||
export const isMapDataEvent = new tg.IsInterface()
|
||||
.withProperties({
|
||||
data: tg.isObject,
|
||||
})
|
||||
|
@ -9,4 +9,4 @@ export const isDataLayerEvent = new tg.IsInterface()
|
|||
/**
|
||||
* A message sent from the game to the iFrame when the data of the layers change after the iFrame send a message to the game that it want to listen to the data of the layers
|
||||
*/
|
||||
export type DataLayerEvent = tg.GuardedType<typeof isDataLayerEvent>;
|
||||
export type MapDataEvent = tg.GuardedType<typeof isMapDataEvent>;
|
Loading…
Add table
Add a link
Reference in a new issue