-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* migrate a couple components over to composition
- Loading branch information
1 parent
0e49079
commit 6032e81
Showing
5 changed files
with
145 additions
and
180 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,52 +1,49 @@ | ||
<script setup lang="ts"> | ||
import ClickMp3 from '@/assets/audio/click2.mp3'; | ||
import { AudioWrap } from '@/mixins/audiowrap.js'; | ||
import { computed } from 'vue'; | ||
import { useGameStore } from '@/stores/game.js'; | ||
import { useI18n } from 'vue-i18n'; | ||
const click = new AudioWrap(ClickMp3); | ||
const gameStore = useGameStore(); | ||
const rank = computed((): number[] => { | ||
let result = []; | ||
let lastScore = -1; | ||
let lastRank = 1; | ||
for (const [rank, score] of gameStore.scores.entries()) { | ||
if (score.points < lastScore) { | ||
result.push(rank + 1); | ||
lastRank = rank + 1; | ||
} else { | ||
result.push(lastRank); | ||
} | ||
lastScore = score.points; | ||
} | ||
return result; | ||
}); | ||
function toLobby() { | ||
click.play(); | ||
gameStore.setScene('Lobby'); | ||
} | ||
const { n } = useI18n(); | ||
</script> | ||
|
||
<template> | ||
<div class="w-100 d-flex flex-column justify-content-start align-items-center gap-3 py-3 px-4"> | ||
<h1 v-t="'playerScores'" class="mt-2 text-center display-1 text-red font-fancy" /> | ||
|
||
<div class="list-group w-75 w-xl-50"> | ||
<div v-for="(score, index) in scores" :key="score.player.id" class="list-group-item"> | ||
{{ rank[index] }}. {{ score.player.name }}: {{ $n(score.points) }} | ||
<div v-for="(score, index) in gameStore.scores" :key="score.player.id" class="list-group-item"> | ||
{{ rank[index] }}. {{ score.player.name }}: {{ n(score.points) }} | ||
</div> | ||
</div> | ||
|
||
<div class="flex-grow-1" /> | ||
<button v-t="'toLobby'" class="btn btn-blue w-75 w-lg-50 fs-4 mb-4" @click="toLobby" /> | ||
</div> | ||
</template> | ||
|
||
<script lang="ts"> | ||
import { mapActions, mapState } from 'pinia'; | ||
import ClickMp3 from '@/assets/audio/click2.mp3'; | ||
import { AudioWrap } from '@/mixins/audiowrap.js'; | ||
import { useGameStore } from '@/stores/game.js'; | ||
import { defineComponent } from 'vue'; | ||
const click = new AudioWrap(ClickMp3); | ||
export default defineComponent({ | ||
computed: { | ||
...mapState(useGameStore, ['scores']), | ||
rank() { | ||
let result = []; | ||
let lastScore = -1; | ||
let lastRank = 1; | ||
for (const [rank, score] of this.scores.entries()) { | ||
if (score.points < lastScore) { | ||
result.push(rank + 1); | ||
lastRank = rank + 1; | ||
} else { | ||
result.push(lastRank); | ||
} | ||
lastScore = score.points; | ||
} | ||
return result; | ||
} | ||
}, | ||
methods: { | ||
...mapActions(useGameStore, ['setScene']), | ||
toLobby() { | ||
click.play(); | ||
this.setScene('Lobby'); | ||
} | ||
} | ||
}); | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,68 +1,57 @@ | ||
<script setup lang="ts"> | ||
import { onMounted, ref, watch } from 'vue'; | ||
import { AudioWrap } from '@/mixins/audiowrap.js'; | ||
import ClickMp3 from '@/assets/audio/click2.mp3'; | ||
import socket from '@/socket/socket.js'; | ||
import { useRoomStore } from '@/stores/room.js'; | ||
import { useGameStore } from '@/stores/game.js'; | ||
import NotificationCount from '@/components/gameShared/NotificationCount.vue'; | ||
import PlayerChooser from '@/components/endRound/PlayerChooser.vue'; | ||
import ResponseList from '@/components/gameShared/ResponseList.vue'; | ||
import Prompt from '@/components/gameShared/Prompt.vue'; | ||
import { useI18n } from 'vue-i18n'; | ||
const roomStore = useRoomStore(); | ||
const gameStore = useGameStore(); | ||
const responsesId = ref(''); | ||
const selectedId = ref(''); | ||
watch(selectedId, async (val: string) => { | ||
if (val) { | ||
await gameStore.getResponses(val).then(() => { | ||
responsesId.value = val; | ||
}); | ||
} | ||
}); | ||
onMounted(() => { | ||
selectedId.value = roomStore.self!.id; | ||
}); | ||
function sendVote() { | ||
new AudioWrap(ClickMp3).play(); | ||
socket.emit('pollVote', 'startNextRound'); | ||
} | ||
const { t, n } = useI18n(); | ||
</script> | ||
|
||
<template> | ||
<div class="w-100 d-flex flex-column justify-content-between align-items-center py-3 px-4"> | ||
<prompt :prompt="prompt" /> | ||
<prompt :prompt="gameStore.prompt" /> | ||
<response-list :selectable="false" :height="45" :player-id="responsesId" /> | ||
<player-chooser v-model="selectedId" class="w-50 w-lg-25 fs-4 mb-3" /> | ||
<button | ||
class="btn btn-orange w-75 w-lg-50 w-xl-25 fs-4 mb-3 position-relative" | ||
:class="{ 'btn-blue': !startNextRoundNext }" | ||
:class="{ 'btn-blue': !gameStore.startNextRoundNext }" | ||
@click="sendVote"> | ||
{{ hasNextRound ? $t('startNextRound') : $t('viewResults') }} | ||
<notification-count v-if="startNextRoundCount" class="position-absolute top-0 start-100 translate-middle fs-6"> | ||
{{ $n(startNextRoundCount) }} | ||
{{ gameStore.hasNextRound ? t('startNextRound') : t('viewResults') }} | ||
<notification-count | ||
v-if="gameStore.startNextRoundCount" | ||
class="position-absolute top-0 start-100 translate-middle fs-6"> | ||
{{ n(gameStore.startNextRoundCount) }} | ||
</notification-count> | ||
</button> | ||
</div> | ||
</template> | ||
|
||
<script lang="ts"> | ||
import Prompt from '@/components/gameShared/Prompt.vue'; | ||
import ResponseList from '@/components/gameShared/ResponseList.vue'; | ||
import NotificationCount from '@/components/gameShared/NotificationCount.vue'; | ||
import ClickMp3 from '@/assets/audio/click2.mp3'; | ||
import PlayerChooser from '@/components/endRound/PlayerChooser.vue'; | ||
import { AudioWrap } from '@/mixins/audiowrap.js'; | ||
import socket from '@/socket/socket'; | ||
import { useGameStore } from '@/stores/game.js'; | ||
import { useRoomStore } from '@/stores/room.js'; | ||
import { mapState, mapActions } from 'pinia'; | ||
import { defineComponent } from 'vue'; | ||
export default defineComponent({ | ||
components: { | ||
PlayerChooser, | ||
Prompt, | ||
ResponseList, | ||
NotificationCount | ||
}, | ||
data() { | ||
return { | ||
responsesId: '', | ||
selectedId: '' | ||
}; | ||
}, | ||
computed: { | ||
...mapState(useGameStore, ['prompt', 'hasNextRound', 'startNextRoundCount', 'startNextRoundNext']), | ||
...mapState(useRoomStore, ['self']) | ||
}, | ||
watch: { | ||
selectedId(val: string) { | ||
if (val) { | ||
void this.getResponses(val).then(() => { | ||
this.responsesId = val; | ||
}); | ||
} | ||
} | ||
}, | ||
mounted() { | ||
this.selectedId = this.self!.id; | ||
}, | ||
methods: { | ||
sendVote() { | ||
new AudioWrap(ClickMp3).play(); | ||
socket.emit('pollVote', 'startNextRound'); | ||
}, | ||
...mapActions(useGameStore, ['getResponses']) | ||
} | ||
}); | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters