2021-05-17 00:27:47 +02:00
|
|
|
<template>
|
2021-05-13 14:01:10 +02:00
|
|
|
<div>
|
|
|
|
|
<h1>New game</h1>
|
|
|
|
|
<table>
|
|
|
|
|
<tr>
|
|
|
|
|
<td><label>Pieces: </label></td>
|
|
|
|
|
<td><input type="text" v-model="tiles" /></td>
|
|
|
|
|
</tr>
|
|
|
|
|
<tr>
|
|
|
|
|
<td><label>Scoring: </label></td>
|
|
|
|
|
<td>
|
|
|
|
|
<label><input type="radio" v-model="scoreMode" value="1" /> Any (Score when pieces are connected to each other or on final location)</label>
|
|
|
|
|
<br />
|
|
|
|
|
<label><input type="radio" v-model="scoreMode" value="0" /> Final (Score when pieces are put to their final location)</label>
|
|
|
|
|
</td>
|
|
|
|
|
</tr>
|
|
|
|
|
<tr>
|
|
|
|
|
<td><label>Image: </label></td>
|
|
|
|
|
<td>
|
|
|
|
|
<span v-if="image">
|
|
|
|
|
<img :src="image.url" style="width: 150px;" />
|
|
|
|
|
or
|
|
|
|
|
<upload @uploaded="mediaImgUploaded($event)" accept="image/*" label="Upload an image" />
|
|
|
|
|
</span>
|
|
|
|
|
<span v-else>
|
|
|
|
|
<upload @uploaded="mediaImgUploaded($event)" accept="image/*" label="Upload an image" />
|
|
|
|
|
(or select from below)
|
|
|
|
|
</span>
|
|
|
|
|
</td>
|
|
|
|
|
</tr>
|
|
|
|
|
<tr>
|
|
|
|
|
<td colspan="2">
|
2021-05-13 16:23:05 +02:00
|
|
|
<button class="btn" :disabled="!canStartNewGame" @click="onNewGameClick">Start new game</button>
|
2021-05-13 14:01:10 +02:00
|
|
|
</td>
|
|
|
|
|
</tr>
|
|
|
|
|
</table>
|
|
|
|
|
|
|
|
|
|
<h1>Image lib</h1>
|
|
|
|
|
<div>
|
2021-05-17 00:27:47 +02:00
|
|
|
<image-teaser v-for="(i,idx) in images" :image="i" @click="image = i" :key="idx" />
|
2021-05-13 14:01:10 +02:00
|
|
|
</div>
|
2021-05-17 00:27:47 +02:00
|
|
|
</div>
|
|
|
|
|
</template>
|
|
|
|
|
<script lang="ts">
|
|
|
|
|
import { defineComponent } from 'vue'
|
|
|
|
|
|
2021-05-17 02:32:33 +02:00
|
|
|
import { ScoreMode } from './../../common/GameCommon'
|
2021-05-17 00:27:47 +02:00
|
|
|
import Upload from './../components/Upload.vue'
|
|
|
|
|
import ImageTeaser from './../components/ImageTeaser.vue'
|
|
|
|
|
|
|
|
|
|
export default defineComponent({
|
|
|
|
|
name: 'new-game-dialog',
|
|
|
|
|
components: {
|
|
|
|
|
Upload,
|
|
|
|
|
ImageTeaser,
|
|
|
|
|
},
|
2021-05-13 14:01:10 +02:00
|
|
|
props: {
|
|
|
|
|
images: Array,
|
|
|
|
|
},
|
|
|
|
|
emits: {
|
|
|
|
|
newGame: null,
|
|
|
|
|
},
|
|
|
|
|
data() {
|
|
|
|
|
return {
|
|
|
|
|
tiles: 1000,
|
|
|
|
|
image: '',
|
2021-05-17 02:32:33 +02:00
|
|
|
scoreMode: ScoreMode.ANY,
|
2021-05-13 14:01:10 +02:00
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
methods: {
|
2021-05-17 00:27:47 +02:00
|
|
|
// TODO: ts type UploadedImage
|
|
|
|
|
mediaImgUploaded(data: any) {
|
|
|
|
|
this.image = data.image
|
2021-05-13 14:01:10 +02:00
|
|
|
},
|
|
|
|
|
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: {
|
2021-05-17 00:27:47 +02:00
|
|
|
scoreModeInt (): number {
|
|
|
|
|
return parseInt(`${this.scoreMode}`, 10)
|
2021-05-13 14:01:10 +02:00
|
|
|
},
|
2021-05-17 00:27:47 +02:00
|
|
|
tilesInt (): number {
|
|
|
|
|
return parseInt(`${this.tiles}`, 10)
|
2021-05-13 14:01:10 +02:00
|
|
|
},
|
|
|
|
|
},
|
2021-05-17 00:27:47 +02:00
|
|
|
})
|
|
|
|
|
</script>
|