add replay check in overview
This commit is contained in:
parent
083fc0463c
commit
98c05304c5
4 changed files with 32 additions and 3 deletions
|
|
@ -60,6 +60,9 @@ export default {
|
||||||
{{time(g.started, g.finished)}}<br />
|
{{time(g.started, g.finished)}}<br />
|
||||||
</span>
|
</span>
|
||||||
</a>
|
</a>
|
||||||
|
<a v-if="g.hasReplay" class="game-replay" :href="'/replay/' + g.id">
|
||||||
|
↪️ Watch replay
|
||||||
|
</a>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -59,6 +59,7 @@ async function createGameObject(gameId, targetTiles, image, ts) {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
async function createGame(gameId, targetTiles, image, ts) {
|
async function createGame(gameId, targetTiles, image, ts) {
|
||||||
|
GameLog.create(gameId)
|
||||||
GameLog.log(gameId, 'createGame', targetTiles, image, ts)
|
GameLog.log(gameId, 'createGame', targetTiles, image, ts)
|
||||||
|
|
||||||
const seed = Util.hash(gameId + ' ' + ts)
|
const seed = Util.hash(gameId + ' ' + ts)
|
||||||
|
|
|
||||||
|
|
@ -2,14 +2,36 @@ import fs from 'fs'
|
||||||
|
|
||||||
const DATA_DIR = './../data'
|
const DATA_DIR = './../data'
|
||||||
|
|
||||||
|
const filename = (gameId) => `${DATA_DIR}/log_${gameId}.log`
|
||||||
|
|
||||||
|
const create = (gameId) => {
|
||||||
|
const file = filename(gameId)
|
||||||
|
if (!fs.existsSync(file)) {
|
||||||
|
fs.appendFileSync(file, '')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const exists = (gameId) => {
|
||||||
|
const file = filename(gameId)
|
||||||
|
return fs.existsSync(file)
|
||||||
|
}
|
||||||
|
|
||||||
const log = (gameId, ...args) => {
|
const log = (gameId, ...args) => {
|
||||||
|
const file = filename(gameId)
|
||||||
|
if (!fs.existsSync(file)) {
|
||||||
|
return
|
||||||
|
}
|
||||||
const str = JSON.stringify(args)
|
const str = JSON.stringify(args)
|
||||||
fs.appendFileSync(`${DATA_DIR}/log_${gameId}.log`, str + "\n")
|
fs.appendFileSync(file, str + "\n")
|
||||||
}
|
}
|
||||||
|
|
||||||
const get = (gameId) => {
|
const get = (gameId) => {
|
||||||
const all = fs.readFileSync(`${DATA_DIR}/log_${gameId}.log`, 'utf-8')
|
const file = filename(gameId)
|
||||||
return all.split("\n").filter(line => !!line).map((line) => {
|
if (!fs.existsSync(file)) {
|
||||||
|
return []
|
||||||
|
}
|
||||||
|
const lines = fs.readFileSync(file, 'utf-8').split("\n")
|
||||||
|
return lines.filter(line => !!line).map((line) => {
|
||||||
try {
|
try {
|
||||||
return JSON.parse(line)
|
return JSON.parse(line)
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|
@ -20,6 +42,8 @@ const get = (gameId) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
|
create,
|
||||||
|
exists,
|
||||||
log,
|
log,
|
||||||
get,
|
get,
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -91,6 +91,7 @@ app.use('/', async (req, res, next) => {
|
||||||
const games = [
|
const games = [
|
||||||
...Game.getAllGames().map(game => ({
|
...Game.getAllGames().map(game => ({
|
||||||
id: game.id,
|
id: game.id,
|
||||||
|
hasReplay: GameLog.exists(game.id),
|
||||||
started: Game.getStartTs(game.id),
|
started: Game.getStartTs(game.id),
|
||||||
finished: Game.getFinishTs(game.id),
|
finished: Game.getFinishTs(game.id),
|
||||||
tilesFinished: Game.getFinishedTileCount(game.id),
|
tilesFinished: Game.getFinishedTileCount(game.id),
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue