2020-10-27 10:11:41 +01:00
|
|
|
<template>
|
|
|
|
<div v-if="game == null"><MkLoading/></div>
|
|
|
|
<GameSetting v-else-if="!game.isStarted" :init-game="game" :connection="connection"/>
|
|
|
|
<GameBoard v-else :init-game="game" :connection="connection"/>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts">
|
|
|
|
import { defineComponent } from 'vue';
|
|
|
|
import GameSetting from './game.setting.vue';
|
|
|
|
import GameBoard from './game.board.vue';
|
2021-03-23 09:30:14 +01:00
|
|
|
import * as os from '@client/os';
|
2021-04-10 05:54:12 +02:00
|
|
|
import * as symbols from '@client/symbols';
|
2020-10-27 10:11:41 +01:00
|
|
|
|
|
|
|
export default defineComponent({
|
|
|
|
components: {
|
|
|
|
GameSetting,
|
|
|
|
GameBoard,
|
|
|
|
},
|
|
|
|
|
|
|
|
props: {
|
|
|
|
gameId: {
|
|
|
|
type: String,
|
|
|
|
required: true
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
data() {
|
|
|
|
return {
|
2021-04-10 05:54:12 +02:00
|
|
|
[symbols.PAGE_INFO]: {
|
2020-12-26 02:47:36 +01:00
|
|
|
title: this.$ts._reversi.reversi,
|
2021-04-20 16:22:59 +02:00
|
|
|
icon: 'fas fa-gamepad'
|
2020-10-27 10:11:41 +01:00
|
|
|
},
|
|
|
|
game: null,
|
|
|
|
connection: null,
|
|
|
|
};
|
|
|
|
},
|
|
|
|
|
|
|
|
watch: {
|
|
|
|
gameId() {
|
|
|
|
this.fetch();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
mounted() {
|
|
|
|
this.fetch();
|
|
|
|
},
|
|
|
|
|
|
|
|
beforeUnmount() {
|
|
|
|
if (this.connection) {
|
|
|
|
this.connection.dispose();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
methods: {
|
|
|
|
fetch() {
|
|
|
|
os.api('games/reversi/games/show', {
|
|
|
|
gameId: this.gameId
|
|
|
|
}).then(game => {
|
|
|
|
this.game = game;
|
|
|
|
|
|
|
|
if (this.connection) {
|
|
|
|
this.connection.dispose();
|
|
|
|
}
|
|
|
|
this.connection = os.stream.connectToChannel('gamesReversiGame', {
|
|
|
|
gameId: this.game.id
|
|
|
|
});
|
|
|
|
this.connection.on('started', this.onStarted);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
onStarted(game) {
|
|
|
|
Object.assign(this.game, game);
|
|
|
|
},
|
|
|
|
}
|
|
|
|
});
|
|
|
|
</script>
|