Renaming changeTile to setTiles

This commit is contained in:
David Négrier 2021-06-28 14:58:49 +02:00
parent 319db95bc8
commit 1e57028e6e
11 changed files with 85 additions and 85 deletions

View file

@ -18,7 +18,7 @@ import type { PlaySoundEvent } from "./PlaySoundEvent";
import type { MenuItemClickedEvent } from "./ui/MenuItemClickedEvent";
import type { MenuItemRegisterEvent } from './ui/MenuItemRegisterEvent';
import type { HasPlayerMovedEvent } from "./HasPlayerMovedEvent";
import type { ChangeTileEvent } from "./ChangeTileEvent";
import type { SetTilesEvent } from "./SetTilesEvent";
export interface TypedMessageEvent<T> extends MessageEvent {
data: T
@ -46,7 +46,7 @@ export type IframeEventMap = {
loadSound: LoadSoundEvent
playSound: PlaySoundEvent
stopSound: null
changeTile: ChangeTileEvent
setTiles: SetTilesEvent
getState: undefined,
registerMenuCommand: MenuItemRegisterEvent
}

View file

@ -1,6 +1,6 @@
import * as tg from "generic-type-guard";
export const isChangeTileEvent =
export const isSetTilesEvent =
tg.isArray(
new tg.IsInterface().withProperties({
x: tg.isNumber,
@ -10,6 +10,6 @@ export const isChangeTileEvent =
}).get()
);
/**
* A message sent from the game to the iFrame when a user enters or leaves a zone marked with the "zone" property.
* A message sent from the iFrame to the game to set one or many tiles.
*/
export type ChangeTileEvent = tg.GuardedType<typeof isChangeTileEvent>;
export type SetTilesEvent = tg.GuardedType<typeof isSetTilesEvent>;

View file

@ -29,7 +29,7 @@ import type {GameStateEvent} from "./Events/GameStateEvent";
import type {HasPlayerMovedEvent} from "./Events/HasPlayerMovedEvent";
import {isLoadPageEvent} from "./Events/LoadPageEvent";
import {handleMenuItemRegistrationEvent, isMenuItemRegisterIframeEvent} from "./Events/ui/MenuItemRegisterEvent";
import {ChangeTileEvent, isChangeTileEvent} from "./Events/ChangeTileEvent";
import {SetTilesEvent, isSetTilesEvent} from "./Events/SetTilesEvent";
/**
* Listens to messages from iframes and turn those messages into easy to use observables.
@ -103,8 +103,8 @@ 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 _setTilesStream: Subject<SetTilesEvent> = new Subject();
public readonly setTilesStream = this._setTilesStream.asObservable();
private readonly iframes = new Set<HTMLIFrameElement>();
private readonly iframeCloseCallbacks = new Map<HTMLIFrameElement, (() => void)[]>();
@ -193,8 +193,8 @@ class IframeListener {
this._unregisterMenuCommandStream.next(data);
})
handleMenuItemRegistrationEvent(payload.data)
} else if (payload.type == "changeTile" && isChangeTileEvent(payload.data)) {
this._changeTileStream.next(payload.data);
} else if (payload.type == "setTiles" && isSetTilesEvent(payload.data)) {
this._setTilesStream.next(payload.data);
}
}
}, false);

View file

@ -137,9 +137,9 @@ class WorkadventureRoomCommands extends IframeApiContribution<WorkadventureRoomC
return { id: gameState.uuid, nickName: gameState.nickname, tags: gameState.tags };
});
}
changeTile(tiles: TileDescriptor[]) {
setTiles(tiles: TileDescriptor[]) {
sendToWorkadventure({
type: 'changeTile',
type: 'setTiles',
data: tiles
})
}

View file

@ -947,7 +947,7 @@ ${escapedMessage}
tags: this.connection ? this.connection.getAllTags() : []
})
}));
this.iframeSubscriptionList.push(iframeListener.changeTileStream.subscribe((eventTiles) => {
this.iframeSubscriptionList.push(iframeListener.setTilesStream.subscribe((eventTiles) => {
for (const eventTile of eventTiles) {
this.gameMap.putTile(eventTile.tile, eventTile.x, eventTile.y, eventTile.layer);
}