Migrating WA.player.getCurrentUser and WA.room.getCurrentRoom to direct property access and WA.room.getMap
This commit is contained in:
parent
ea1460abaf
commit
62a4814961
11 changed files with 220 additions and 159 deletions
|
@ -6,6 +6,24 @@ import { isHasPlayerMovedEvent } from "../Events/HasPlayerMovedEvent";
|
|||
|
||||
const moveStream = new Subject<HasPlayerMovedEvent>();
|
||||
|
||||
let playerName: string|undefined;
|
||||
|
||||
export const setPlayerName = (name: string) => {
|
||||
playerName = name;
|
||||
}
|
||||
|
||||
let tags: string[]|undefined;
|
||||
|
||||
export const setTags = (_tags: string[]) => {
|
||||
tags = _tags;
|
||||
}
|
||||
|
||||
let uuid: string|undefined;
|
||||
|
||||
export const setUuid = (_uuid: string|undefined) => {
|
||||
uuid = _uuid;
|
||||
}
|
||||
|
||||
export class WorkadventurePlayerCommands extends IframeApiContribution<WorkadventurePlayerCommands> {
|
||||
callbacks = [
|
||||
apiCallback({
|
||||
|
@ -24,6 +42,29 @@ export class WorkadventurePlayerCommands extends IframeApiContribution<Workadven
|
|||
data: null,
|
||||
});
|
||||
}
|
||||
|
||||
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.');
|
||||
}
|
||||
return playerName;
|
||||
}
|
||||
|
||||
get tags() : string[] {
|
||||
if (tags === undefined) {
|
||||
throw new Error('Tags not initialized yet. You should call WA.player.tags within a WA.onInit callback.');
|
||||
}
|
||||
return tags;
|
||||
}
|
||||
|
||||
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.');
|
||||
}
|
||||
return uuid;
|
||||
}
|
||||
}
|
||||
|
||||
export default new WorkadventurePlayerCommands();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue