2020-11-25 22:03:35 +01:00
|
|
|
|
const Upload = {
|
|
|
|
|
|
name: 'upload',
|
|
|
|
|
|
props: {
|
|
|
|
|
|
accept: String,
|
|
|
|
|
|
label: String,
|
|
|
|
|
|
},
|
|
|
|
|
|
template: `
|
|
|
|
|
|
<label>
|
|
|
|
|
|
<input type="file" style="display: none" @change="upload" :accept="accept" />
|
|
|
|
|
|
<span class="btn">{{label || 'Upload File'}}</span>
|
|
|
|
|
|
</label>
|
|
|
|
|
|
`,
|
|
|
|
|
|
methods: {
|
|
|
|
|
|
async upload(evt) {
|
|
|
|
|
|
const file = evt.target.files[0]
|
|
|
|
|
|
if (!file) return;
|
|
|
|
|
|
const formData = new FormData();
|
|
|
|
|
|
formData.append('file', file, file.name);
|
|
|
|
|
|
const res = await fetch('/upload', {
|
|
|
|
|
|
method: 'post',
|
|
|
|
|
|
body: formData,
|
2020-11-17 21:46:56 +01:00
|
|
|
|
})
|
2020-11-25 22:03:35 +01:00
|
|
|
|
const j = await res.json()
|
|
|
|
|
|
this.$emit('uploaded', j)
|
|
|
|
|
|
},
|
2020-11-17 21:46:56 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-12-06 21:55:23 +01:00
|
|
|
|
|
|
|
|
|
|
export const timestamp = () => {
|
|
|
|
|
|
const d = new Date();
|
|
|
|
|
|
return Date.UTC(
|
|
|
|
|
|
d.getUTCFullYear(),
|
|
|
|
|
|
d.getUTCMonth(),
|
|
|
|
|
|
d.getUTCDate(),
|
|
|
|
|
|
d.getUTCHours(),
|
|
|
|
|
|
d.getUTCMinutes(),
|
|
|
|
|
|
d.getUTCSeconds(),
|
|
|
|
|
|
d.getUTCMilliseconds(),
|
|
|
|
|
|
)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-11-25 22:03:35 +01:00
|
|
|
|
export default {
|
|
|
|
|
|
components: {
|
|
|
|
|
|
Upload,
|
|
|
|
|
|
},
|
|
|
|
|
|
props: {
|
|
|
|
|
|
games: Array,
|
|
|
|
|
|
images: Array,
|
|
|
|
|
|
},
|
|
|
|
|
|
template: `
|
|
|
|
|
|
<div id="app">
|
|
|
|
|
|
<h1>Running games</h1>
|
2020-12-06 21:55:23 +01:00
|
|
|
|
<div class="game-teaser-wrap" v-for="g in games">
|
|
|
|
|
|
<div class="game-teaser" :style="'background-image: url('+g.imageUrl+')'">
|
|
|
|
|
|
<a class="game-info" :href="'/g/' + g.id">
|
|
|
|
|
|
<span class="game-info-text">
|
|
|
|
|
|
🧩 {{g.tilesFinished}}/{{g.tilesTotal}}<br />
|
|
|
|
|
|
👥 {{g.players}}<br />
|
|
|
|
|
|
{{time(g.started, g.finished)}}<br />
|
|
|
|
|
|
</span>
|
|
|
|
|
|
</a>
|
2020-12-22 22:54:31 +01:00
|
|
|
|
<a v-if="g.hasReplay" class="game-replay" :href="'/replay/' + g.id">
|
|
|
|
|
|
↪️ Watch replay
|
|
|
|
|
|
</a>
|
2020-12-06 21:55:23 +01:00
|
|
|
|
</div>
|
2020-11-25 22:03:35 +01:00
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
<h1>New game</h1>
|
|
|
|
|
|
<div>
|
2020-12-05 19:45:34 +01:00
|
|
|
|
<label>Pieces: </label>
|
2020-11-25 22:03:35 +01:00
|
|
|
|
<input type="text" v-model="tiles" />
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<div>
|
|
|
|
|
|
<label>Image: </label>
|
|
|
|
|
|
<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>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<span class="btn" :class="" @click="newGame">Start new game</span>
|
|
|
|
|
|
|
|
|
|
|
|
<h1>Image lib</h1>
|
|
|
|
|
|
<div>
|
|
|
|
|
|
<img
|
|
|
|
|
|
v-for="i in images"
|
|
|
|
|
|
:src="i.url"
|
|
|
|
|
|
@click="image = i"
|
|
|
|
|
|
style="width: 150px; display: inline-block; margin: 5px;"
|
|
|
|
|
|
/>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>`,
|
|
|
|
|
|
data() {
|
|
|
|
|
|
return {
|
|
|
|
|
|
tiles: 1000,
|
|
|
|
|
|
image: '',
|
2020-11-08 12:56:54 +01:00
|
|
|
|
}
|
2020-11-25 22:03:35 +01:00
|
|
|
|
},
|
|
|
|
|
|
methods: {
|
2020-12-06 21:55:23 +01:00
|
|
|
|
time(start, end) {
|
|
|
|
|
|
const icon = end ? '🏁' : '⏳'
|
|
|
|
|
|
|
|
|
|
|
|
const from = start;
|
|
|
|
|
|
const to = end || timestamp()
|
|
|
|
|
|
|
|
|
|
|
|
const MS = 1
|
|
|
|
|
|
const SEC = MS * 1000
|
|
|
|
|
|
const MIN = SEC * 60
|
|
|
|
|
|
const HOUR = MIN * 60
|
|
|
|
|
|
const DAY = HOUR * 24
|
|
|
|
|
|
|
|
|
|
|
|
let diff = to - from
|
|
|
|
|
|
const d = Math.floor(diff / DAY)
|
|
|
|
|
|
diff = diff % DAY
|
|
|
|
|
|
|
|
|
|
|
|
const h = Math.floor(diff / HOUR)
|
|
|
|
|
|
diff = diff % HOUR
|
|
|
|
|
|
|
|
|
|
|
|
const m = Math.floor(diff / MIN)
|
|
|
|
|
|
diff = diff % MIN
|
|
|
|
|
|
|
|
|
|
|
|
const s = Math.floor(diff / SEC)
|
|
|
|
|
|
|
|
|
|
|
|
return `${icon} ${d}d ${h}h ${m}m ${s}s`
|
|
|
|
|
|
},
|
2020-11-25 22:03:35 +01:00
|
|
|
|
mediaImgUploaded(j) {
|
|
|
|
|
|
this.image = j.image
|
|
|
|
|
|
},
|
|
|
|
|
|
async newGame() {
|
|
|
|
|
|
const res = await fetch('/newgame', {
|
|
|
|
|
|
method: 'post',
|
|
|
|
|
|
headers: {
|
|
|
|
|
|
'Accept': 'application/json',
|
|
|
|
|
|
'Content-Type': 'application/json'
|
|
|
|
|
|
},
|
|
|
|
|
|
body: JSON.stringify({tiles: this.tiles, image: this.image}),
|
2020-11-10 18:48:16 +01:00
|
|
|
|
})
|
2020-11-25 22:03:35 +01:00
|
|
|
|
if (res.status === 200) {
|
|
|
|
|
|
const game = await res.json()
|
|
|
|
|
|
location.assign(game.url)
|
2020-11-19 12:38:50 +01:00
|
|
|
|
}
|
2020-11-09 01:54:05 +01:00
|
|
|
|
}
|
2020-11-07 11:35:29 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|