little fixes for moveTo example and with event return data
This commit is contained in:
parent
bf6b9a7c83
commit
b088e63290
@ -35,6 +35,7 @@ import type { CameraSetEvent } from "./CameraSetEvent";
|
||||
import type { CameraFollowPlayerEvent } from "./CameraFollowPlayerEvent";
|
||||
import { isColorEvent } from "./ColorEvent";
|
||||
import { isMovePlayerToEventConfig } from "./MovePlayerToEvent";
|
||||
import { isMovePlayerToEventAnswer } from "./MovePlayerToEventAnswer";
|
||||
|
||||
export interface TypedMessageEvent<T> extends MessageEvent {
|
||||
data: T;
|
||||
@ -176,7 +177,7 @@ export const iframeQueryMapTypeGuards = {
|
||||
},
|
||||
movePlayerTo: {
|
||||
query: isMovePlayerToEventConfig,
|
||||
answer: isPlayerPosition,
|
||||
answer: isMovePlayerToEventAnswer,
|
||||
},
|
||||
};
|
||||
|
||||
|
11
front/src/Api/Events/MovePlayerToEventAnswer.ts
Normal file
11
front/src/Api/Events/MovePlayerToEventAnswer.ts
Normal file
@ -0,0 +1,11 @@
|
||||
import * as tg from "generic-type-guard";
|
||||
|
||||
export const isMovePlayerToEventAnswer = new tg.IsInterface()
|
||||
.withProperties({
|
||||
x: tg.isNumber,
|
||||
y: tg.isNumber,
|
||||
cancelled: tg.isBoolean,
|
||||
})
|
||||
.get();
|
||||
|
||||
export type MovePlayerToEventAnswer = tg.GuardedType<typeof isMovePlayerToEventAnswer>;
|
@ -16,10 +16,19 @@
|
||||
randomChainedMovementButton.addEventListener('click', async () => {
|
||||
try {
|
||||
WA.player.moveTo(100, 100, 10).then((result) => {
|
||||
if (result.cancelled) {
|
||||
return;
|
||||
}
|
||||
console.log(result);
|
||||
WA.player.moveTo(500, 100, 20).then((result) => {
|
||||
if (result.cancelled) {
|
||||
return;
|
||||
}
|
||||
console.log(result);
|
||||
WA.player.moveTo(500, 500, 10).then((result) => {
|
||||
if (result.cancelled) {
|
||||
return;
|
||||
}
|
||||
console.log(result);
|
||||
});
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user