You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
cardGame/roomMod.js

76 lines
1.9 KiB
JavaScript

// Build a room, fill will players, etc.
const cardGen = require('./cardGen');
const components = require('./components');
// Room should, setPlayers, add them to correct team (TODO), build their decks, and first shuffle
function startItemCount(){
let item = [];
let itemCount = 0;
returns = {'item': item, 'itemCount': itemCount};
return(returns);
}
function setPlayers(playerData, itemData){
itemData.player = {}; //let player = {}; // Player item belongs to
itemData.players = []; // List of the players (an associated playerItem?)
let playerNo = 0 + itemData['itemCount']; // Start loop from current itemCount
playerCount = playerData.length + itemData['itemCount']; // End at playerCount diff from itemCount
let i = 0;
for(playerNo; playerNo < playerCount; playerNo++){
itemData['players'].push([playerNo, playerData[i]]); // Add player no to array so can be looped
i++;
}
return itemData;
}
// For future, when 2v2s, and 5v1 Raids, etc.
function setTeams(){
}
function roomGeneration(playerCount, teamCount = null, playerTeams = null){
return new Promise((resolve, reject) => {
(async () => {
let itemData = startItemCount();
// This will be passed by the joinRoom for each player, then built
// on startGame)
let playerData = [
{'playerId': 1, 'deck':{'playerId':1,'deckId':1}},
{'playerId': 2, 'deck':{'playerId':2,'deckId':1}},
];
// Add players for the room
itemData = setPlayers(playerData, itemData);
// TODO: Get their selected decks
// Add all the empty components to the room itemData
itemData.component = components.component;
// Generate the decks, and card within the deck cardLists
[itemData] = await Promise.all([ cardGen.requestDeck(itemData) ]);
//console.log('deckData');
//console.log(deckData);
return resolve(itemData);
})()
});
}
module.exports = {
startItemCount
,setPlayers
,roomGeneration
};