ログインしていないとリバーシを観戦できない問題を修正

This commit is contained in:
syuilo 2018-07-27 04:01:12 +09:00
parent 3eb6b36866
commit fab0a0d6e2
3 changed files with 44 additions and 28 deletions

View File

@ -105,7 +105,8 @@ export default Vue.extend({
} }
}, },
isMyTurn(): boolean { 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; return this.turnUser.id == this.$store.state.i.id;
}, },
cellsStyle(): any { cellsStyle(): any {

View File

@ -67,7 +67,9 @@ export default Vue.extend({
components: { components: {
XGameroom XGameroom
}, },
props: ['initGame'], props: ['initGame'],
data() { data() {
return { return {
game: null, game: null,
@ -82,17 +84,21 @@ export default Vue.extend({
pingClock: null pingClock: null
}; };
}, },
watch: { watch: {
game(g) { game(g) {
this.$emit('gamed', g); this.$emit('gamed', g);
} }
}, },
created() { created() {
if (this.initGame) { if (this.initGame) {
this.game = this.initGame; this.game = this.initGame;
} }
}, },
mounted() { mounted() {
if (this.$store.getters.isSignedIn) {
this.connection = (this as any).os.streams.reversiStream.getConnection(); this.connection = (this as any).os.streams.reversiStream.getConnection();
this.connectionId = (this as any).os.streams.reversiStream.use(); this.connectionId = (this as any).os.streams.reversiStream.use();
@ -105,11 +111,6 @@ export default Vue.extend({
this.myGames = games; this.myGames = games;
}); });
(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 as any).api('games/reversi/invitations').then(invitations => {
this.invitations = this.invitations.concat(invitations); this.invitations = this.invitations.concat(invitations);
}); });
@ -122,14 +123,24 @@ export default Vue.extend({
}); });
} }
}, 3000); }, 3000);
}
(this as any).api('games/reversi/games').then(games => {
this.games = games;
this.gamesFetching = false;
});
}, },
beforeDestroy() { beforeDestroy() {
if (this.connection) {
this.connection.off('matched', this.onMatched); this.connection.off('matched', this.onMatched);
this.connection.off('invited', this.onInvited); this.connection.off('invited', this.onInvited);
(this as any).os.streams.reversiStream.dispose(this.connectionId); (this as any).os.streams.reversiStream.dispose(this.connectionId);
clearInterval(this.pingClock); clearInterval(this.pingClock);
}
}, },
methods: { methods: {
go(game) { go(game) {
(this as any).api('games/reversi/games/show', { (this as any).api('games/reversi/games/show', {
@ -139,6 +150,7 @@ export default Vue.extend({
this.game = game; this.game = game;
}); });
}, },
match() { match() {
(this as any).apis.input({ (this as any).apis.input({
title: 'ユーザー名を入力してください' title: 'ユーザー名を入力してください'
@ -158,10 +170,12 @@ export default Vue.extend({
}); });
}); });
}, },
cancel() { cancel() {
this.matching = null; this.matching = null;
(this as any).api('games/reversi/match/cancel'); (this as any).api('games/reversi/match/cancel');
}, },
accept(invitation) { accept(invitation) {
(this as any).api('games/reversi/match', { (this as any).api('games/reversi/match', {
userId: invitation.parent.id userId: invitation.parent.id
@ -172,10 +186,12 @@ export default Vue.extend({
} }
}); });
}, },
onMatched(game) { onMatched(game) {
this.matching = null; this.matching = null;
this.game = game; this.game = game;
}, },
onInvited(invite) { onInvited(invite) {
this.invitations.unshift(invite); this.invitations.unshift(invite);
} }

View File

@ -3,7 +3,6 @@ import ReversiGame, { pack } from '../../../../../models/games/reversi/game';
import { ILocalUser } from '../../../../../models/user'; import { ILocalUser } from '../../../../../models/user';
export const meta = { export const meta = {
requireCredential: true
}; };
export default (params: any, user: ILocalUser) => new Promise(async (res, rej) => { export default (params: any, user: ILocalUser) => new Promise(async (res, rej) => {