summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorsyuilo <syuilotan@yahoo.co.jp>2018-03-28 13:32:05 +0900
committersyuilo <syuilotan@yahoo.co.jp>2018-03-28 13:32:05 +0900
commit69cef75b53671ccd7e0a199d31fa2d6d7c91fe78 (patch)
tree80441ef9023587db260b6db726e6c833f43e02b8 /src
parentwip (diff)
downloadsharkey-69cef75b53671ccd7e0a199d31fa2d6d7c91fe78.tar.gz
sharkey-69cef75b53671ccd7e0a199d31fa2d6d7c91fe78.tar.bz2
sharkey-69cef75b53671ccd7e0a199d31fa2d6d7c91fe78.zip
wip
Diffstat (limited to 'src')
-rw-r--r--src/api/endpoints/othello/games.ts4
-rw-r--r--src/api/endpoints/othello/games/show.ts4
-rw-r--r--src/api/endpoints/othello/match.ts4
-rw-r--r--src/api/models/othello-game.ts34
-rw-r--r--src/api/stream/othello-game.ts32
5 files changed, 39 insertions, 39 deletions
diff --git a/src/api/endpoints/othello/games.ts b/src/api/endpoints/othello/games.ts
index 2a6bbb4043..f6e38b8d87 100644
--- a/src/api/endpoints/othello/games.ts
+++ b/src/api/endpoints/othello/games.ts
@@ -1,5 +1,5 @@
import $ from 'cafy';
-import Game, { pack } from '../../models/othello-game';
+import OthelloGame, { pack } from '../../models/othello-game';
module.exports = (params, user) => new Promise(async (res, rej) => {
// Get 'my' parameter
@@ -50,7 +50,7 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
}
// Fetch games
- const games = await Game.find(q, {
+ const games = await OthelloGame.find(q, {
sort,
limit
});
diff --git a/src/api/endpoints/othello/games/show.ts b/src/api/endpoints/othello/games/show.ts
index 2b0db4dd00..c7bd74a39a 100644
--- a/src/api/endpoints/othello/games/show.ts
+++ b/src/api/endpoints/othello/games/show.ts
@@ -1,5 +1,5 @@
import $ from 'cafy';
-import Game, { pack } from '../../../models/othello-game';
+import OthelloGame, { pack } from '../../../models/othello-game';
import Othello from '../../../../common/othello/core';
module.exports = (params, user) => new Promise(async (res, rej) => {
@@ -7,7 +7,7 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
const [gameId, gameIdErr] = $(params.game_id).id().$;
if (gameIdErr) return rej('invalid game_id param');
- const game = await Game.findOne({ _id: gameId });
+ const game = await OthelloGame.findOne({ _id: gameId });
if (game == null) {
return rej('game not found');
diff --git a/src/api/endpoints/othello/match.ts b/src/api/endpoints/othello/match.ts
index b73e105ef0..f73386ba7c 100644
--- a/src/api/endpoints/othello/match.ts
+++ b/src/api/endpoints/othello/match.ts
@@ -1,6 +1,6 @@
import $ from 'cafy';
import Matching, { pack as packMatching } from '../../models/othello-matching';
-import Game, { pack as packGame } from '../../models/othello-game';
+import OthelloGame, { pack as packGame } from '../../models/othello-game';
import User from '../../models/user';
import publishUserStream, { publishOthelloStream } from '../../event';
import { eighteight } from '../../../common/othello/maps';
@@ -28,7 +28,7 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
});
// Create game
- const game = await Game.insert({
+ const game = await OthelloGame.insert({
created_at: new Date(),
user1_id: exist.parent_id,
user2_id: user._id,
diff --git a/src/api/models/othello-game.ts b/src/api/models/othello-game.ts
index 01c6ca6c00..b9e57632d4 100644
--- a/src/api/models/othello-game.ts
+++ b/src/api/models/othello-game.ts
@@ -3,17 +3,17 @@ import deepcopy = require('deepcopy');
import db from '../../db/mongodb';
import { IUser, pack as packUser } from './user';
-const Game = db.get<IGame>('othello_games');
-export default Game;
+const OthelloGame = db.get<IOthelloGame>('othelloGames');
+export default OthelloGame;
-export interface IGame {
+export interface IOthelloGame {
_id: mongo.ObjectID;
- created_at: Date;
- started_at: Date;
- user1_id: mongo.ObjectID;
- user2_id: mongo.ObjectID;
- user1_accepted: boolean;
- user2_accepted: boolean;
+ createdAt: Date;
+ startedAt: Date;
+ user1Id: mongo.ObjectID;
+ user2Id: mongo.ObjectID;
+ user1Accepted: boolean;
+ user2Accepted: boolean;
/**
* どちらのプレイヤーが先行(黒)か
@@ -22,9 +22,9 @@ export interface IGame {
*/
black: number;
- is_started: boolean;
- is_ended: boolean;
- winner_id: mongo.ObjectID;
+ isStarted: boolean;
+ isEnded: boolean;
+ winnerId: mongo.ObjectID;
logs: Array<{
at: Date;
color: boolean;
@@ -33,9 +33,9 @@ export interface IGame {
settings: {
map: string[];
bw: string | number;
- is_llotheo: boolean;
- can_put_everywhere: boolean;
- looped_board: boolean;
+ isLlotheo: boolean;
+ canPutEverywhere: boolean;
+ loopedBoard: boolean;
};
form1: any;
form2: any;
@@ -62,11 +62,11 @@ export const pack = (
// Populate the game if 'game' is ID
if (mongo.ObjectID.prototype.isPrototypeOf(game)) {
- _game = await Game.findOne({
+ _game = await OthelloGame.findOne({
_id: game
});
} else if (typeof game === 'string') {
- _game = await Game.findOne({
+ _game = await OthelloGame.findOne({
_id: new mongo.ObjectID(game)
});
} else {
diff --git a/src/api/stream/othello-game.ts b/src/api/stream/othello-game.ts
index 1c846f27ae..45a931c7e7 100644
--- a/src/api/stream/othello-game.ts
+++ b/src/api/stream/othello-game.ts
@@ -1,7 +1,7 @@
import * as websocket from 'websocket';
import * as redis from 'redis';
import * as CRC32 from 'crc-32';
-import Game, { pack } from '../models/othello-game';
+import OthelloGame, { pack } from '../models/othello-game';
import { publishOthelloGameStream } from '../event';
import Othello from '../../common/othello/core';
import * as maps from '../../common/othello/maps';
@@ -60,14 +60,14 @@ export default function(request: websocket.request, connection: websocket.connec
});
async function updateSettings(settings) {
- const game = await Game.findOne({ _id: gameId });
+ const game = await OthelloGame.findOne({ _id: gameId });
if (game.is_started) return;
if (!game.user1_id.equals(user._id) && !game.user2_id.equals(user._id)) return;
if (game.user1_id.equals(user._id) && game.user1_accepted) return;
if (game.user2_id.equals(user._id) && game.user2_accepted) return;
- await Game.update({ _id: gameId }, {
+ await OthelloGame.update({ _id: gameId }, {
$set: {
settings
}
@@ -77,7 +77,7 @@ export default function(request: websocket.request, connection: websocket.connec
}
async function initForm(form) {
- const game = await Game.findOne({ _id: gameId });
+ const game = await OthelloGame.findOne({ _id: gameId });
if (game.is_started) return;
if (!game.user1_id.equals(user._id) && !game.user2_id.equals(user._id)) return;
@@ -88,7 +88,7 @@ export default function(request: websocket.request, connection: websocket.connec
form2: form
};
- await Game.update({ _id: gameId }, {
+ await OthelloGame.update({ _id: gameId }, {
$set: set
});
@@ -99,7 +99,7 @@ export default function(request: websocket.request, connection: websocket.connec
}
async function updateForm(id, value) {
- const game = await Game.findOne({ _id: gameId });
+ const game = await OthelloGame.findOne({ _id: gameId });
if (game.is_started) return;
if (!game.user1_id.equals(user._id) && !game.user2_id.equals(user._id)) return;
@@ -118,7 +118,7 @@ export default function(request: websocket.request, connection: websocket.connec
form1: form
};
- await Game.update({ _id: gameId }, {
+ await OthelloGame.update({ _id: gameId }, {
$set: set
});
@@ -138,14 +138,14 @@ export default function(request: websocket.request, connection: websocket.connec
}
async function accept(accept: boolean) {
- const game = await Game.findOne({ _id: gameId });
+ const game = await OthelloGame.findOne({ _id: gameId });
if (game.is_started) return;
let bothAccepted = false;
if (game.user1_id.equals(user._id)) {
- await Game.update({ _id: gameId }, {
+ await OthelloGame.update({ _id: gameId }, {
$set: {
user1_accepted: accept
}
@@ -158,7 +158,7 @@ export default function(request: websocket.request, connection: websocket.connec
if (accept && game.user2_accepted) bothAccepted = true;
} else if (game.user2_id.equals(user._id)) {
- await Game.update({ _id: gameId }, {
+ await OthelloGame.update({ _id: gameId }, {
$set: {
user2_accepted: accept
}
@@ -177,7 +177,7 @@ export default function(request: websocket.request, connection: websocket.connec
if (bothAccepted) {
// 3秒後、まだacceptされていたらゲーム開始
setTimeout(async () => {
- const freshGame = await Game.findOne({ _id: gameId });
+ const freshGame = await OthelloGame.findOne({ _id: gameId });
if (freshGame == null || freshGame.is_started || freshGame.is_ended) return;
if (!freshGame.user1_accepted || !freshGame.user2_accepted) return;
@@ -196,7 +196,7 @@ export default function(request: websocket.request, connection: websocket.connec
const map = freshGame.settings.map != null ? freshGame.settings.map : getRandomMap();
- await Game.update({ _id: gameId }, {
+ await OthelloGame.update({ _id: gameId }, {
$set: {
started_at: new Date(),
is_started: true,
@@ -222,7 +222,7 @@ export default function(request: websocket.request, connection: websocket.connec
winner = null;
}
- await Game.update({
+ await OthelloGame.update({
_id: gameId
}, {
$set: {
@@ -245,7 +245,7 @@ export default function(request: websocket.request, connection: websocket.connec
// 石を打つ
async function set(pos) {
- const game = await Game.findOne({ _id: gameId });
+ const game = await OthelloGame.findOne({ _id: gameId });
if (!game.is_started) return;
if (game.is_ended) return;
@@ -288,7 +288,7 @@ export default function(request: websocket.request, connection: websocket.connec
const crc32 = CRC32.str(game.logs.map(x => x.pos.toString()).join('') + pos.toString());
- await Game.update({
+ await OthelloGame.update({
_id: gameId
}, {
$set: {
@@ -314,7 +314,7 @@ export default function(request: websocket.request, connection: websocket.connec
}
async function check(crc32) {
- const game = await Game.findOne({ _id: gameId });
+ const game = await OthelloGame.findOne({ _id: gameId });
if (!game.is_started) return;