2020-02-15 14:59:27 +00:00
|
|
|
var mongo = require("./mongoHelp.js")
|
2020-02-16 22:59:33 +00:00
|
|
|
const uuidv4 = require('uuid/v4')
|
|
|
|
const game = require("./game.js")
|
2020-02-15 14:59:27 +00:00
|
|
|
|
2020-02-16 22:59:33 +00:00
|
|
|
var lobby = {
|
2020-02-15 23:22:09 +00:00
|
|
|
list: async () => {
|
2020-02-16 22:59:33 +00:00
|
|
|
result = await mongo.get("embezzle", "gamelist", {})
|
|
|
|
pubArr = []
|
|
|
|
result.forEach(element => {
|
|
|
|
if (element.status == "lobby") {
|
|
|
|
obj = {
|
|
|
|
gameID: element.gameID,
|
|
|
|
name: element.name,
|
|
|
|
seats: element.seats,
|
|
|
|
players: element.players,
|
|
|
|
}
|
|
|
|
pubArr.push(obj)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
return (pubArr)
|
2020-02-15 14:59:27 +00:00
|
|
|
},
|
2020-02-16 22:59:33 +00:00
|
|
|
details: async (search) => {
|
|
|
|
result = await mongo.get("embezzle", "gamelist", {
|
|
|
|
gameID: search
|
|
|
|
})
|
|
|
|
pubArr = []
|
|
|
|
result.forEach(element => {
|
|
|
|
if (element.status == "lobby") {
|
|
|
|
obj = {
|
|
|
|
gameID: element.gameID,
|
|
|
|
name: element.name,
|
|
|
|
seats: element.seats,
|
|
|
|
players: element.players,
|
|
|
|
}
|
|
|
|
pubArr.push(obj)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
return (pubArr)
|
2020-02-15 14:59:27 +00:00
|
|
|
},
|
|
|
|
register: (name) => {
|
2020-02-16 22:59:33 +00:00
|
|
|
id = uuidv4()
|
|
|
|
mongo.put("embezzle", "players", {
|
|
|
|
_id: id,
|
|
|
|
name: name
|
|
|
|
})
|
|
|
|
return ({
|
|
|
|
ownerID: id
|
|
|
|
})
|
2020-02-15 14:59:27 +00:00
|
|
|
},
|
2020-02-16 22:59:33 +00:00
|
|
|
make: async (ownerID, seats) => {
|
|
|
|
gameID = uuidv4()
|
2020-02-15 23:22:09 +00:00
|
|
|
//todo write charity name generator
|
2020-02-16 22:59:33 +00:00
|
|
|
name = await mongo.get("embezzle", "players", {
|
|
|
|
"_id": ownerID
|
|
|
|
})
|
|
|
|
name = name[0].name
|
|
|
|
mongo.put("embezzle", "gamelist", {
|
|
|
|
gameID: gameID,
|
|
|
|
ownerID: ownerID,
|
|
|
|
name: name,
|
|
|
|
seats: seats,
|
|
|
|
status: "lobby",
|
|
|
|
players: []
|
|
|
|
})
|
|
|
|
lobby.join(ownerID, gameID)
|
|
|
|
return ({
|
|
|
|
gameID: gameID
|
|
|
|
})
|
|
|
|
// return({gameID:gameID})
|
2020-02-15 23:22:09 +00:00
|
|
|
},
|
2020-02-16 22:59:33 +00:00
|
|
|
join: async (ownerID, gameID) => {
|
|
|
|
value = await mongo.get("embezzle", "gamelist", {
|
|
|
|
"gameID": gameID
|
|
|
|
})
|
|
|
|
gameObj = value[0]
|
|
|
|
player = await mongo.get("embezzle", "players", {
|
|
|
|
"_id": ownerID
|
|
|
|
})
|
|
|
|
player=player[0]
|
|
|
|
playerObj = {
|
|
|
|
name: player.name
|
|
|
|
}
|
|
|
|
|
|
|
|
gameObj.players.push(playerObj)
|
|
|
|
mongo.update("embezzle", "gamelist", {
|
|
|
|
"gameID": gameID
|
|
|
|
}, gameObj)
|
|
|
|
return ({
|
|
|
|
gameID: gameID
|
2020-02-15 23:22:09 +00:00
|
|
|
})
|
2020-02-15 14:59:27 +00:00
|
|
|
},
|
|
|
|
start: (ownerID, gameID) => {
|
2020-02-16 22:59:33 +00:00
|
|
|
mongo.get("embezzle", "gamelist", {
|
|
|
|
"ownerID": ownerID,
|
|
|
|
"gameID": gameID
|
|
|
|
}).then(value => {
|
|
|
|
value[0].status = "playing"
|
|
|
|
mongo.update("embezzle", "gamelist", {
|
|
|
|
"gameID": gameID,
|
|
|
|
"ownerID": ownerID
|
|
|
|
}, value[0])
|
|
|
|
game.init(gameID)
|
|
|
|
})
|
|
|
|
|
|
|
|
return ({
|
|
|
|
gameID: gameID
|
2020-02-15 23:22:09 +00:00
|
|
|
})
|
2020-02-15 14:59:27 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = lobby
|