diff --git a/src/api/endpoints.ts b/src/api/endpoints.ts index fad666711..1fc9465cd 100644 --- a/src/api/endpoints.ts +++ b/src/api/endpoints.ts @@ -253,6 +253,11 @@ const endpoints: Endpoint[] = [ withCredential: true }, + { + name: 'othello/games/show', + withCredential: true + }, + { name: 'mute/create', withCredential: true, diff --git a/src/api/endpoints/othello/games.ts b/src/api/endpoints/othello/games.ts index dd3ee523a..2a6bbb404 100644 --- a/src/api/endpoints/othello/games.ts +++ b/src/api/endpoints/othello/games.ts @@ -23,7 +23,7 @@ module.exports = (params, user) => new Promise(async (res, rej) => { return rej('cannot set since_id and until_id'); } - const q = my ? { + const q: any = my ? { is_started: true, $or: [{ user1_id: user._id @@ -34,7 +34,6 @@ module.exports = (params, user) => new Promise(async (res, rej) => { is_started: true }; - const sort = { _id: -1 }; @@ -52,7 +51,8 @@ module.exports = (params, user) => new Promise(async (res, rej) => { // Fetch games const games = await Game.find(q, { - sort + sort, + limit }); // Reponse diff --git a/src/api/endpoints/othello/games/show.ts b/src/api/endpoints/othello/games/show.ts new file mode 100644 index 000000000..9dc8f2490 --- /dev/null +++ b/src/api/endpoints/othello/games/show.ts @@ -0,0 +1,16 @@ +import $ from 'cafy'; +import Game, { pack } from '../../../models/othello-game'; + +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'); + } + + res(await pack(game, user)); +}); diff --git a/src/api/models/othello-game.ts b/src/api/models/othello-game.ts index 7ae48b8aa..82c004210 100644 --- a/src/api/models/othello-game.ts +++ b/src/api/models/othello-game.ts @@ -2,7 +2,6 @@ import * as mongo from 'mongodb'; import deepcopy = require('deepcopy'); import db from '../../db/mongodb'; import { IUser, pack as packUser } from './user'; -import { Map } from '../../common/othello/maps'; const Game = db.get('othello_games'); export default Game; @@ -79,6 +78,11 @@ export const pack = ( if (opts.detail === false) { delete _game.logs; delete _game.settings.map; + } else { + // 互換性のため + if (_game.settings.map.hasOwnProperty('size')) { + _game.settings.map = _game.settings.map.data.match(new RegExp(`.{1,${_game.settings.map.size}}`, 'g')); + } } // Populate user diff --git a/src/web/app/common/views/components/othello.game.vue b/src/web/app/common/views/components/othello.game.vue index 248528ed4..6daa7a810 100644 --- a/src/web/app/common/views/components/othello.game.vue +++ b/src/web/app/common/views/components/othello.game.vue @@ -106,8 +106,6 @@ export default Vue.extend({ this.o.put(log.color, log.pos); }); - console.log(this.o); - this.logs = this.game.logs; this.logPos = this.logs.length; }, diff --git a/src/web/app/common/views/components/othello.vue b/src/web/app/common/views/components/othello.vue index 31858fca1..d4157eb76 100644 --- a/src/web/app/common/views/components/othello.vue +++ b/src/web/app/common/views/components/othello.vue @@ -39,7 +39,7 @@

自分の対局

-
+
{{ g.user1.name }} vs {{ g.user2.name }} @@ -48,7 +48,7 @@

みんなの対局

-
+
{{ g.user1.name }} vs {{ g.user2.name }} @@ -108,6 +108,13 @@ export default Vue.extend({ (this as any).os.streams.othelloStream.dispose(this.connectionId); }, methods: { + go(game) { + (this as any).api('othello/games/show', { + game_id: game.id + }).then(game => { + this.game = game; + }); + }, match() { (this as any).apis.input({ title: 'ユーザー名を入力してください' diff --git a/src/web/app/desktop/views/components/input-dialog.vue b/src/web/app/desktop/views/components/input-dialog.vue index e27bc8da8..e939fc190 100644 --- a/src/web/app/desktop/views/components/input-dialog.vue +++ b/src/web/app/desktop/views/components/input-dialog.vue @@ -43,7 +43,6 @@ export default Vue.extend({ mounted() { if (this.default) this.text = this.default; this.$nextTick(() => { - console.log(this); (this.$refs.text as any).focus(); }); },