parse game state and phase
This commit is contained in:
parent
281baa5bd2
commit
86bb2486f0
@ -2,6 +2,15 @@
|
|||||||
<div>
|
<div>
|
||||||
<GameControls />
|
<GameControls />
|
||||||
<EngineDebug />
|
<EngineDebug />
|
||||||
|
<div v-if="gameState === 'idle'">
|
||||||
|
<p>waiting ...</p>
|
||||||
|
</div>
|
||||||
|
<div v-if="gameState === 'ready-set'">
|
||||||
|
<h1>{{ gamePhase }}</h1>
|
||||||
|
</div>
|
||||||
|
<div v-if="gameState === 'play'">
|
||||||
|
<h2>Play</h2>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
@ -13,5 +22,13 @@ export default {
|
|||||||
async beforeDestroy() {
|
async beforeDestroy() {
|
||||||
await this.$engine.stop()
|
await this.$engine.stop()
|
||||||
},
|
},
|
||||||
|
computed: {
|
||||||
|
gameState() {
|
||||||
|
return this.$store.state.game.state
|
||||||
|
},
|
||||||
|
gamePhase() {
|
||||||
|
return this.$store.state.game.phase
|
||||||
|
},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
@ -14,8 +14,13 @@ export default async function() {
|
|||||||
g: store.state.engine.user?.game,
|
g: store.state.engine.user?.game,
|
||||||
})
|
})
|
||||||
|
|
||||||
store.commit('engine/setJson', response.data)
|
this.parseSyncData(response.data)
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
if (!e.response) {
|
||||||
|
// request aborted or other causes
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
const { status, statusText } = e.response
|
const { status, statusText } = e.response
|
||||||
if (status != 200) {
|
if (status != 200) {
|
||||||
console.warn(`HTTP ${status} ${statusText}`)
|
console.warn(`HTTP ${status} ${statusText}`)
|
||||||
|
@ -4,6 +4,7 @@ import stop from './stop'
|
|||||||
import fetchUpdate from './fetchUpdate'
|
import fetchUpdate from './fetchUpdate'
|
||||||
import fetchUserInfo from './fetchUserInfo'
|
import fetchUserInfo from './fetchUserInfo'
|
||||||
import startGame from './startGame'
|
import startGame from './startGame'
|
||||||
|
import parseSyncData from './parseSyncData'
|
||||||
|
|
||||||
export default (context, inject) => {
|
export default (context, inject) => {
|
||||||
const engine = {
|
const engine = {
|
||||||
@ -18,6 +19,7 @@ export default (context, inject) => {
|
|||||||
fetchUpdate,
|
fetchUpdate,
|
||||||
fetchUserInfo,
|
fetchUserInfo,
|
||||||
startGame,
|
startGame,
|
||||||
|
parseSyncData,
|
||||||
}
|
}
|
||||||
|
|
||||||
inject('engine', engine)
|
inject('engine', engine)
|
||||||
|
6
client/src/plugins/engine/parseSyncData.js
Normal file
6
client/src/plugins/engine/parseSyncData.js
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
export default function(data) {
|
||||||
|
const { store } = this.context
|
||||||
|
|
||||||
|
store.commit('engine/setJson', data)
|
||||||
|
store.commit('game/setStateAndPhase', data.game)
|
||||||
|
}
|
11
client/src/store/game.js
Normal file
11
client/src/store/game.js
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
export const state = () => ({
|
||||||
|
state: "...",
|
||||||
|
phase: "...",
|
||||||
|
})
|
||||||
|
|
||||||
|
export const mutations = {
|
||||||
|
setStateAndPhase(state, { state: gameState, phase }) {
|
||||||
|
state.state = gameState
|
||||||
|
state.phase = phase
|
||||||
|
},
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user