From 3ea031caa32729a0629cf4c7e29f913db42f1b06 Mon Sep 17 00:00:00 2001 From: Hamcha Date: Mon, 23 Sep 2019 17:22:06 +0200 Subject: [PATCH] Refactor room inside lobby --- public/index.html | 36 +++++++++++++++++++--------------- src/router.ts | 5 ----- src/store/network/getters.ts | 10 ++++++++++ src/store/network/mutations.ts | 18 ++++++----------- src/views/Lobby.vue | 10 ++++++++-- src/views/Room.vue | 14 ------------- 6 files changed, 44 insertions(+), 49 deletions(-) delete mode 100644 src/views/Room.vue diff --git a/public/index.html b/public/index.html index e4d8640..ce79e8c 100644 --- a/public/index.html +++ b/public/index.html @@ -1,18 +1,22 @@ - - - - - - - mcgvue - - - -
- - - + + + + + + + + MLPCARDGAME + + + + +
+ + + + \ No newline at end of file diff --git a/src/router.ts b/src/router.ts index 98f83a2..1a2b459 100644 --- a/src/router.ts +++ b/src/router.ts @@ -45,11 +45,6 @@ export default new Router({ topnav: "Lobby" } }, - { - path: "/room", - name: "room", - component: RoomView - }, { path: "/settings", name: "settings", diff --git a/src/store/network/getters.ts b/src/store/network/getters.ts index 3840b22..de91bd9 100644 --- a/src/store/network/getters.ts +++ b/src/store/network/getters.ts @@ -15,6 +15,16 @@ const getters: GetterTree = { connectionType(state): "client" | "server" | "none" { return state.peerType; + }, + + inRoom(state): boolean { + if (state.peerType == "client") { + return state.connectionStatus == "connected"; + } + if (state.peerType == "server") { + return true; + } + return false; } }; diff --git a/src/store/network/mutations.ts b/src/store/network/mutations.ts index 5a0d135..c6decfe 100644 --- a/src/store/network/mutations.ts +++ b/src/store/network/mutations.ts @@ -4,21 +4,15 @@ import { LocalClient, PeerServer, PeerClient } from "@/network"; const mutations: MutationTree = { becomeServer(state, payload: { local: LocalClient; server: PeerServer }) { - state = { - ...state, - peerType: "server", - local: payload.local, - server: payload.server - }; + state.peerType = "server"; + (state as ServerNetworkState).local = payload.local; + (state as ServerNetworkState).server = payload.server; }, becomeClient(state, payload: { peer: PeerClient }) { - state = { - ...state, - connectionStatus: "connecting", - peerType: "client", - peer: payload.peer - }; + state.peerType = "client"; + (state as ClientNetworkState).connectionStatus = "connecting"; + (state as ClientNetworkState).peer = payload.peer; }, connected(state) { diff --git a/src/views/Lobby.vue b/src/views/Lobby.vue index 897c42a..bc7c769 100644 --- a/src/views/Lobby.vue +++ b/src/views/Lobby.vue @@ -1,7 +1,7 @@ @@ -183,7 +186,7 @@ import { Component, Vue } from "vue-property-decorator"; import TopNav from "@/components/Navigation/TopNav.vue"; import { StartServerOptions, ConnectOptions } from "@/store/network/types"; -import { Action } from "vuex-class"; +import { Action, Getter } from "vuex-class"; @Component({ components: { @@ -203,6 +206,9 @@ export default class Lobby extends Vue { @Action("connect", { namespace: "network" }) private connect!: (options: ConnectOptions) => void; + @Getter("inRoom", { namespace: "network" }) + private inRoom!: boolean; + private data() { return { playerName: diff --git a/src/views/Room.vue b/src/views/Room.vue deleted file mode 100644 index 0fe4cae..0000000 --- a/src/views/Room.vue +++ /dev/null @@ -1,14 +0,0 @@ - - - - -