summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/client/app/common/views/components/games/reversi/reversi.game.vue3
-rw-r--r--src/client/app/common/views/components/games/reversi/reversi.vue68
-rw-r--r--src/server/api/endpoints/games/reversi/games.ts1
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 303070ffd8..dd3f3fa55e 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 6e64710823..3d28b6bdd6 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 b72af06d22..2838940b5c 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) => {