preparation for merge with metadataScriptApi

This commit is contained in:
GRL 2021-05-25 09:50:59 +02:00
parent 46996f7049
commit b18b2fe0e3
3 changed files with 10 additions and 12 deletions

View file

@ -1,9 +1,7 @@
import * as tg from "generic-type-guard";
export const updateTile = "updateTile"
export const isUpdateTileEvent = tg.isArray(
export const isChangeTileEvent = tg.isArray(
new tg.IsInterface().withProperties({
x: tg.isNumber,
y: tg.isNumber,
@ -14,4 +12,4 @@ export const isUpdateTileEvent = tg.isArray(
/**
* 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>;
export type ChangeTileEvent = tg.GuardedType<typeof isChangeTileEvent>;

View file

@ -13,7 +13,7 @@ import { scriptUtils } from "./ScriptUtils";
import { GoToPageEvent, isGoToPageEvent } from "./Events/GoToPageEvent";
import { isOpenCoWebsite, OpenCoWebSiteEvent } from "./Events/OpenCoWebSiteEvent";
import { isLoadPageEvent } from './Events/LoadPageEvent';
import { isUpdateTileEvent, UpdateTileEvent } from './Events/ApiUpdateTileEvent';
import { isChangeTileEvent, ChangeTileEvent } from './Events/ChangeTileEvent';
/**
@ -58,7 +58,7 @@ class IframeListener {
private readonly _removeBubbleStream: Subject<void> = new Subject();
public readonly removeBubbleStream = this._removeBubbleStream.asObservable();
private readonly _updateTileEvent: Subject<UpdateTileEvent> = new Subject();
private readonly _updateTileEvent: Subject<ChangeTileEvent> = new Subject();
public readonly updateTileEvent = this._updateTileEvent.asObservable();
private readonly iframes = new Set<HTMLIFrameElement>();
@ -114,7 +114,7 @@ class IframeListener {
this._removeBubbleStream.next();
} else if (payload.type === 'loadPage' && isLoadPageEvent(payload.data)) {
this._loadPageStream.next(payload.data.url);
} else if (payload.type == "updateTile" && isUpdateTileEvent(payload.data)) {
} else if (payload.type == "updateTile" && isChangeTileEvent(payload.data)) {
this._updateTileEvent.next(payload.data)
}
}

View file

@ -134,7 +134,7 @@ export class GameScene extends ResizableScene implements CenterListener {
MapPlayers!: Phaser.Physics.Arcade.Group;
MapPlayersByKey: Map<number, RemotePlayer> = new Map<number, RemotePlayer>();
Map!: Phaser.Tilemaps.Tilemap;
Layers!: Array<Phaser.Tilemaps.StaticTilemapLayer>;
Layers!: Array<Phaser.Tilemaps.TilemapLayer>;
Objects!: Array<Phaser.Physics.Arcade.Sprite>;
mapFile!: ITiledMap;
groups: Map<number, Sprite>;
@ -395,12 +395,12 @@ export class GameScene extends ResizableScene implements CenterListener {
this.physics.world.setBounds(0, 0, this.Map.widthInPixels, this.Map.heightInPixels);
//add layer on map
this.Layers = new Array<Phaser.Tilemaps.StaticTilemapLayer>();
this.Layers = new Array<Phaser.Tilemaps.TilemapLayer>();
let depth = -2;
for (const layer of this.gameMap.layersIterator) {
if (layer.type === 'tilelayer') {
this.addLayer(this.Map.createStaticLayer(layer.name, this.Terrains, 0, 0).setDepth(depth));
this.addLayer(this.Map.createLayer(layer.name, this.Terrains, 0, 0).setDepth(depth));
const exitSceneUrl = this.getExitSceneUrl(layer);
if (exitSceneUrl !== undefined) {
@ -1105,13 +1105,13 @@ ${escapedMessage}
this.cameras.main.setZoom(ZOOM_LEVEL);
}
addLayer(Layer: Phaser.Tilemaps.StaticTilemapLayer) {
addLayer(Layer: Phaser.Tilemaps.TilemapLayer) {
this.Layers.push(Layer);
}
createCollisionWithPlayer() {
//add collision layer
this.Layers.forEach((Layer: Phaser.Tilemaps.StaticTilemapLayer) => {
this.Layers.forEach((Layer: Phaser.Tilemaps.TilemapLayer) => {
this.physics.add.collider(this.CurrentPlayer, Layer, (object1: GameObject, object2: GameObject) => {
//this.CurrentPlayer.say("Collision with layer : "+ (object2 as Tile).layer.name)
});