diff --git a/client/src/pages/play.vue b/client/src/pages/play.vue index dfed701..fa41b29 100644 --- a/client/src/pages/play.vue +++ b/client/src/pages/play.vue @@ -2,6 +2,15 @@
+
+

waiting ...

+
+
+

{{ gamePhase }}

+
+
+

Play

+
@@ -13,5 +22,13 @@ export default { async beforeDestroy() { await this.$engine.stop() }, + computed: { + gameState() { + return this.$store.state.game.state + }, + gamePhase() { + return this.$store.state.game.phase + }, + }, } diff --git a/client/src/plugins/engine/fetchUpdate.js b/client/src/plugins/engine/fetchUpdate.js index 9c8b2e1..9a870d7 100644 --- a/client/src/plugins/engine/fetchUpdate.js +++ b/client/src/plugins/engine/fetchUpdate.js @@ -14,8 +14,13 @@ export default async function() { g: store.state.engine.user?.game, }) - store.commit('engine/setJson', response.data) + this.parseSyncData(response.data) } catch (e) { + if (!e.response) { + // request aborted or other causes + return + } + const { status, statusText } = e.response if (status != 200) { console.warn(`HTTP ${status} ${statusText}`) diff --git a/client/src/plugins/engine/index.js b/client/src/plugins/engine/index.js index 9657a47..470c6c1 100644 --- a/client/src/plugins/engine/index.js +++ b/client/src/plugins/engine/index.js @@ -4,6 +4,7 @@ import stop from './stop' import fetchUpdate from './fetchUpdate' import fetchUserInfo from './fetchUserInfo' import startGame from './startGame' +import parseSyncData from './parseSyncData' export default (context, inject) => { const engine = { @@ -18,6 +19,7 @@ export default (context, inject) => { fetchUpdate, fetchUserInfo, startGame, + parseSyncData, } inject('engine', engine) diff --git a/client/src/plugins/engine/parseSyncData.js b/client/src/plugins/engine/parseSyncData.js new file mode 100644 index 0000000..4d46136 --- /dev/null +++ b/client/src/plugins/engine/parseSyncData.js @@ -0,0 +1,6 @@ +export default function(data) { + const { store } = this.context + + store.commit('engine/setJson', data) + store.commit('game/setStateAndPhase', data.game) +} diff --git a/client/src/store/game.js b/client/src/store/game.js new file mode 100644 index 0000000..2d486ed --- /dev/null +++ b/client/src/store/game.js @@ -0,0 +1,11 @@ +export const state = () => ({ + state: "...", + phase: "...", +}) + +export const mutations = { + setStateAndPhase(state, { state: gameState, phase }) { + state.state = gameState + state.phase = phase + }, +}