puzzle/src/frontend/views/Replay.vue

170 lines
5 KiB
Vue
Raw Normal View History

2021-05-17 00:27:47 +02:00
<template>
<div id="replay">
2021-05-13 22:45:55 +02:00
<settings-overlay v-show="overlay === 'settings'" @bgclick="toggle('settings', true)" v-model="g.player" />
<preview-overlay v-show="overlay === 'preview'" @bgclick="toggle('preview', false)" :img="g.previewImageUrl" />
<help-overlay v-show="overlay === 'help'" @bgclick="toggle('help', true)" />
<puzzle-status
:finished="finished"
:duration="duration"
:piecesDone="piecesDone"
:piecesTotal="piecesTotal"
>
<div>
<div>{{replayText}}</div>
<div>
<label>Skip no action phases: <input
type="checkbox"
v-model="skipNoAction"
@change="g.replayOnSkipToggle()" /></label>
</div>
2021-05-13 22:45:55 +02:00
<button class="btn" @click="g.replayOnSpeedUp()"></button>
<button class="btn" @click="g.replayOnSpeedDown()"></button>
<button class="btn" @click="g.replayOnPauseToggle()"></button>
</div>
</puzzle-status>
<div class="menu">
<div class="tabs">
<router-link class="opener" :to="{name: 'index'}" target="_blank">🧩 Puzzles</router-link>
<div class="opener" @click="toggle('preview', false)">🖼 Preview</div>
<div class="opener" @click="toggle('settings', true)">🛠 Settings</div>
<div class="opener" @click="toggle('help', true)"> Help</div>
</div>
</div>
<scores :activePlayers="activePlayers" :idlePlayers="idlePlayers" />
2021-05-17 00:27:47 +02:00
</div>
</template>
<script lang="ts">
import { defineComponent } from 'vue'
import Scores from './../components/Scores.vue'
import PuzzleStatus from './../components/PuzzleStatus.vue'
import SettingsOverlay from './../components/SettingsOverlay.vue'
import PreviewOverlay from './../components/PreviewOverlay.vue'
import HelpOverlay from './../components/HelpOverlay.vue'
import { main, MODE_REPLAY } from './../game'
export default defineComponent({
name: 'replay',
components: {
PuzzleStatus,
Scores,
SettingsOverlay,
PreviewOverlay,
HelpOverlay,
},
2021-05-13 16:58:21 +02:00
data() {
return {
2021-05-17 00:27:47 +02:00
activePlayers: [] as Array<any>,
idlePlayers: [] as Array<any>,
2021-05-13 22:45:55 +02:00
finished: false,
duration: 0,
piecesDone: 0,
piecesTotal: 0,
skipNoAction: true,
2021-05-13 22:45:55 +02:00
2021-05-17 00:27:47 +02:00
overlay: '',
connectionState: 0,
2021-05-13 22:45:55 +02:00
g: {
player: {
background: '',
color: '',
name: '',
2021-05-29 23:14:19 +02:00
soundsEnabled: false,
2021-05-13 22:45:55 +02:00
},
previewImageUrl: '',
2021-05-17 00:27:47 +02:00
setHotkeys: (v: boolean) => {},
onBgChange: (v: string) => {},
onColorChange: (v: string) => {},
onNameChange: (v: string) => {},
2021-05-29 23:14:19 +02:00
onSoundsEnabledChange: (v: boolean) => {},
2021-05-13 22:45:55 +02:00
replayOnSpeedUp: () => {},
replayOnSpeedDown: () => {},
replayOnPauseToggle: () => {},
replayOnSkipToggle: () => {},
2021-06-05 08:58:20 +02:00
connect: () => {},
2021-05-13 22:45:55 +02:00
disconnect: () => {},
2021-06-05 08:58:20 +02:00
unload: () => {},
2021-05-13 22:45:55 +02:00
},
replay: {
speed: 1,
paused: false,
},
2021-05-13 16:58:21 +02:00
}
},
2021-05-13 22:45:55 +02:00
async mounted() {
if (!this.$route.params.id) {
return
}
2021-05-17 00:27:47 +02:00
this.$watch(() => this.g.player.background, (value: string) => {
2021-05-13 22:45:55 +02:00
this.g.onBgChange(value)
})
2021-05-17 00:27:47 +02:00
this.$watch(() => this.g.player.color, (value: string) => {
2021-05-13 22:45:55 +02:00
this.g.onColorChange(value)
})
2021-05-17 00:27:47 +02:00
this.$watch(() => this.g.player.name, (value: string) => {
2021-05-13 22:45:55 +02:00
this.g.onNameChange(value)
})
2021-05-29 23:14:19 +02:00
this.$watch(() => this.g.player.soundsEnabled, (value: boolean) => {
this.g.onSoundsEnabledChange(value)
})
2021-05-13 22:45:55 +02:00
this.g = await main(
2021-05-17 00:27:47 +02:00
`${this.$route.params.id}`,
// @ts-ignore
this.$clientId,
2021-05-17 00:27:47 +02:00
// @ts-ignore
2021-05-13 22:45:55 +02:00
this.$config.WS_ADDRESS,
MODE_REPLAY,
this.$el,
{
2021-05-17 00:27:47 +02:00
setActivePlayers: (v: Array<any>) => { this.activePlayers = v },
setIdlePlayers: (v: Array<any>) => { this.idlePlayers = v },
setFinished: (v: boolean) => { this.finished = v },
setDuration: (v: number) => { this.duration = v },
setPiecesDone: (v: number) => { this.piecesDone = v },
setPiecesTotal: (v: number) => { this.piecesTotal = v },
2021-05-13 22:45:55 +02:00
togglePreview: () => { this.toggle('preview', false) },
2021-05-17 00:27:47 +02:00
setConnectionState: (v: number) => { this.connectionState = v },
setReplaySpeed: (v: number) => { this.replay.speed = v },
setReplayPaused: (v: boolean) => { this.replay.paused = v },
2021-05-29 23:14:19 +02:00
toggleSoundsEnabled: () => { this.g.player.soundsEnabled = !this.g.player.soundsEnabled },
2021-05-13 22:45:55 +02:00
}
2021-05-13 16:58:21 +02:00
)
},
2021-05-13 22:45:55 +02:00
unmounted () {
2021-06-05 08:58:20 +02:00
this.g.unload()
2021-05-13 22:45:55 +02:00
this.g.disconnect()
},
2021-05-13 16:58:21 +02:00
methods: {
2021-05-17 00:27:47 +02:00
toggle(overlay: string, affectsHotkeys: boolean): void {
if (this.overlay === '') {
2021-05-13 22:45:55 +02:00
this.overlay = overlay
if (affectsHotkeys) {
this.g.setHotkeys(false)
}
} else {
// could check if overlay was the provided one
2021-05-17 00:27:47 +02:00
this.overlay = ''
2021-05-13 22:45:55 +02:00
if (affectsHotkeys) {
this.g.setHotkeys(true)
}
}
2021-05-13 16:58:21 +02:00
},
},
2021-05-17 00:27:47 +02:00
computed: {
replayText (): string {
return 'Replay-Speed: ' +
(this.replay.speed + 'x') +
(this.replay.paused ? ' Paused' : '')
},
},
})
</script>