Uses the current player position rather than the starting one to position iframe

This commit is contained in:
Benedicte Quimbert 2021-10-29 12:01:07 +02:00
parent e39e341ab7
commit 516d756db1
4 changed files with 36 additions and 0 deletions

View File

@ -31,6 +31,7 @@ import type { ChangeLayerEvent } from "./ChangeLayerEvent";
import { isPlayerPropertyEvent } from "./PlayerPropertyEvent";
import type { ChangeZoneEvent } from "./ChangeZoneEvent";
import { isColorEvent } from "./ColorEvent";
import { isPlayerPosition } from "./PlayerPosition";
export interface TypedMessageEvent<T> extends MessageEvent {
data: T;
@ -170,6 +171,10 @@ export const iframeQueryMapTypeGuards = {
query: tg.isUndefined,
answer: tg.isUndefined,
},
getPlayerPosition: {
query: tg.isUndefined,
answer: isPlayerPosition,
},
};
type GuardedType<T> = T extends (x: unknown) => x is infer T ? T : never;

View File

@ -0,0 +1,10 @@
import * as tg from "generic-type-guard";
export const isPlayerPosition = new tg.IsInterface()
.withProperties({
x: tg.isNumber,
y: tg.isNumber,
})
.get();
export type PlayerPosition = tg.GuardedType<typeof isPlayerPosition>;

View File

@ -77,6 +77,13 @@ export class WorkadventurePlayerCommands extends IframeApiContribution<Workadven
return uuid;
}
async getPosition(): Promise<Position> {
return await queryWorkadventure({
type: "getPlayerPosition",
data: undefined,
});
}
get userRoomToken(): string | undefined {
if (userRoomToken === undefined) {
throw new Error(
@ -119,4 +126,10 @@ export class WorkadventurePlayerCommands extends IframeApiContribution<Workadven
}
}
//TODO: move or delete
type Position = {
x: number;
y: number;
};
export default new WorkadventurePlayerCommands();

View File

@ -1360,6 +1360,14 @@ ${escapedMessage}
this.CurrentPlayer.removeOutlineColor();
this.connection?.emitPlayerOutlineColor(null);
});
iframeListener.registerAnswerer("getPlayerPosition", () => {
return {
x: this.CurrentPlayer.x,
y: this.CurrentPlayer.y,
};
});
}
private setPropertyLayer(