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();
|
private readonly _removeBubbleStream: Subject<void> = new Subject();
|
||||||
public readonly removeBubbleStream = this._removeBubbleStream.asObservable();
|
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 iframes = new Set<HTMLIFrameElement>();
|
||||||
private readonly scripts = new Map<string, HTMLIFrameElement>();
|
private readonly scripts = new Map<string, HTMLIFrameElement>();
|
||||||
|
|
||||||
|
@ -110,6 +113,10 @@ class IframeListener {
|
||||||
this._removeBubbleStream.next();
|
this._removeBubbleStream.next();
|
||||||
}else if (payload.type === 'loadPage' && isLoadPageEvent(payload.data)){
|
}else if (payload.type === 'loadPage' && isLoadPageEvent(payload.data)){
|
||||||
this._loadPageStream.next(payload.data.url);
|
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 {touchScreenManager} from "../../Touch/TouchScreenManager";
|
||||||
import {PinchManager} from "../UserInput/PinchManager";
|
import {PinchManager} from "../UserInput/PinchManager";
|
||||||
import {joystickBaseImg, joystickBaseKey, joystickThumbImg, joystickThumbKey} from "../Components/MobileJoystick";
|
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 {
|
export interface GameSceneInitInterface {
|
||||||
initPosition: PointInterface | null,
|
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;
|
let scriptedBubbleSprite: Sprite;
|
||||||
this.iframeSubscriptionList.push(iframeListener.displayBubbleStream.subscribe(() => {
|
this.iframeSubscriptionList.push(iframeListener.displayBubbleStream.subscribe(() => {
|
||||||
scriptedBubbleSprite = new Sprite(this, this.CurrentPlayer.x + 25, this.CurrentPlayer.y, 'circleSprite-white');
|
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 {
|
private getMapDirUrl(): string {
|
||||||
return this.MapUrlFile.substr(0, this.MapUrlFile.lastIndexOf('/'));
|
return this.MapUrlFile.substr(0, this.MapUrlFile.lastIndexOf('/'));
|
||||||
}
|
}
|
||||||
|
|
|
@ -167,7 +167,7 @@ export interface ITiledTileSet {
|
||||||
tilewidth: number;
|
tilewidth: number;
|
||||||
transparentcolor: string;
|
transparentcolor: string;
|
||||||
terrains: ITiledMapTerrain[];
|
terrains: ITiledMapTerrain[];
|
||||||
tiles: {[key: string]: { terrain: number[] }};
|
tiles: Array<ITile>;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Refers to external tileset file (should be JSON)
|
* Refers to external tileset file (should be JSON)
|
||||||
|
@ -175,6 +175,11 @@ export interface ITiledTileSet {
|
||||||
source: string;
|
source: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface ITile {
|
||||||
|
id: number,
|
||||||
|
type?: string
|
||||||
|
}
|
||||||
|
|
||||||
export interface ITiledMapTerrain {
|
export interface ITiledMapTerrain {
|
||||||
name: string;
|
name: string;
|
||||||
tile: number;
|
tile: number;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue