prepare use of vue for game/replay
This commit is contained in:
parent
343263be6c
commit
8e7aa7d453
7 changed files with 156 additions and 43 deletions
40
public/views/NewGame.vue.js
Normal file
40
public/views/NewGame.vue.js
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
"use strict"
|
||||
|
||||
import NewGameDialog from './../components/NewGameDialog.vue.js'
|
||||
|
||||
export default {
|
||||
components: {
|
||||
NewGameDialog,
|
||||
},
|
||||
// TODO: maybe move dialog back, now that this is a view on its own
|
||||
template: `
|
||||
<div>
|
||||
<new-game-dialog :images="images" @newGame="onNewGame" />
|
||||
</div>`,
|
||||
data() {
|
||||
return {
|
||||
images: [],
|
||||
}
|
||||
},
|
||||
async created() {
|
||||
const res = await fetch('/api/newgame-data')
|
||||
const json = await res.json()
|
||||
this.images = json.images
|
||||
},
|
||||
methods: {
|
||||
async onNewGame(gameSettings) {
|
||||
const res = await fetch('/newgame', {
|
||||
method: 'post',
|
||||
headers: {
|
||||
'Accept': 'application/json',
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
body: JSON.stringify(gameSettings),
|
||||
})
|
||||
if (res.status === 200) {
|
||||
const game = await res.json()
|
||||
location.assign(game.url)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue