Uses the current player position rather than the starting one to position iframe
This commit is contained in:
parent
c5f96a76ad
commit
a22c2a09b8
@ -29,6 +29,7 @@ import { isMessageReferenceEvent, isTriggerActionMessageEvent } from "./ui/Trigg
|
||||
import type { MenuRegisterEvent, UnregisterMenuEvent } from "./ui/MenuRegisterEvent";
|
||||
import type { ChangeLayerEvent } from "./ChangeLayerEvent";
|
||||
import { isPlayerPropertyEvent } from "./PlayerPropertyEvent";
|
||||
import { isPlayerPosition } from "./PlayerPosition";
|
||||
|
||||
export interface TypedMessageEvent<T> extends MessageEvent {
|
||||
data: T;
|
||||
@ -150,6 +151,10 @@ export const iframeQueryMapTypeGuards = {
|
||||
query: isCreateEmbeddedWebsiteEvent,
|
||||
answer: tg.isUndefined,
|
||||
},
|
||||
getPlayerPosition: {
|
||||
query: tg.isUndefined,
|
||||
answer: isPlayerPosition,
|
||||
},
|
||||
};
|
||||
|
||||
type GuardedType<T> = T extends (x: unknown) => x is infer T ? T : never;
|
||||
|
10
front/src/Api/Events/PlayerPosition.ts
Normal file
10
front/src/Api/Events/PlayerPosition.ts
Normal 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>;
|
@ -70,6 +70,20 @@ export class WorkadventurePlayerCommands extends IframeApiContribution<Workadven
|
||||
}
|
||||
return uuid;
|
||||
}
|
||||
|
||||
async getPosition(): Promise<Position> {
|
||||
//TODO: type
|
||||
return await queryWorkadventure({
|
||||
type: "getPlayerPosition",
|
||||
data: undefined,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
//TODO: move or delete
|
||||
type Position = {
|
||||
x: number;
|
||||
y: number;
|
||||
};
|
||||
|
||||
export default new WorkadventurePlayerCommands();
|
||||
|
@ -1274,6 +1274,14 @@ ${escapedMessage}
|
||||
iframeListener.registerAnswerer("removeActionMessage", (message) => {
|
||||
layoutManagerActionStore.removeAction(message.uuid);
|
||||
});
|
||||
|
||||
|
||||
iframeListener.registerAnswerer("getPlayerPosition", () => {
|
||||
return {
|
||||
x: this.CurrentPlayer.x,
|
||||
y: this.CurrentPlayer.y,
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
private setPropertyLayer(
|
||||
|
Loading…
Reference in New Issue
Block a user