better game overview, start/finish time

This commit is contained in:
Zutatensuppe 2020-12-06 21:55:23 +01:00
parent af5364155f
commit 69ab049f50
7 changed files with 142 additions and 27 deletions

View file

@ -12,17 +12,19 @@ async function createGame(gameId, targetTiles, image) {
})
}
const DATA_DIR = './../data'
function loadAllGames() {
const files = fs.readdirSync('./../data/')
const files = fs.readdirSync(DATA_DIR)
for (const f of files) {
if (!f.match(/\.json$/)) {
continue
}
const gameId = f.replace(/\.json$/, '')
const contents = fs.readFileSync(`./../data/${f}`, 'utf-8')
const file = `${DATA_DIR}/${f}`
const contents = fs.readFileSync(file, 'utf-8')
const game = JSON.parse(contents)
GameCommon.newGame({
id: gameId,
id: game.id,
puzzle: game.puzzle,
players: game.players,
sockets: [],
@ -33,7 +35,7 @@ function loadAllGames() {
function persistAll() {
for (const game of GameCommon.getAllGames()) {
fs.writeFileSync('./../data/' + game.id + '.json', JSON.stringify({
fs.writeFileSync(`${DATA_DIR}/${game.id}.json`, JSON.stringify({
id: game.id,
puzzle: game.puzzle,
players: game.players,

View file

@ -101,6 +101,8 @@ async function createPuzzle(targetTiles, image) {
// TODO: maybe calculate this each time?
maxZ: 0, // max z of all pieces
maxGroup: 0, // max group of all pieces
started: Util.timestamp(), // start timestamp
finished: 0, // finish timestamp
},
// static puzzle information. stays same for complete duration of
// the game

View file

@ -78,6 +78,8 @@ app.use('/', async (req, res, next) => {
const games = [
...Game.getAllGames().map(game => ({
id: game.id,
started: game.puzzle.data.started,
finished: game.puzzle.data.finished,
tilesFinished: Game.getFinishedTileCount(game.id),
tilesTotal: Game.getTileCount(game.id),
players: Game.getActivePlayers(game.id).length,