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

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 {
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 {

View file

@ -67,7 +67,9 @@ export default Vue.extend({
components: {
XGameroom
},
props: ['initGame'],
data() {
return {
game: null,
@ -82,17 +84,21 @@ export default Vue.extend({
pingClock: null
};
},
watch: {
game(g) {
this.$emit('gamed', g);
}
},
created() {
if (this.initGame) {
this.game = this.initGame;
}
},
mounted() {
if (this.$store.getters.isSignedIn) {
this.connection = (this as any).os.streams.reversiStream.getConnection();
this.connectionId = (this as any).os.streams.reversiStream.use();
@ -105,11 +111,6 @@ export default Vue.extend({
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.invitations = this.invitations.concat(invitations);
});
@ -122,14 +123,24 @@ export default Vue.extend({
});
}
}, 3000);
}
(this as any).api('games/reversi/games').then(games => {
this.games = games;
this.gamesFetching = false;
});
},
beforeDestroy() {
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);
}
},
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);
}

View file

@ -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) => {