2019-06-06 16:07:15 +00:00
|
|
|
<template>
|
|
|
|
<div class="container">
|
2019-06-10 16:15:29 +00:00
|
|
|
<b-button @click="create" icon-left="library-plus" type="is-primary"
|
|
|
|
>Create</b-button
|
|
|
|
>
|
2019-06-07 13:32:43 +00:00
|
|
|
<b-table
|
|
|
|
striped
|
|
|
|
hoverable
|
|
|
|
:data="rooms"
|
|
|
|
:columns="columns"
|
|
|
|
@click="rowClicked"
|
|
|
|
></b-table>
|
2019-06-06 16:07:15 +00:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
2019-06-07 13:32:43 +00:00
|
|
|
<style lang="scss" scoped>
|
|
|
|
.b-table {
|
|
|
|
cursor: pointer;
|
|
|
|
}
|
|
|
|
</style>
|
|
|
|
|
2019-06-06 16:07:15 +00:00
|
|
|
<script lang="ts">
|
|
|
|
import { Component, Vue } from "vue-property-decorator";
|
2019-06-07 13:32:43 +00:00
|
|
|
import { State, Action } from "vuex-class";
|
|
|
|
import { ServerState } from "@/store/server";
|
|
|
|
import { Room } from "@/store/room";
|
|
|
|
|
|
|
|
const columns = [
|
|
|
|
{
|
|
|
|
field: "game_id",
|
|
|
|
label: "Game"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
field: "name",
|
|
|
|
label: "Name"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
field: "creator",
|
|
|
|
label: "Creator"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
field: "can_spectate",
|
|
|
|
label: "Spectators allowed"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
field: "players",
|
|
|
|
label: "Players",
|
|
|
|
numeric: true
|
|
|
|
},
|
|
|
|
{
|
|
|
|
field: "spectators",
|
|
|
|
label: "Spectators",
|
|
|
|
numeric: true
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
|
|
|
interface RoomRow {
|
|
|
|
id: string;
|
|
|
|
game_id: string;
|
|
|
|
name: string;
|
|
|
|
creator: string;
|
|
|
|
players: number;
|
|
|
|
spectators: number;
|
|
|
|
can_spectate: string;
|
|
|
|
}
|
2019-06-06 16:07:15 +00:00
|
|
|
|
|
|
|
@Component({})
|
2019-06-07 13:32:43 +00:00
|
|
|
export default class RoomList extends Vue {
|
|
|
|
@State("server") private server!: ServerState;
|
|
|
|
@Action("joinRoom", { namespace: "server" }) private join: any;
|
2019-06-10 16:15:29 +00:00
|
|
|
@Action("createRoom", { namespace: "server" }) private create: any;
|
2019-06-07 13:32:43 +00:00
|
|
|
|
|
|
|
private data() {
|
|
|
|
return {
|
|
|
|
columns
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
private get rooms(): RoomRow[] {
|
|
|
|
if (this.server.rooms == null) {
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
let rooms: RoomRow[] = [];
|
|
|
|
for (const room of this.server.rooms) {
|
|
|
|
rooms.push({
|
|
|
|
id: room.id,
|
|
|
|
game_id: room.game_id,
|
|
|
|
name: room.name,
|
|
|
|
creator: room.creator,
|
|
|
|
players: room.current_players,
|
|
|
|
spectators: room.current_spectators,
|
|
|
|
can_spectate: room.can_spectate ? "Yes" : "No"
|
|
|
|
});
|
|
|
|
}
|
|
|
|
return rooms;
|
|
|
|
}
|
|
|
|
|
|
|
|
private rowClicked(row: RoomRow) {
|
|
|
|
this.join({
|
|
|
|
roomid: row.id,
|
|
|
|
as_spectator: row.can_spectate == "Yes"
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
2019-06-06 16:07:15 +00:00
|
|
|
</script>
|