From 722be39ad95d73721762c6acf1655b7ebb9cb3c4 Mon Sep 17 00:00:00 2001 From: Zutatensuppe Date: Thu, 13 May 2021 14:01:10 +0200 Subject: [PATCH] move new game setup to new component --- public/components/NewGameDialog.vue.js | 94 ++++++++++++++++++++++++++ public/views/Index.vue.js | 83 ++++------------------- 2 files changed, 106 insertions(+), 71 deletions(-) create mode 100644 public/components/NewGameDialog.vue.js diff --git a/public/components/NewGameDialog.vue.js b/public/components/NewGameDialog.vue.js new file mode 100644 index 0000000..3eb6040 --- /dev/null +++ b/public/components/NewGameDialog.vue.js @@ -0,0 +1,94 @@ +"use strict" + +import GameCommon from './../../common/GameCommon.js' +import Upload from './../components/Upload.vue.js' +import ImageTeaser from './../components/ImageTeaser.vue.js' + +export default { + name: 'NewGameDialog', + components: { + Upload, + ImageTeaser, + }, + template: ` +
+

New game

+ + + + + + + + + + + + + + + + +
+ +
+ +
+ + + or + + + + + (or select from below) + +
+ +
+ +

Image lib

+
+ +
+
`, + props: { + images: Array, + }, + emits: { + newGame: null, + }, + data() { + return { + tiles: 1000, + image: '', + scoreMode: GameCommon.SCORE_MODE_ANY, + } + }, + methods: { + mediaImgUploaded(j) { + this.image = j.image + }, + canStartNewGame () { + if (!this.tilesInt || !this.image || ![0, 1].includes(this.scoreModeInt)) { + return false + } + return true + }, + onNewGameClick() { + this.$emit('newGame', { + tiles: this.tilesInt, + image: this.image, + scoreMode: this.scoreModeInt, + }) + }, + }, + computed: { + scoreModeInt () { + return parseInt(this.scoreMode, 10) + }, + tilesInt () { + return parseInt(this.tiles, 10) + }, + }, +} diff --git a/public/views/Index.vue.js b/public/views/Index.vue.js index ba73afb..3999d93 100644 --- a/public/views/Index.vue.js +++ b/public/views/Index.vue.js @@ -1,64 +1,28 @@ "use strict" -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' +import NewGameDialog from './../components/NewGameDialog.vue.js' export default { components: { - Upload, GameTeaser, - ImageTeaser, + NewGameDialog, }, template: `
+ New game + +

Running games

-

New game

- - - - - - - - - - - - - - - - -
- -
- -
- - - or - - - - - (or select from below) - -
- -
- -

Image lib

-
- -
-

Finished games

@@ -66,9 +30,7 @@ export default {
`, data() { return { - tiles: 1000, - image: '', - scoreMode: GameCommon.SCORE_MODE_ANY, + showNewGameDialog: false, gamesRunning: [], gamesFinished: [], @@ -82,20 +44,6 @@ export default { this.gamesFinished = json.gamesFinished this.images = json.images }, - computed: { - scoreModeInt () { - return parseInt(this.scoreMode, 10) - }, - tilesInt () { - return parseInt(this.tiles, 10) - }, - canStartNewGame () { - if (!this.tilesInt || !this.image || ![0, 1].includes(this.scoreModeInt)) { - return false - } - return true - }, - }, methods: { time(start, end) { const icon = end ? '🏁' : '⏳' @@ -104,21 +52,14 @@ export default { const timeDiffStr = Time.timeDiffStr(from, to) return `${icon} ${timeDiffStr}` }, - mediaImgUploaded(j) { - this.image = j.image - }, - async onNewGameClick() { + async onNewGame(gameSettings) { const res = await fetch('/newgame', { method: 'post', headers: { 'Accept': 'application/json', 'Content-Type': 'application/json' }, - body: JSON.stringify({ - tiles: this.tilesInt, - image: this.image, - scoreMode: this.scoreModeInt, - }), + body: JSON.stringify(gameSettings), }) if (res.status === 200) { const game = await res.json()