add other snap mode

This commit is contained in:
Zutatensuppe 2021-06-04 09:26:37 +02:00
parent 42aaf10679
commit 2a12900614
11 changed files with 164 additions and 27 deletions

View file

@ -1,5 +1,5 @@
import GameCommon from './../common/GameCommon'
import { Change, Game, Input, ScoreMode, ShapeMode, Timestamp } from './../common/Types'
import { Change, Game, Input, ScoreMode, ShapeMode, SnapMode, Timestamp } from './../common/Types'
import Util, { logger } from './../common/Util'
import { Rng } from './../common/Rng'
import GameLog from './GameLog'
@ -15,7 +15,8 @@ async function createGameObject(
image: PuzzleCreationImageInfo,
ts: Timestamp,
scoreMode: ScoreMode,
shapeMode: ShapeMode
shapeMode: ShapeMode,
snapMode: SnapMode
): Promise<Game> {
const seed = Util.hash(gameId + ' ' + ts)
const rng = new Rng(seed)
@ -27,6 +28,7 @@ async function createGameObject(
evtInfos: {},
scoreMode,
shapeMode,
snapMode,
}
}
@ -36,7 +38,8 @@ async function createGame(
image: PuzzleCreationImageInfo,
ts: Timestamp,
scoreMode: ScoreMode,
shapeMode: ShapeMode
shapeMode: ShapeMode,
snapMode: SnapMode
): Promise<void> {
const gameObject = await createGameObject(
gameId,
@ -44,7 +47,8 @@ async function createGame(
image,
ts,
scoreMode,
shapeMode
shapeMode,
snapMode
)
GameLog.create(gameId)
@ -56,7 +60,8 @@ async function createGame(
image,
ts,
scoreMode,
shapeMode
shapeMode,
snapMode
)
GameCommon.setGame(gameObject.id, gameObject)

View file

@ -1,6 +1,6 @@
import fs from 'fs'
import GameCommon from './../common/GameCommon'
import { Piece, ScoreMode } from './../common/Types'
import { Game, Piece, ScoreMode, ShapeMode, SnapMode } from './../common/Types'
import Util, { logger } from './../common/Util'
import { Rng } from './../common/Rng'
import { DATA_DIR } from './Dirs'
@ -49,7 +49,7 @@ function loadGame(gameId: string): void {
if (!Array.isArray(game.players)) {
game.players = Object.values(game.players)
}
const gameObject = {
const gameObject: Game = {
id: game.id,
rng: {
type: game.rng ? game.rng.type : '_fake_',
@ -59,6 +59,8 @@ function loadGame(gameId: string): void {
players: game.players,
evtInfos: {},
scoreMode: game.scoreMode || ScoreMode.FINAL,
shapeMode: game.shapeMode || ShapeMode.ANY,
snapMode: game.snapMode || SnapMode.NORMAL,
}
GameCommon.setGame(gameObject.id, gameObject)
}
@ -88,6 +90,8 @@ function persistGame(gameId: string): void {
puzzle: game.puzzle,
players: game.players,
scoreMode: game.scoreMode,
shapeMode: game.shapeMode,
snapMode: game.snapMode,
}))
log.info(`[INFO] persisted game ${game.id}`)
}

View file

@ -19,7 +19,7 @@ import {
UPLOAD_DIR,
} from './Dirs'
import GameCommon from '../common/GameCommon'
import { ServerEvent, Game as GameType, GameSettings, ScoreMode, ShapeMode } from '../common/Types'
import { ServerEvent, Game as GameType, GameSettings, ScoreMode, ShapeMode, SnapMode } from '../common/Types'
import GameStorage from './GameStorage'
import Db from './Db'
@ -90,7 +90,8 @@ app.get('/api/replay-data', async (req, res): Promise<void> => {
log[0][3],
log[0][4],
log[0][5] || ScoreMode.FINAL,
log[0][6] || ShapeMode.NORMAL
log[0][6] || ShapeMode.NORMAL,
log[0][7] || SnapMode.NORMAL,
)
}
res.send({ log, game: game ? Util.encodeGame(game) : null })
@ -203,7 +204,8 @@ app.post('/api/newgame', express.json(), async (req, res): Promise<void> => {
gameSettings.image,
ts,
gameSettings.scoreMode,
gameSettings.shapeMode
gameSettings.shapeMode,
gameSettings.snapMode,
)
}
res.send({ id: gameId })