Introduce processor
This commit is contained in:
parent
68ce6d5748
commit
90f8fe7e53
582 changed files with 246 additions and 188 deletions
32
src/server/api/endpoints/othello/games/show.ts
Normal file
32
src/server/api/endpoints/othello/games/show.ts
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
import $ from 'cafy';
|
||||
import Game, { pack } from '../../../models/othello-game';
|
||||
import Othello from '../../../../common/othello/core';
|
||||
|
||||
module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||
// Get 'game_id' parameter
|
||||
const [gameId, gameIdErr] = $(params.game_id).id().$;
|
||||
if (gameIdErr) return rej('invalid game_id param');
|
||||
|
||||
const game = await Game.findOne({ _id: gameId });
|
||||
|
||||
if (game == null) {
|
||||
return rej('game not found');
|
||||
}
|
||||
|
||||
const o = new Othello(game.settings.map, {
|
||||
isLlotheo: game.settings.is_llotheo,
|
||||
canPutEverywhere: game.settings.can_put_everywhere,
|
||||
loopedBoard: game.settings.looped_board
|
||||
});
|
||||
|
||||
game.logs.forEach(log => {
|
||||
o.put(log.color, log.pos);
|
||||
});
|
||||
|
||||
const packed = await pack(game, user);
|
||||
|
||||
res(Object.assign({
|
||||
board: o.board,
|
||||
turn: o.turn
|
||||
}, packed));
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue