Sharkey/src/client/app/common/views/components/games/reversi/reversi.gameroom.vue

55 lines
1.1 KiB
Vue
Raw Normal View History

2018-03-08 09:57:57 +01:00
<template>
<div>
2018-03-29 07:48:47 +02:00
<x-room v-if="!g.isStarted" :game="g" :connection="connection"/>
2018-08-05 06:40:26 +02:00
<x-game v-else :init-game="g" :connection="connection" :self-nav="selfNav" @go-index="goIndex"/>
2018-03-08 09:57:57 +01:00
</div>
</template>
<script lang="ts">
import Vue from 'vue';
2018-06-17 01:10:54 +02:00
import XGame from './reversi.game.vue';
import XRoom from './reversi.room.vue';
2018-07-11 06:49:06 +02:00
import { ReversiGameStream } from '../../../../scripts/streaming/games/reversi/reversi-game';
2018-03-08 09:57:57 +01:00
export default Vue.extend({
components: {
XGame,
XRoom
},
2018-08-05 06:40:26 +02:00
props: {
game: {
type: Object,
required: true
},
selfNav: {
type: Boolean,
require: true
}
},
2018-03-08 09:57:57 +01:00
data() {
return {
connection: null,
g: null
};
},
created() {
this.g = this.game;
2018-06-17 01:10:54 +02:00
this.connection = new ReversiGameStream((this as any).os, this.$store.state.i, this.game);
2018-03-08 09:57:57 +01:00
this.connection.on('started', this.onStarted);
},
beforeDestroy() {
this.connection.off('started', this.onStarted);
this.connection.close();
},
methods: {
onStarted(game) {
Object.assign(this.g, game);
this.$forceUpdate();
2018-08-05 06:40:26 +02:00
},
goIndex() {
this.$emit('go-index');
2018-03-08 09:57:57 +01:00
}
}
});
</script>