diff --git a/cardGen.js b/cardGen.js index 3c6468a..72a903c 100644 --- a/cardGen.js +++ b/cardGen.js @@ -159,7 +159,7 @@ function getCardColourRequirement(){ // using last example // TODO: When this is functionally working, need to split up into other func/modules // such as: playerMod, cardMod, deckMod, miscMod ? -function requestDeck(socket, playerId, deckId){ +function requestDeck(itemData = null){ return new Promise((resolve, reject) => { (async () => { @@ -221,8 +221,22 @@ function requestDeck(socket, playerId, deckId){ // So creating as a test for a 'room' to see if it's simple enough to // send and play with // BUILD THE DATA TO SEND TO CLIENTS! (Kinda) + + // To continue from previous item/itemCount from other funcs, something like this let item = []; - let itemCount = 0; // TODO: Have this continue from last function (ie. getPlayers?) + let itemCount = 0; + + // Jank check to allow current client call, and new roomMod.roomGeneration call to + // both work (will replace client call with roomGeneration when closer) + if(itemData !== null){ + if(itemData['item'] !== undefined){ + item = itemData['item']; + } + if(itemData['itemCount'] !== undefined){ + itemCount = itemData['itemCount']; + } + } + let deckData = {}; // New but may be useful let deckIn = {}; // Which deck the item is in? Kinda the player/boardelement thing? let cardData = {}; diff --git a/roomMod.js b/roomMod.js new file mode 100644 index 0000000..11a88d7 --- /dev/null +++ b/roomMod.js @@ -0,0 +1,66 @@ +// Build a room, fill will players, etc. +const cardGen = require('./cardGen'); + + +// 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(playerCount = 2, itemData){ + // Add new item attribute for 'players' + // TODO: Maybe check if exists, and add to in that case (for replacing people?) + // Doubt that would ever make it into the game, but could still be worth + itemData.player = {}; //let player = {}; + + // Can be done with just referring to itemData[x], but less readable + // Will likely redefine vars each new function. For now will keep this as-is + + let playerNo = 0 + itemData['itemCount']; // Start loop from current itemCount + playerCount = playerCount + itemData['itemCount']; // End at playerCount diff from itemCount + for(playerNo; playerNo <= playerCount; playerNo++){ + itemData['item'].push(playerNo); + itemData['player'][itemData['itemCount']] = playerNo; // The player belongs to itself + itemData['itemCount']++; + } + // Return related item and item attributes + //returns = {'item': item, 'itemCount': itemCount, 'player': player}; + return itemData; + //return([item, itemCount, player]); +} + +// 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(); + + // Create 2 players for the room + itemData = setPlayers(2, itemData); + + // TODO: Get their selected decks (will need to pass somewhere) + + // Generate the decks, and card within the deck cardLists + const [deckData] = await Promise.all([ cardGen.requestDeck(itemData) ]); + + console.log('deckData'); + console.log(deckData); + return resolve(deckData); + })() + }); +} + +module.exports = { + startItemCount + ,setPlayers + ,roomGeneration +}; + diff --git a/server.js b/server.js index 304a5cc..0adafe0 100644 --- a/server.js +++ b/server.js @@ -2,6 +2,7 @@ const express = require('express'); const database = require('./database'); const cardGen = require('./cardGen'); +const roomMod = require('./roomMod'); const app = express(); const http = require('http').Server(app); const port = process.env.PORT || 3000; @@ -41,6 +42,7 @@ for (let roomId = 1; roomId <= numRoomsToPreGen; roomId++) { } // For testing to see console logs +roomMod.roomGeneration(2); //cardGen.requestDeck(); function requestStartGame(socket){