From fab0a0d6e246e6f95a81bd37a96c0ab860ed5df8 Mon Sep 17 00:00:00 2001 From: syuilo Date: Fri, 27 Jul 2018 04:01:12 +0900 Subject: [PATCH] =?UTF-8?q?=E3=83=AD=E3=82=B0=E3=82=A4=E3=83=B3=E3=81=97?= =?UTF-8?q?=E3=81=A6=E3=81=84=E3=81=AA=E3=81=84=E3=81=A8=E3=83=AA=E3=83=90?= =?UTF-8?q?=E3=83=BC=E3=82=B7=E3=82=92=E8=A6=B3=E6=88=A6=E3=81=A7=E3=81=8D?= =?UTF-8?q?=E3=81=AA=E3=81=84=E5=95=8F=E9=A1=8C=E3=82=92=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../components/games/reversi/reversi.game.vue | 3 +- .../components/games/reversi/reversi.vue | 68 ++++++++++++------- .../api/endpoints/games/reversi/games.ts | 1 - 3 files changed, 44 insertions(+), 28 deletions(-) diff --git a/src/client/app/common/views/components/games/reversi/reversi.game.vue b/src/client/app/common/views/components/games/reversi/reversi.game.vue index 303070ffd..dd3f3fa55 100644 --- a/src/client/app/common/views/components/games/reversi/reversi.game.vue +++ b/src/client/app/common/views/components/games/reversi/reversi.game.vue @@ -105,7 +105,8 @@ export default Vue.extend({ } }, isMyTurn(): boolean { - if (this.turnUser == null) return null; + if (!this.iAmPlayer) return false; + if (this.turnUser == null) return false; return this.turnUser.id == this.$store.state.i.id; }, cellsStyle(): any { diff --git a/src/client/app/common/views/components/games/reversi/reversi.vue b/src/client/app/common/views/components/games/reversi/reversi.vue index 6e6471082..3d28b6bdd 100644 --- a/src/client/app/common/views/components/games/reversi/reversi.vue +++ b/src/client/app/common/views/components/games/reversi/reversi.vue @@ -67,7 +67,9 @@ export default Vue.extend({ components: { XGameroom }, + props: ['initGame'], + data() { return { game: null, @@ -82,54 +84,63 @@ export default Vue.extend({ pingClock: null }; }, + watch: { game(g) { this.$emit('gamed', g); } }, + created() { if (this.initGame) { this.game = this.initGame; } }, + mounted() { - this.connection = (this as any).os.streams.reversiStream.getConnection(); - this.connectionId = (this as any).os.streams.reversiStream.use(); + if (this.$store.getters.isSignedIn) { + this.connection = (this as any).os.streams.reversiStream.getConnection(); + this.connectionId = (this as any).os.streams.reversiStream.use(); - this.connection.on('matched', this.onMatched); - this.connection.on('invited', this.onInvited); + this.connection.on('matched', this.onMatched); + this.connection.on('invited', this.onInvited); - (this as any).api('games/reversi/games', { - my: true - }).then(games => { - this.myGames = games; - }); + (this as any).api('games/reversi/games', { + my: true + }).then(games => { + this.myGames = games; + }); + + (this as any).api('games/reversi/invitations').then(invitations => { + this.invitations = this.invitations.concat(invitations); + }); + + this.pingClock = setInterval(() => { + if (this.matching) { + this.connection.send({ + type: 'ping', + id: this.matching.id + }); + } + }, 3000); + } (this as any).api('games/reversi/games').then(games => { this.games = games; this.gamesFetching = false; }); - - (this as any).api('games/reversi/invitations').then(invitations => { - this.invitations = this.invitations.concat(invitations); - }); - - this.pingClock = setInterval(() => { - if (this.matching) { - this.connection.send({ - type: 'ping', - id: this.matching.id - }); - } - }, 3000); }, + beforeDestroy() { - this.connection.off('matched', this.onMatched); - this.connection.off('invited', this.onInvited); - (this as any).os.streams.reversiStream.dispose(this.connectionId); + if (this.connection) { + this.connection.off('matched', this.onMatched); + this.connection.off('invited', this.onInvited); + (this as any).os.streams.reversiStream.dispose(this.connectionId); - clearInterval(this.pingClock); + clearInterval(this.pingClock); + } }, + methods: { go(game) { (this as any).api('games/reversi/games/show', { @@ -139,6 +150,7 @@ export default Vue.extend({ this.game = game; }); }, + match() { (this as any).apis.input({ title: 'ユーザー名を入力してください' @@ -158,10 +170,12 @@ export default Vue.extend({ }); }); }, + cancel() { this.matching = null; (this as any).api('games/reversi/match/cancel'); }, + accept(invitation) { (this as any).api('games/reversi/match', { userId: invitation.parent.id @@ -172,10 +186,12 @@ export default Vue.extend({ } }); }, + onMatched(game) { this.matching = null; this.game = game; }, + onInvited(invite) { this.invitations.unshift(invite); } diff --git a/src/server/api/endpoints/games/reversi/games.ts b/src/server/api/endpoints/games/reversi/games.ts index b72af06d2..2838940b5 100644 --- a/src/server/api/endpoints/games/reversi/games.ts +++ b/src/server/api/endpoints/games/reversi/games.ts @@ -3,7 +3,6 @@ import ReversiGame, { pack } from '../../../../../models/games/reversi/game'; import { ILocalUser } from '../../../../../models/user'; export const meta = { - requireCredential: true }; export default (params: any, user: ILocalUser) => new Promise(async (res, rej) => {