summaryrefslogtreecommitdiff
path: root/src/web/app/common
diff options
context:
space:
mode:
authorsyuilo <syuilotan@yahoo.co.jp>2018-03-11 17:23:59 +0900
committersyuilo <syuilotan@yahoo.co.jp>2018-03-11 17:23:59 +0900
commit27914e227f6f3ca30841c02969c6510235503425 (patch)
tree6001c605757b4672cb3936917737dfb59dcc0fa7 /src/web/app/common
parentv4107 (diff)
downloadmisskey-27914e227f6f3ca30841c02969c6510235503425.tar.gz
misskey-27914e227f6f3ca30841c02969c6510235503425.tar.bz2
misskey-27914e227f6f3ca30841c02969c6510235503425.zip
#1230
Diffstat (limited to 'src/web/app/common')
-rw-r--r--src/web/app/common/views/components/othello.game.vue45
-rw-r--r--src/web/app/common/views/components/othello.gameroom.vue2
2 files changed, 44 insertions, 3 deletions
diff --git a/src/web/app/common/views/components/othello.game.vue b/src/web/app/common/views/components/othello.game.vue
index 77be458879..01148f193e 100644
--- a/src/web/app/common/views/components/othello.game.vue
+++ b/src/web/app/common/views/components/othello.game.vue
@@ -37,17 +37,20 @@
<script lang="ts">
import Vue from 'vue';
+import * as CRC32 from 'crc-32';
import Othello, { Color } from '../../../../../common/othello/core';
import { url } from '../../../config';
export default Vue.extend({
- props: ['game', 'connection'],
+ props: ['initGame', 'connection'],
data() {
return {
+ game: null,
o: null as Othello,
logs: [],
- logPos: 0
+ logPos: 0,
+ pollingClock: null
};
},
@@ -104,6 +107,8 @@ export default Vue.extend({
},
created() {
+ this.game = this.initGame;
+
this.o = new Othello(this.game.settings.map, {
isLlotheo: this.game.settings.is_llotheo,
canPutEverywhere: this.game.settings.can_put_everywhere,
@@ -116,14 +121,29 @@ export default Vue.extend({
this.logs = this.game.logs;
this.logPos = this.logs.length;
+
+ // 通信を取りこぼしてもいいように定期的にポーリングさせる
+ if (this.game.is_started && !this.game.is_ended) {
+ this.pollingClock = setInterval(() => {
+ const crc32 = CRC32.str(this.logs.map(x => x.pos.toString()).join(''));
+ this.connection.send({
+ type: 'check',
+ crc32
+ });
+ }, 10000);
+ }
},
mounted() {
this.connection.on('set', this.onSet);
+ this.connection.on('rescue', this.onRescue);
},
beforeDestroy() {
this.connection.off('set', this.onSet);
+ this.connection.off('rescue', this.onRescue);
+
+ clearInterval(this.pollingClock);
},
methods: {
@@ -181,6 +201,27 @@ export default Vue.extend({
this.game.winner = null;
}
}
+ },
+
+ // 正しいゲーム情報が送られてきたとき
+ onRescue(game) {
+ this.game = game;
+
+ this.o = new Othello(this.game.settings.map, {
+ isLlotheo: this.game.settings.is_llotheo,
+ canPutEverywhere: this.game.settings.can_put_everywhere,
+ loopedBoard: this.game.settings.looped_board
+ });
+
+ this.game.logs.forEach(log => {
+ this.o.put(log.color, log.pos);
+ });
+
+ this.logs = this.game.logs;
+ this.logPos = this.logs.length;
+
+ this.checkEnd();
+ this.$forceUpdate();
}
}
});
diff --git a/src/web/app/common/views/components/othello.gameroom.vue b/src/web/app/common/views/components/othello.gameroom.vue
index 9f4037515a..9df458f644 100644
--- a/src/web/app/common/views/components/othello.gameroom.vue
+++ b/src/web/app/common/views/components/othello.gameroom.vue
@@ -1,7 +1,7 @@
<template>
<div>
<x-room v-if="!g.is_started" :game="g" :connection="connection"/>
- <x-game v-else :game="g" :connection="connection"/>
+ <x-game v-else :init-game="g" :connection="connection"/>
</div>
</template>