commit #5
This commit is contained in:
parent
b76bca9c57
commit
14c4a434f7
6 changed files with 42 additions and 28 deletions
|
@ -3,6 +3,8 @@
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
"start:ui": "vite preview --host",
|
||||||
|
"build:ui": "vite build",
|
||||||
"dev:ui": "vite",
|
"dev:ui": "vite",
|
||||||
"dev:server": "NODE_ENV=development tsx watch --clear-screen=false ./src/server/main.ts"
|
"dev:server": "NODE_ENV=development tsx watch --clear-screen=false ./src/server/main.ts"
|
||||||
},
|
},
|
||||||
|
|
|
@ -25,7 +25,6 @@ export const useGame = defineStore("game", () => {
|
||||||
const actions = reactive<GameAction[]>([])
|
const actions = reactive<GameAction[]>([])
|
||||||
|
|
||||||
const auth = useAuth()
|
const auth = useAuth()
|
||||||
|
|
||||||
const actionsBus = useGameActionsBus()
|
const actionsBus = useGameActionsBus()
|
||||||
actionsBus.on(action => {
|
actionsBus.on(action => {
|
||||||
actions.push(action)
|
actions.push(action)
|
||||||
|
@ -60,11 +59,15 @@ export const useGame = defineStore("game", () => {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
async create() {
|
async reset() {
|
||||||
return await trpcClient.createGame.mutate()
|
window.location.hash = ""
|
||||||
|
lobbyCode.value = null
|
||||||
|
state.value = getUninitializedGameState()
|
||||||
|
actions.splice(0, actions.length)
|
||||||
},
|
},
|
||||||
start: () => trpcClient.game.start.mutate({ lobbyCode: lobbyCode.value! }),
|
start: () => trpcClient.game.start.mutate({ lobbyCode: lobbyCode.value! }),
|
||||||
hit: () => trpcClient.game.hit.mutate({ lobbyCode: lobbyCode.value! }),
|
hit: () => trpcClient.game.hit.mutate({ lobbyCode: lobbyCode.value! }),
|
||||||
stay: () => trpcClient.game.stay.mutate({ lobbyCode: lobbyCode.value! })
|
stay: () => trpcClient.game.stay.mutate({ lobbyCode: lobbyCode.value! }),
|
||||||
|
create: () => trpcClient.createGame.mutate()
|
||||||
}
|
}
|
||||||
})
|
})
|
|
@ -1,27 +1,34 @@
|
||||||
<template>
|
<template>
|
||||||
<div class="flex flex-col gap-14">
|
<div class="flex flex-col gap-14">
|
||||||
<PlayerCards v-for="playerId in reorderedPlayerIds" :key="playerId" :player-id="playerId"/>
|
<PlayerCards v-for="playerId in reorderedPlayerIds" :key="playerId" :player-id="playerId"/>
|
||||||
<div
|
<div class="flex gap-5 justify-end items-center transform transition ease duration-500">
|
||||||
class="flex gap-5 justify-end items-center transform transition ease duration-500"
|
<template v-if="game.state.phase === 'end'">
|
||||||
:class="game.state.phase === 'end' ? 'translate-y-4 opacity-0' : ''"
|
<BigButton
|
||||||
>
|
class="bg-gradient-to-br from-gray-600 to-gray-800"
|
||||||
<div class="font-fat opacity-20 text-3xl pr-2">
|
@click="game.reset()"
|
||||||
<template v-if="isBust">You are bust.</template>
|
>
|
||||||
</div>
|
Leave
|
||||||
<BigButton
|
</BigButton>
|
||||||
class="bg-gradient-to-br from-red-800 to-red-900 uppercase"
|
</template>
|
||||||
:disabled="!isYourTurn || isBust"
|
<template v-else>
|
||||||
@click="game.hit()"
|
<div class="font-fat opacity-20 text-3xl pr-2">
|
||||||
>
|
<template v-if="isBust">You are bust.</template>
|
||||||
Hit
|
</div>
|
||||||
</BigButton>
|
<BigButton
|
||||||
<BigButton
|
class="bg-gradient-to-br from-red-800 to-red-900 uppercase"
|
||||||
class="bg-gradient-to-br from-blue-800 to-blue-900 uppercase"
|
:disabled="!isYourTurn || isBust"
|
||||||
:disabled="!isYourTurn"
|
@click="game.hit()"
|
||||||
@click="game.stay()"
|
>
|
||||||
>
|
Hit
|
||||||
Stay
|
</BigButton>
|
||||||
</BigButton>
|
<BigButton
|
||||||
|
class="bg-gradient-to-br from-blue-800 to-blue-900 uppercase"
|
||||||
|
:disabled="!isYourTurn"
|
||||||
|
@click="game.stay()"
|
||||||
|
>
|
||||||
|
Stay
|
||||||
|
</BigButton>
|
||||||
|
</template>
|
||||||
</div>
|
</div>
|
||||||
<GameEndModal/>
|
<GameEndModal/>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -40,10 +40,11 @@
|
||||||
const usernameInput = ref("")
|
const usernameInput = ref("")
|
||||||
const isLoading = ref(false)
|
const isLoading = ref(false)
|
||||||
|
|
||||||
function submit() {
|
async function submit() {
|
||||||
if (isLoading.value) return
|
if (isLoading.value) return
|
||||||
isLoading.value = true
|
isLoading.value = true
|
||||||
auth.login(usernameInput.value)
|
await auth.login(usernameInput.value)
|
||||||
|
window.location.reload() // so that the WebSocket reconnects with the cookie set
|
||||||
isLoading.value = false
|
isLoading.value = false
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
|
@ -85,6 +85,7 @@ export class Game extends EventEmitter<Events> {
|
||||||
|
|
||||||
addPlayer(id: string, name: string) {
|
addPlayer(id: string, name: string) {
|
||||||
if (this.lobbyPlayerIds.has(id)) return
|
if (this.lobbyPlayerIds.has(id)) return
|
||||||
|
if (this.state.phase !== "pre-start") throw new Error("The game was already started.")
|
||||||
if (this.lobbyPlayerIds.size >= 3) throw new Error("The game is full.")
|
if (this.lobbyPlayerIds.size >= 3) throw new Error("The game is full.")
|
||||||
this.lobbyPlayerIds.add(id)
|
this.lobbyPlayerIds.add(id)
|
||||||
this.addAction({
|
this.addAction({
|
||||||
|
|
|
@ -15,7 +15,7 @@ export const trpcClient = createTRPCProxyClient<AppRouter>({
|
||||||
splitLink({
|
splitLink({
|
||||||
condition: o => o.type === "subscription",
|
condition: o => o.type === "subscription",
|
||||||
true: wsLink({
|
true: wsLink({
|
||||||
client: wsClient,
|
client: wsClient
|
||||||
}),
|
}),
|
||||||
false: httpLink({
|
false: httpLink({
|
||||||
url: "/trpc"
|
url: "/trpc"
|
||||||
|
|
Loading…
Add table
Reference in a new issue