66 lines
2.1 KiB
JavaScript
66 lines
2.1 KiB
JavaScript
|
|
const PLAYER_LIST = [
|
|
{id: 0, name: "Groupe", wealth: [0,0,0,0], debt: 0},
|
|
{id: 1, name: "Lomion", wealth: [0,0,0,0], debt: 0},
|
|
{id: 4, name: "Oilosse", wealth: [0,0,0,0], debt: 0},
|
|
{id: 3, name: "Fefi", wealth: [0,0,0,0], debt: 0},
|
|
];
|
|
|
|
const fetchPlayerList = function () {
|
|
|
|
};
|
|
|
|
const fetchRequests = function () {
|
|
|
|
};
|
|
|
|
export const AppStorage = {
|
|
debug: true,
|
|
state: {
|
|
player_id: 0,
|
|
player_list: [],
|
|
show_player_chest: false,
|
|
requests: {},
|
|
},
|
|
// Initiate the state
|
|
initStorage (playerId) {
|
|
if (this.debug) console.log('Initiate with player : ', playerId)
|
|
this.state.player_id = playerId;
|
|
for (var idx in PLAYER_LIST) {
|
|
var player = PLAYER_LIST[idx];
|
|
this.state.player_list.push(player);
|
|
this.state.requests[player.id] = [];
|
|
}
|
|
},
|
|
// Player actions
|
|
// Sets a new active player by id
|
|
setActivePlayer (newPlayerId) {
|
|
if (this.debug) console.log('setActivePlayer to ', newPlayerId)
|
|
this.state.player_id = newPlayerId
|
|
document.cookie = `player_id=${newPlayerId};`;
|
|
},
|
|
// Show/Hide player's chest
|
|
switchPlayerChestVisibility () {
|
|
if (this.debug) console.log('switchPlayerChestVisibility', !this.state.show_player_chest)
|
|
this.state.show_player_chest = !this.state.show_player_chest
|
|
},
|
|
// Put a claim on an item from group chest.
|
|
putRequest (itemId) {
|
|
const playerId = this.state.player_id
|
|
if (this.debug) console.log('newRequest from', playerId, 'on', itemId)
|
|
this.state.requests[playerId].push(itemId);
|
|
},
|
|
// Withdraws a claim.
|
|
cancelRequest(itemId) {
|
|
const playerId = this.state.player_id
|
|
if (this.debug) console.log('cancelRequest of', playerId, 'on', itemId)
|
|
var idx = this.state.requests[playerId].indexOf(itemId);
|
|
if (idx > -1) {
|
|
this.state.requests[playerId].splice(idx, 1);
|
|
} else {
|
|
if (this.debug) console.log("cancel a non-existent request")
|
|
}
|
|
}
|
|
}
|
|
|