Merge branch 'develop' of github.com:thecodingmachine/workadventure into scripting_api_room_metadata
This commit is contained in:
commit
5c7ea7b258
66 changed files with 1296 additions and 967 deletions
|
@ -2,27 +2,34 @@ import { IframeApiContribution, sendToWorkadventure } from "./IframeApiContribut
|
|||
import type { HasPlayerMovedEvent, HasPlayerMovedEventCallback } from "../Events/HasPlayerMovedEvent";
|
||||
import { Subject } from "rxjs";
|
||||
import { apiCallback } from "./registeredCallbacks";
|
||||
import { getGameState } from "./room";
|
||||
import { isHasPlayerMovedEvent } from "../Events/HasPlayerMovedEvent";
|
||||
|
||||
interface User {
|
||||
id: string | undefined;
|
||||
nickName: string | null;
|
||||
tags: string[];
|
||||
}
|
||||
|
||||
const moveStream = new Subject<HasPlayerMovedEvent>();
|
||||
|
||||
let playerName: string|undefined;
|
||||
let playerName: string | undefined;
|
||||
|
||||
export const setPlayerName = (name: string) => {
|
||||
playerName = name;
|
||||
}
|
||||
};
|
||||
|
||||
let tags: string[]|undefined;
|
||||
let tags: string[] | undefined;
|
||||
|
||||
export const setTags = (_tags: string[]) => {
|
||||
tags = _tags;
|
||||
}
|
||||
};
|
||||
|
||||
let uuid: string|undefined;
|
||||
let uuid: string | undefined;
|
||||
|
||||
export const setUuid = (_uuid: string|undefined) => {
|
||||
export const setUuid = (_uuid: string | undefined) => {
|
||||
uuid = _uuid;
|
||||
}
|
||||
};
|
||||
|
||||
export class WorkadventurePlayerCommands extends IframeApiContribution<WorkadventurePlayerCommands> {
|
||||
callbacks = [
|
||||
|
@ -43,25 +50,27 @@ export class WorkadventurePlayerCommands extends IframeApiContribution<Workadven
|
|||
});
|
||||
}
|
||||
|
||||
get name() : string {
|
||||
get name(): string {
|
||||
if (playerName === undefined) {
|
||||
throw new Error('Player name not initialized yet. You should call WA.player.name within a WA.onInit callback.');
|
||||
throw new Error(
|
||||
"Player name not initialized yet. You should call WA.player.name within a WA.onInit callback."
|
||||
);
|
||||
}
|
||||
return playerName;
|
||||
}
|
||||
|
||||
get tags() : string[] {
|
||||
get tags(): string[] {
|
||||
if (tags === undefined) {
|
||||
throw new Error('Tags not initialized yet. You should call WA.player.tags within a WA.onInit callback.');
|
||||
throw new Error("Tags not initialized yet. You should call WA.player.tags within a WA.onInit callback.");
|
||||
}
|
||||
return tags;
|
||||
}
|
||||
|
||||
get id() : string|undefined {
|
||||
get id(): string | undefined {
|
||||
// Note: this is not a type, we are checking if playerName is undefined because playerName cannot be undefined
|
||||
// while uuid could.
|
||||
if (playerName === undefined) {
|
||||
throw new Error('Player id not initialized yet. You should call WA.player.id within a WA.onInit callback.');
|
||||
throw new Error("Player id not initialized yet. You should call WA.player.id within a WA.onInit callback.");
|
||||
}
|
||||
return uuid;
|
||||
}
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
import {Observable, Subject} from "rxjs";
|
||||
import { Observable, Subject } from "rxjs";
|
||||
|
||||
import { EnterLeaveEvent, isEnterLeaveEvent } from "../Events/EnterLeaveEvent";
|
||||
|
||||
import {IframeApiContribution, queryWorkadventure, sendToWorkadventure} from "./IframeApiContribution";
|
||||
import { IframeApiContribution, queryWorkadventure, sendToWorkadventure } from "./IframeApiContribution";
|
||||
import { apiCallback } from "./registeredCallbacks";
|
||||
|
||||
import type { ITiledMap } from "../../Phaser/Map/ITiledMap";
|
||||
|
@ -13,21 +13,21 @@ const leaveStreams: Map<string, Subject<EnterLeaveEvent>> = new Map<string, Subj
|
|||
interface TileDescriptor {
|
||||
x: number;
|
||||
y: number;
|
||||
tile: number | string;
|
||||
tile: number | string | null;
|
||||
layer: string;
|
||||
}
|
||||
|
||||
let roomId: string|undefined;
|
||||
let roomId: string | undefined;
|
||||
|
||||
export const setRoomId = (id: string) => {
|
||||
roomId = id;
|
||||
}
|
||||
};
|
||||
|
||||
let mapURL: string|undefined;
|
||||
let mapURL: string | undefined;
|
||||
|
||||
export const setMapURL = (url: string) => {
|
||||
mapURL = url;
|
||||
}
|
||||
};
|
||||
|
||||
export class WorkadventureRoomCommands extends IframeApiContribution<WorkadventureRoomCommands> {
|
||||
callbacks = [
|
||||
|
@ -90,16 +90,18 @@ export class WorkadventureRoomCommands extends IframeApiContribution<Workadventu
|
|||
});
|
||||
}
|
||||
|
||||
get id() : string {
|
||||
get id(): string {
|
||||
if (roomId === undefined) {
|
||||
throw new Error('Room id not initialized yet. You should call WA.room.id within a WA.onInit callback.');
|
||||
throw new Error("Room id not initialized yet. You should call WA.room.id within a WA.onInit callback.");
|
||||
}
|
||||
return roomId;
|
||||
}
|
||||
|
||||
get mapURL() : string {
|
||||
get mapURL(): string {
|
||||
if (mapURL === undefined) {
|
||||
throw new Error('mapURL is not initialized yet. You should call WA.room.mapURL within a WA.onInit callback.');
|
||||
throw new Error(
|
||||
"mapURL is not initialized yet. You should call WA.room.mapURL within a WA.onInit callback."
|
||||
);
|
||||
}
|
||||
return mapURL;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue