import GameCommon from './../../common/GameCommon.js'
import Time from './../../common/Time.js'
import Upload from './../components/Upload.vue.js'
import GameTeaser from './../components/GameTeaser.vue.js'
import ImageTeaser from './../components/ImageTeaser.vue.js'
export default {
components: {
Upload,
GameTeaser,
ImageTeaser,
},
props: {
gamesRunning: Array,
gamesFinished: Array,
images: Array,
},
template: `
Running games
New game
Image lib
Finished games
`,
data() {
return {
tiles: 1000,
image: '',
scoreMode: GameCommon.SCORE_MODE_ANY,
}
},
methods: {
time(start, end) {
const icon = end ? '🏁' : '⏳'
const from = start;
const to = end || Time.timestamp()
const timeDiffStr = Time.timeDiffStr(from, to)
return `${icon} ${timeDiffStr}`
},
mediaImgUploaded(j) {
this.image = j.image
},
async onNewGameClick() {
const res = await fetch('/newgame', {
method: 'post',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
},
body: JSON.stringify({
tiles: this.tiles,
image: this.image,
scoreMode: parseInt(this.scoreMode, 10),
}),
})
if (res.status === 200) {
const game = await res.json()
location.assign(game.url)
}
}
}
}