Add new roomMod.js for roomGeneration, etc.

develop
Nathan Steel 1 year ago
parent 9147a1569a
commit 2da3a75986

@ -159,7 +159,7 @@ function getCardColourRequirement(){
// using last example // using last example
// TODO: When this is functionally working, need to split up into other func/modules // TODO: When this is functionally working, need to split up into other func/modules
// such as: playerMod, cardMod, deckMod, miscMod ? // such as: playerMod, cardMod, deckMod, miscMod ?
function requestDeck(socket, playerId, deckId){ function requestDeck(itemData = null){
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
(async () => { (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 // So creating as a test for a 'room' to see if it's simple enough to
// send and play with // send and play with
// BUILD THE DATA TO SEND TO CLIENTS! (Kinda) // BUILD THE DATA TO SEND TO CLIENTS! (Kinda)
// To continue from previous item/itemCount from other funcs, something like this
let item = []; 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 deckData = {}; // New but may be useful
let deckIn = {}; // Which deck the item is in? Kinda the player/boardelement thing? let deckIn = {}; // Which deck the item is in? Kinda the player/boardelement thing?
let cardData = {}; let cardData = {};

@ -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
};

@ -2,6 +2,7 @@
const express = require('express'); const express = require('express');
const database = require('./database'); const database = require('./database');
const cardGen = require('./cardGen'); const cardGen = require('./cardGen');
const roomMod = require('./roomMod');
const app = express(); const app = express();
const http = require('http').Server(app); const http = require('http').Server(app);
const port = process.env.PORT || 3000; const port = process.env.PORT || 3000;
@ -41,6 +42,7 @@ for (let roomId = 1; roomId <= numRoomsToPreGen; roomId++) {
} }
// For testing to see console logs // For testing to see console logs
roomMod.roomGeneration(2);
//cardGen.requestDeck(); //cardGen.requestDeck();
function requestStartGame(socket){ function requestStartGame(socket){

Loading…
Cancel
Save