✌️
This commit is contained in:
parent
910ccf1804
commit
e82268db7e
@ -253,6 +253,11 @@ const endpoints: Endpoint[] = [
|
|||||||
withCredential: true
|
withCredential: true
|
||||||
},
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
name: 'othello/games/show',
|
||||||
|
withCredential: true
|
||||||
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
name: 'mute/create',
|
name: 'mute/create',
|
||||||
withCredential: true,
|
withCredential: true,
|
||||||
|
@ -23,7 +23,7 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
|
|||||||
return rej('cannot set since_id and until_id');
|
return rej('cannot set since_id and until_id');
|
||||||
}
|
}
|
||||||
|
|
||||||
const q = my ? {
|
const q: any = my ? {
|
||||||
is_started: true,
|
is_started: true,
|
||||||
$or: [{
|
$or: [{
|
||||||
user1_id: user._id
|
user1_id: user._id
|
||||||
@ -34,7 +34,6 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
|
|||||||
is_started: true
|
is_started: true
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
const sort = {
|
const sort = {
|
||||||
_id: -1
|
_id: -1
|
||||||
};
|
};
|
||||||
@ -52,7 +51,8 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
|
|||||||
|
|
||||||
// Fetch games
|
// Fetch games
|
||||||
const games = await Game.find(q, {
|
const games = await Game.find(q, {
|
||||||
sort
|
sort,
|
||||||
|
limit
|
||||||
});
|
});
|
||||||
|
|
||||||
// Reponse
|
// Reponse
|
||||||
|
16
src/api/endpoints/othello/games/show.ts
Normal file
16
src/api/endpoints/othello/games/show.ts
Normal file
@ -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));
|
||||||
|
});
|
@ -2,7 +2,6 @@ import * as mongo from 'mongodb';
|
|||||||
import deepcopy = require('deepcopy');
|
import deepcopy = require('deepcopy');
|
||||||
import db from '../../db/mongodb';
|
import db from '../../db/mongodb';
|
||||||
import { IUser, pack as packUser } from './user';
|
import { IUser, pack as packUser } from './user';
|
||||||
import { Map } from '../../common/othello/maps';
|
|
||||||
|
|
||||||
const Game = db.get<IGame>('othello_games');
|
const Game = db.get<IGame>('othello_games');
|
||||||
export default Game;
|
export default Game;
|
||||||
@ -79,6 +78,11 @@ export const pack = (
|
|||||||
if (opts.detail === false) {
|
if (opts.detail === false) {
|
||||||
delete _game.logs;
|
delete _game.logs;
|
||||||
delete _game.settings.map;
|
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
|
// Populate user
|
||||||
|
@ -106,8 +106,6 @@ export default Vue.extend({
|
|||||||
this.o.put(log.color, log.pos);
|
this.o.put(log.color, log.pos);
|
||||||
});
|
});
|
||||||
|
|
||||||
console.log(this.o);
|
|
||||||
|
|
||||||
this.logs = this.game.logs;
|
this.logs = this.game.logs;
|
||||||
this.logPos = this.logs.length;
|
this.logPos = this.logs.length;
|
||||||
},
|
},
|
||||||
|
@ -39,7 +39,7 @@
|
|||||||
</section>
|
</section>
|
||||||
<section v-if="myGames.length > 0">
|
<section v-if="myGames.length > 0">
|
||||||
<h2>自分の対局</h2>
|
<h2>自分の対局</h2>
|
||||||
<div class="game" v-for="g in myGames" tabindex="-1" @click="game = g">
|
<div class="game" v-for="g in myGames" tabindex="-1" @click="go(g)">
|
||||||
<img :src="`${g.user1.avatar_url}?thumbnail&size=32`" alt="">
|
<img :src="`${g.user1.avatar_url}?thumbnail&size=32`" alt="">
|
||||||
<img :src="`${g.user2.avatar_url}?thumbnail&size=32`" alt="">
|
<img :src="`${g.user2.avatar_url}?thumbnail&size=32`" alt="">
|
||||||
<span><b>{{ g.user1.name }}</b> vs <b>{{ g.user2.name }}</b></span>
|
<span><b>{{ g.user1.name }}</b> vs <b>{{ g.user2.name }}</b></span>
|
||||||
@ -48,7 +48,7 @@
|
|||||||
</section>
|
</section>
|
||||||
<section v-if="games.length > 0">
|
<section v-if="games.length > 0">
|
||||||
<h2>みんなの対局</h2>
|
<h2>みんなの対局</h2>
|
||||||
<div class="game" v-for="g in games" tabindex="-1" @click="game = g">
|
<div class="game" v-for="g in games" tabindex="-1" @click="go(g)">
|
||||||
<img :src="`${g.user1.avatar_url}?thumbnail&size=32`" alt="">
|
<img :src="`${g.user1.avatar_url}?thumbnail&size=32`" alt="">
|
||||||
<img :src="`${g.user2.avatar_url}?thumbnail&size=32`" alt="">
|
<img :src="`${g.user2.avatar_url}?thumbnail&size=32`" alt="">
|
||||||
<span><b>{{ g.user1.name }}</b> vs <b>{{ g.user2.name }}</b></span>
|
<span><b>{{ g.user1.name }}</b> vs <b>{{ g.user2.name }}</b></span>
|
||||||
@ -108,6 +108,13 @@ export default Vue.extend({
|
|||||||
(this as any).os.streams.othelloStream.dispose(this.connectionId);
|
(this as any).os.streams.othelloStream.dispose(this.connectionId);
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
|
go(game) {
|
||||||
|
(this as any).api('othello/games/show', {
|
||||||
|
game_id: game.id
|
||||||
|
}).then(game => {
|
||||||
|
this.game = game;
|
||||||
|
});
|
||||||
|
},
|
||||||
match() {
|
match() {
|
||||||
(this as any).apis.input({
|
(this as any).apis.input({
|
||||||
title: 'ユーザー名を入力してください'
|
title: 'ユーザー名を入力してください'
|
||||||
|
@ -43,7 +43,6 @@ export default Vue.extend({
|
|||||||
mounted() {
|
mounted() {
|
||||||
if (this.default) this.text = this.default;
|
if (this.default) this.text = this.default;
|
||||||
this.$nextTick(() => {
|
this.$nextTick(() => {
|
||||||
console.log(this);
|
|
||||||
(this.$refs.text as any).focus();
|
(this.$refs.text as any).focus();
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
Loading…
Reference in New Issue
Block a user