add different score modes
This commit is contained in:
parent
90590d334e
commit
abf6e6aa02
6 changed files with 101 additions and 30 deletions
|
|
@ -48,12 +48,13 @@ function loadGame(gameId) {
|
|||
},
|
||||
puzzle: game.puzzle,
|
||||
players: game.players,
|
||||
evtInfos: {}
|
||||
evtInfos: {},
|
||||
scoreMode: game.scoreMode || GameCommon.SCORE_MODE_FINAL,
|
||||
})
|
||||
}
|
||||
|
||||
const changedGames = {}
|
||||
async function createGameObject(gameId, targetTiles, image, ts) {
|
||||
async function createGameObject(gameId, targetTiles, image, ts, scoreMode) {
|
||||
const seed = Util.hash(gameId + ' ' + ts)
|
||||
const rng = new Rng(seed)
|
||||
return GameCommon.__createGameObject(
|
||||
|
|
@ -64,12 +65,13 @@ async function createGameObject(gameId, targetTiles, image, ts) {
|
|||
},
|
||||
await createPuzzle(rng, targetTiles, image, ts),
|
||||
[],
|
||||
{}
|
||||
{},
|
||||
scoreMode
|
||||
)
|
||||
}
|
||||
async function createGame(gameId, targetTiles, image, ts) {
|
||||
async function createGame(gameId, targetTiles, image, ts, scoreMode) {
|
||||
GameLog.create(gameId)
|
||||
GameLog.log(gameId, Protocol.LOG_HEADER, 1, targetTiles, image, ts)
|
||||
GameLog.log(gameId, Protocol.LOG_HEADER, 1, targetTiles, image, ts, scoreMode)
|
||||
|
||||
const seed = Util.hash(gameId + ' ' + ts)
|
||||
const rng = new Rng(seed)
|
||||
|
|
@ -82,6 +84,7 @@ async function createGame(gameId, targetTiles, image, ts) {
|
|||
puzzle: await createPuzzle(rng, targetTiles, image, ts),
|
||||
players: [],
|
||||
evtInfos: {},
|
||||
scoreMode,
|
||||
})
|
||||
|
||||
changedGames[gameId] = true
|
||||
|
|
@ -130,6 +133,7 @@ function persistGame(gameId) {
|
|||
},
|
||||
puzzle: game.puzzle,
|
||||
players: game.players,
|
||||
scoreMode: game.scoreMode,
|
||||
}))
|
||||
log.info(`[INFO] persisted game ${game.id}`)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ import {
|
|||
GAME_DIR,
|
||||
TEMPLATE_DIR,
|
||||
} from './Dirs.js'
|
||||
import GameCommon from '../common/GameCommon.js'
|
||||
|
||||
const log = logger('index.js')
|
||||
|
||||
|
|
@ -85,7 +86,13 @@ app.post('/newgame', bodyParser.json(), async (req, res) => {
|
|||
const gameId = Util.uniqId()
|
||||
if (!Game.exists(gameId)) {
|
||||
const ts = Time.timestamp()
|
||||
await Game.createGame(gameId, req.body.tiles, req.body.image, ts)
|
||||
await Game.createGame(
|
||||
gameId,
|
||||
req.body.tiles,
|
||||
req.body.image,
|
||||
ts,
|
||||
req.body.scoreMode
|
||||
)
|
||||
}
|
||||
res.send({ url: `/g/${gameId}` })
|
||||
})
|
||||
|
|
@ -151,11 +158,12 @@ wss.on('message', async ({socket, data}) => {
|
|||
throw `[gamelog ${gameId} does not exist... ]`
|
||||
}
|
||||
const log = GameLog.get(gameId)
|
||||
let game = await Game.createGameObject(
|
||||
const game = await Game.createGameObject(
|
||||
gameId,
|
||||
log[0][2],
|
||||
log[0][3],
|
||||
log[0][4]
|
||||
log[0][4],
|
||||
log[0][5] || GameCommon.SCORE_MODE_FINAL
|
||||
)
|
||||
notify(
|
||||
[Protocol.EV_SERVER_INIT_REPLAY, Util.encodeGame(game), log],
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue