Add WA.player.language in the API

This commit is contained in:
Nolway 2021-12-09 01:31:18 +01:00 committed by Alexis Faizeau
parent 77f8426788
commit 8286cdd41d
5 changed files with 31 additions and 2 deletions

View file

@ -13,6 +13,12 @@ export const setPlayerName = (name: string) => {
playerName = name;
};
let playerLanguage: string | undefined;
export const setPlayerLanguage = (language: string | undefined) => {
playerLanguage = language;
};
let tags: string[] | undefined;
export const setTags = (_tags: string[]) => {
@ -61,6 +67,15 @@ export class WorkadventurePlayerCommands extends IframeApiContribution<Workadven
return playerName;
}
get language(): string {
if (playerLanguage === undefined) {
throw new Error(
"Player language not initialized yet. You should call WA.player.language within a WA.onInit callback."
);
}
return playerLanguage;
}
get tags(): string[] {
if (tags === undefined) {
throw new Error("Tags not initialized yet. You should call WA.player.tags within a WA.onInit callback.");