feat: add PlayersStore
This commit is contained in:
parent
608f62a502
commit
600d359a23
25
client/src/components/Lobby.vue
Normal file
25
client/src/components/Lobby.vue
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
<template>
|
||||||
|
<div class="lobby__container">
|
||||||
|
Lobby
|
||||||
|
<div class="lobby__players-list">
|
||||||
|
<div v-for="player in players" :key="player.id" class="lobby__player">
|
||||||
|
* {{ player.name }}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup lang="ts">
|
||||||
|
import { usePlayersStore } from '@/stores/PlayersStore'
|
||||||
|
const players = usePlayersStore().players
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style lang="scss">
|
||||||
|
@import '~/assets/css/components';
|
||||||
|
|
||||||
|
.lobby {
|
||||||
|
&__container {
|
||||||
|
font-family: $font-primary;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</style>
|
@ -1,6 +1,7 @@
|
|||||||
import { useEngineStore } from "@/stores/EngineStore"
|
import { useEngineStore } from "@/stores/EngineStore"
|
||||||
import { useUserinfoStore } from "@/stores/UserinfoStore"
|
import { useUserinfoStore } from "@/stores/UserinfoStore"
|
||||||
import { useGameinfoStore } from "@/stores/GameinfoStore"
|
import { useGameinfoStore } from "@/stores/GameinfoStore"
|
||||||
|
import { usePlayersStore } from "@/stores/PlayersStore"
|
||||||
|
|
||||||
export async function fetchUpdate() {
|
export async function fetchUpdate() {
|
||||||
if (this.shouldStop || !this.isActive) {
|
if (this.shouldStop || !this.isActive) {
|
||||||
@ -28,6 +29,7 @@ export async function fetchUpdate() {
|
|||||||
|
|
||||||
useEngineStore().setJson(response)
|
useEngineStore().setJson(response)
|
||||||
useGameinfoStore().setGameinfo(response.game)
|
useGameinfoStore().setGameinfo(response.game)
|
||||||
|
usePlayersStore().setPlayers(response.game.players)
|
||||||
|
|
||||||
// apply rate limit
|
// apply rate limit
|
||||||
const now = new Date()
|
const now = new Date()
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
</AlertBox>
|
</AlertBox>
|
||||||
<div class="page-play__playfield-container">
|
<div class="page-play__playfield-container">
|
||||||
<div class="page-play__playfield-content">
|
<div class="page-play__playfield-content">
|
||||||
<p>wohoo!</p>
|
<Lobby v-if="true"/>
|
||||||
</div>
|
</div>
|
||||||
<EngineDebug v-if="showEngineDebug" class="page-play__playfield-debug" />
|
<EngineDebug v-if="showEngineDebug" class="page-play__playfield-debug" />
|
||||||
</div>
|
</div>
|
||||||
@ -33,8 +33,8 @@ const { start: startEngine, stop: stopEngine, isConnected, retry } = useEngine()
|
|||||||
onMounted(() => startEngine())
|
onMounted(() => startEngine())
|
||||||
onBeforeUnmount(() => stopEngine())
|
onBeforeUnmount(() => stopEngine())
|
||||||
|
|
||||||
const route = useRoute()
|
// debugging
|
||||||
const showEngineDebug = computed(() => route.hash.indexOf('debug') > -1)
|
const showEngineDebug = computed(() => useRoute().hash.indexOf('debug') > -1)
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style lang="scss">
|
<style lang="scss">
|
||||||
@ -55,7 +55,6 @@ const showEngineDebug = computed(() => route.hash.indexOf('debug') > -1)
|
|||||||
|
|
||||||
&-content {
|
&-content {
|
||||||
flex-grow: 1;
|
flex-grow: 1;
|
||||||
padding: 0 2em;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
&-debug {
|
&-debug {
|
||||||
|
23
client/src/stores/PlayersStore.ts
Normal file
23
client/src/stores/PlayersStore.ts
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
import { defineStore } from 'pinia'
|
||||||
|
|
||||||
|
export type Player = {
|
||||||
|
id: string
|
||||||
|
name: string
|
||||||
|
isIdle: boolean
|
||||||
|
score: number
|
||||||
|
}
|
||||||
|
|
||||||
|
export type Players = Array<Player>
|
||||||
|
|
||||||
|
export const usePlayersStore = defineStore('PlayersStore', {
|
||||||
|
state: () => {
|
||||||
|
return {
|
||||||
|
players: [],
|
||||||
|
}
|
||||||
|
},
|
||||||
|
actions: {
|
||||||
|
setPlayers(players: Players): void {
|
||||||
|
this.players = players
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
Loading…
Reference in New Issue
Block a user