option to update tile
# Conflicts: # front/src/Api/Events/ApiUpdateTileEvent.ts # front/src/Api/IframeListener.ts # front/src/Phaser/Game/GameScene.ts
This commit is contained in:
parent
79e530f0e6
commit
ffe03d40f5
4 changed files with 227 additions and 163 deletions
16
front/src/Api/Events/ApiUpdateTileEvent.ts
Normal file
16
front/src/Api/Events/ApiUpdateTileEvent.ts
Normal file
|
@ -0,0 +1,16 @@
|
|||
|
||||
import * as tg from "generic-type-guard";
|
||||
export const updateTile = "updateTile"
|
||||
|
||||
|
||||
export const isUpdateTileEvent =
|
||||
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 UpdateTileEvent = tg.GuardedType<typeof isUpdateTileEvent>;
|
|
@ -57,6 +57,9 @@ class IframeListener {
|
|||
private readonly _removeBubbleStream: Subject<void> = new Subject();
|
||||
public readonly removeBubbleStream = this._removeBubbleStream.asObservable();
|
||||
|
||||
private readonly _updateTileEvent: Subject<UpdateTileEvent> = new Subject();
|
||||
public readonly updateTileEvent = this._updateTileEvent.asObservable();
|
||||
|
||||
private readonly iframes = new Set<HTMLIFrameElement>();
|
||||
private readonly scripts = new Map<string, HTMLIFrameElement>();
|
||||
|
||||
|
@ -110,6 +113,10 @@ class IframeListener {
|
|||
this._removeBubbleStream.next();
|
||||
}else if (payload.type === 'loadPage' && isLoadPageEvent(payload.data)){
|
||||
this._loadPageStream.next(payload.data.url);
|
||||
} else if (payload.type == "getState") {
|
||||
this._gameStateStream.next();
|
||||
} else if (payload.type == "updateTile" && isUpdateTileEvent(payload.data)) {
|
||||
this._updateTileEvent.next(payload.data)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -91,6 +91,10 @@ import {LayersIterator} from "../Map/LayersIterator";
|
|||
import {touchScreenManager} from "../../Touch/TouchScreenManager";
|
||||
import {PinchManager} from "../UserInput/PinchManager";
|
||||
import {joystickBaseImg, joystickBaseKey, joystickThumbImg, joystickThumbKey} from "../Components/MobileJoystick";
|
||||
import { TextUtils } from "../Components/TextUtils";
|
||||
import { touchScreenManager } from "../../Touch/TouchScreenManager";
|
||||
import { PinchManager } from "../UserInput/PinchManager";
|
||||
import { joystickBaseImg, joystickBaseKey, joystickThumbImg, joystickThumbKey } from "../Components/MobileJoystick";
|
||||
|
||||
export interface GameSceneInitInterface {
|
||||
initPosition: PointInterface | null,
|
||||
|
@ -867,6 +871,25 @@ ${escapedMessage}
|
|||
})
|
||||
})
|
||||
}));
|
||||
|
||||
this.iframeSubscriptionList.push(iframeListener.updateTileEvent.subscribe(event => {
|
||||
const layer = this.Layers.find(layer => layer.layer.name == event.layer)
|
||||
if (layer) {
|
||||
const tile = layer.getTileAt(event.x, event.y)
|
||||
if (typeof event.tile == "string") {
|
||||
const tileIndex = this.getIndexForTileType(event.tile);
|
||||
if (tileIndex) {
|
||||
tile.index = tileIndex
|
||||
} else {
|
||||
return
|
||||
}
|
||||
} else {
|
||||
tile.index = event.tile
|
||||
}
|
||||
this.scene.scene.sys.game.events.emit("contextrestored")
|
||||
}
|
||||
}))
|
||||
|
||||
let scriptedBubbleSprite: Sprite;
|
||||
this.iframeSubscriptionList.push(iframeListener.displayBubbleStream.subscribe(() => {
|
||||
scriptedBubbleSprite = new Sprite(this, this.CurrentPlayer.x + 25, this.CurrentPlayer.y, 'circleSprite-white');
|
||||
|
@ -880,6 +903,19 @@ ${escapedMessage}
|
|||
|
||||
}
|
||||
|
||||
private getIndexForTileType(tileType: string): number | undefined {
|
||||
for (const tileset of this.mapFile.tilesets) {
|
||||
if (tileset.tiles) {
|
||||
for (const tilesetTile of tileset.tiles) {
|
||||
if (tilesetTile.type == tileType) {
|
||||
return tileset.firstgid + tilesetTile.id
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return undefined
|
||||
}
|
||||
|
||||
private getMapDirUrl(): string {
|
||||
return this.MapUrlFile.substr(0, this.MapUrlFile.lastIndexOf('/'));
|
||||
}
|
||||
|
|
|
@ -167,7 +167,7 @@ export interface ITiledTileSet {
|
|||
tilewidth: number;
|
||||
transparentcolor: string;
|
||||
terrains: ITiledMapTerrain[];
|
||||
tiles: {[key: string]: { terrain: number[] }};
|
||||
tiles: Array<ITile>;
|
||||
|
||||
/**
|
||||
* Refers to external tileset file (should be JSON)
|
||||
|
@ -175,6 +175,11 @@ export interface ITiledTileSet {
|
|||
source: string;
|
||||
}
|
||||
|
||||
export interface ITile {
|
||||
id: number,
|
||||
type?: string
|
||||
}
|
||||
|
||||
export interface ITiledMapTerrain {
|
||||
name: string;
|
||||
tile: number;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue