Creates player state and uses it to get and set values from local storage
This commit is contained in:
parent
89cd292527
commit
bf69b55e99
10 changed files with 153 additions and 159 deletions
|
@ -14,24 +14,27 @@ import controls from "./Api/iframe/controls";
|
|||
import ui from "./Api/iframe/ui";
|
||||
import sound from "./Api/iframe/sound";
|
||||
import room, { setMapURL, setRoomId } from "./Api/iframe/room";
|
||||
import state, { initVariables } from "./Api/iframe/state";
|
||||
import { createState } from "./Api/iframe/state";
|
||||
import player, { setPlayerName, setTags, setUuid } from "./Api/iframe/player";
|
||||
import type { ButtonDescriptor } from "./Api/iframe/Ui/ButtonDescriptor";
|
||||
import type { Popup } from "./Api/iframe/Ui/Popup";
|
||||
import type { Sound } from "./Api/iframe/Sound/Sound";
|
||||
import { answerPromises, queryWorkadventure, sendToWorkadventure } from "./Api/iframe/IframeApiContribution";
|
||||
import { answerPromises, queryWorkadventure } from "./Api/iframe/IframeApiContribution";
|
||||
|
||||
const globalState = createState("global");
|
||||
|
||||
// Notify WorkAdventure that we are ready to receive data
|
||||
const initPromise = queryWorkadventure({
|
||||
type: "getState",
|
||||
data: undefined,
|
||||
}).then((state) => {
|
||||
setPlayerName(state.nickname);
|
||||
setRoomId(state.roomId);
|
||||
setMapURL(state.mapUrl);
|
||||
setTags(state.tags);
|
||||
setUuid(state.uuid);
|
||||
initVariables(state.variables as Map<string, unknown>);
|
||||
}).then((gameState) => {
|
||||
setPlayerName(gameState.nickname);
|
||||
setRoomId(gameState.roomId);
|
||||
setMapURL(gameState.mapUrl);
|
||||
setTags(gameState.tags);
|
||||
setUuid(gameState.uuid);
|
||||
globalState.initVariables(gameState.variables as Map<string, unknown>);
|
||||
player.state.initVariables(gameState.playerVariables as Map<string, unknown>);
|
||||
});
|
||||
|
||||
const wa = {
|
||||
|
@ -42,7 +45,7 @@ const wa = {
|
|||
sound,
|
||||
room,
|
||||
player,
|
||||
state,
|
||||
state: globalState,
|
||||
|
||||
onInit(): Promise<void> {
|
||||
return initPromise;
|
||||
|
@ -224,7 +227,5 @@ window.addEventListener(
|
|||
callback?.callback(payloadData);
|
||||
}
|
||||
}
|
||||
|
||||
// ...
|
||||
}
|
||||
);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue