zhao/imports/ui/App.vue

83 lines
1.6 KiB
Vue
Raw Normal View History

2020-11-27 05:33:53 +00:00
<template>
<div>
2020-11-27 07:16:15 +00:00
<component
v-bind:is="whatScreen"
2020-11-27 08:18:29 +00:00
v-bind:roomInfo="roomInfo"
2020-11-27 07:34:12 +00:00
v-bind:players="players"
2020-11-27 08:18:29 +00:00
v-bind:currentRoom="currentRoom"
2020-11-27 07:16:15 +00:00
v-on:newGame="newGame"
v-on:joinGame="joinGame"
></component>
2021-01-14 20:09:01 +00:00
User ID: {{ userId }}
2020-11-27 05:33:53 +00:00
</div>
</template>
<script>
2020-11-27 07:34:12 +00:00
import Lobby from "./components/Lobby.vue"
import WaitingRoom from "./components/WaitingRoom.vue"
import Players from "../api/collections/Players";
2020-11-27 08:18:29 +00:00
import Rooms from "../api/collections/Rooms";
2020-11-27 05:33:53 +00:00
export default {
components: {
Lobby,
2020-11-27 07:16:15 +00:00
WaitingRoom,
2020-11-27 05:33:53 +00:00
},
2020-11-27 07:34:12 +00:00
meteor: {
players() {
2020-11-27 08:18:29 +00:00
if (this.roomInfo === null)
return [];
return Players.find({ roomId: this.roomInfo.roomId });
},
currentRoom() {
if (this.roomInfo === null)
return null;
return Rooms.findOne(this.roomInfo.roomId);
2020-11-27 07:34:12 +00:00
},
},
2020-11-27 05:33:53 +00:00
data() {
return {
2020-11-27 08:18:29 +00:00
roomInfo: null,
2020-11-27 05:33:53 +00:00
};
},
2020-11-27 07:16:15 +00:00
2021-01-14 20:09:01 +00:00
computed: {
whatScreen: function() {
if (this.roomInfo === null)
return Lobby;
else if (this.currentRoom === null || this.currentRoom.state === "waitingRoom")
return WaitingRoom;
},
userId: function() {
console.log("userId", Meteor.userId());
return Meteor.userId();
},
},
2020-11-27 07:16:15 +00:00
methods: {
newGame: function(args) {
2020-11-27 08:18:29 +00:00
this.roomInfo = args;
Meteor.subscribe("players", args.roomId);
Meteor.subscribe("currentRoom", args.roomId);
2020-11-27 07:16:15 +00:00
},
joinGame: function(args) {
2020-11-27 08:18:29 +00:00
this.roomInfo = args;
Meteor.subscribe("players", args.roomId);
Meteor.subscribe("currentRoom", args.roomId);
2020-11-27 07:16:15 +00:00
},
}
2020-11-27 05:33:53 +00:00
}
</script>
<style>
2020-11-27 06:36:02 +00:00
body {
font-family: sans-serif;
padding: 10px;
}
2020-11-27 05:33:53 +00:00
</style>