2022-10-12 19:55:22 +02:00
|
|
|
// Local storage element identifiers
|
|
|
|
const localStorageTokenId = "token";
|
|
|
|
const localStoragePlayerName = "name";
|
2022-10-13 09:13:16 +02:00
|
|
|
const localStorageTableId = "table";
|
2022-10-12 19:55:22 +02:00
|
|
|
|
|
|
|
// Can prevent loading of session token, to allow multiple players per browser
|
|
|
|
const debugMode = false
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Store the player name and session token in local storage.
|
|
|
|
* Parameter name: The user name of the player
|
|
|
|
* Parameter token: The session token for the player session
|
|
|
|
*/
|
|
|
|
function storePlayerNameAndToken(name, token) {
|
2022-10-13 09:13:16 +02:00
|
|
|
storePlayerName(name);
|
|
|
|
storeSessionToken(token);
|
|
|
|
}
|
|
|
|
|
|
|
|
function storePlayerName(name) {
|
2022-10-12 19:55:22 +02:00
|
|
|
localStorage.setItem(localStoragePlayerName, name);
|
2022-10-13 09:13:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function loadPlayerName() {
|
|
|
|
return localStorage.getItem(localStoragePlayerName);
|
|
|
|
}
|
|
|
|
|
|
|
|
function deletePlayerName() {
|
|
|
|
localStorage.removeItem(localStoragePlayerName);
|
2022-10-12 19:55:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Get the last session token from local storage.
|
|
|
|
*/
|
|
|
|
function loadSessionToken() {
|
|
|
|
return localStorage.getItem(localStorageTokenId)
|
|
|
|
}
|
|
|
|
|
|
|
|
function storeSessionToken(token) {
|
|
|
|
localStorage.setItem(localStorageTokenId, token)
|
|
|
|
}
|
|
|
|
|
|
|
|
function deleteSessionToken() {
|
2022-10-13 09:13:16 +02:00
|
|
|
localStorage.removeItem(localStorageTokenId);
|
|
|
|
}
|
|
|
|
|
|
|
|
function storeTableId(table) {
|
|
|
|
localStorage.setItem(localStorageTableId, table);
|
|
|
|
}
|
|
|
|
|
|
|
|
function getTableId() {
|
|
|
|
return localStorage.getItem(localStorageTableId);
|
|
|
|
}
|
|
|
|
|
|
|
|
function deleteTableId() {
|
|
|
|
localStorage.removeItem(localStorageTableId);
|
2022-10-12 19:55:22 +02:00
|
|
|
}
|