Add 'playerData' with socketId to roomMod

develop^2
Nathan Steel 1 year ago
parent 525e55a092
commit 16e307c32c

@ -7,6 +7,10 @@ const component = {
//item : [],
//itemCount : 0,
roomId : null,
turn : 0,
playerTurn : 0,
// Card Stuff
cardData : {},
cardFace : {},

@ -182,3 +182,8 @@ socket.on('responseStartGame', function (data) {
loadBoard(data.message);
});
socket.on('alert', function (data) {
console.log('<< alert');
alert(data.message);
});

@ -36,21 +36,37 @@ function setTeams(){
}
function roomGeneration(playerCount, teamCount = null, playerTeams = null){
function roomGeneration(roomId){
return new Promise((resolve, reject) => {
(async () => {
// Player's sockets
console.log('--- Room for generation ---');
console.log(io.sockets.adapter.rooms.get(roomId));
let itemData = startItemCount();
// This will be passed by the joinRoom for each player, then built
// on startGame)
// Need to make it work if they're the same deck too
let playerData = [
{'playerId': 1, 'deck':{'playerId':1,'deckId':1}},
{'playerId': 2, 'deck':{'playerId':2,'deckId':1}},
];
// Player data with Sockets
let playerData = [];
let i = 1;
let clients = global.io.sockets.adapter.rooms.get(roomId);
for (const clientId of clients) {
const clientSocket = global.io.sockets.sockets.get(clientId);
playerData.push({
'playerId': clientSocket.playerId
,'deck':{'playerId':i,'deckId':1}
,'socketId': clientSocket.id // TODO: ONLY FOR SERVERSIDE!!!
});
i++;
}
// Add players for the room
// Test alert so that different data/emits can be sent per-player
global.io.to(playerData[0].socketId).emit('alert', {'message': 'roomMod.js test'});
// Add players for the room (seperate to playerData, currently what's used)
itemData = setPlayers(playerData, itemData);
// TODO: Get their selected decks
@ -61,8 +77,11 @@ function roomGeneration(playerCount, teamCount = null, playerTeams = null){
// Generate the decks, and card within the deck cardLists
[itemData] = await Promise.all([ cardGen.requestDeck(itemData) ]);
//console.log('deckData');
//console.log(deckData);
// Some room stuff, likely change this
itemData.roomId = roomId;
itemData.turn = 0; // The turn count of the match
itemData.playersTurn = 0; // This means it's playerData[0] turn
return resolve(itemData);
})()
});

@ -7,7 +7,7 @@ let roomData = {};
// Variables for server overall
let numRooms = 0;
const maxRooms = 3;
const maxPlayersPerRoom = 1;
const maxPlayersPerRoom = 2;
const maxSpectatorsPerRoom = 0;
function requestRooms(socket, filter){

Loading…
Cancel
Save