collect quotes status added

This commit is contained in:
Settel 2021-10-01 16:40:07 +02:00
parent d783ceba93
commit b24f222533
12 changed files with 80 additions and 6 deletions

View File

@ -1,4 +1,4 @@
TMUX_SESSION=knyt
TMUX_SESSION=knowyt
info:
@echo available targets:

View File

@ -0,0 +1,18 @@
<template>
<div class="collect-quotes">
<p>collecting ...</p>
</div>
</template>
<script>
export default {
}
</script>
<style lang="scss">
.collect-quotes {
font-family: 'Wendy One';
color: #ffffff;
}
</style>

View File

@ -1,5 +1,6 @@
<template>
<nav v-if="isGamemaster" class="gamecontrols">
<button @click="collectQuotes">Collect Quotes</button>
<button @click="startGame">Start</button>
<button @click="continueGame">Continue</button>
<button @click="resetGame">Reset Round</button>
@ -19,6 +20,9 @@ export default {
},
},
methods: {
collectQuotes() {
this.$engine.collectQuotes()
},
startGame() {
this.$engine.startGame()
},

View File

@ -11,6 +11,7 @@
</div>
<ReadySet v-if="gameState === 'ready-set'" :text="gamePhase" />
<Play v-if="gameState === 'play'" />
<CollectQuotes v-if="gameState === 'collect'" />
<Final v-if="gameState === 'final'" />
</div>
</div>

View File

@ -0,0 +1,7 @@
export default async function() {
const { store } = this.context
await this.callApi('/api/collectQuotes', {
g: store.state.engine.user?.game,
})
}

View File

@ -3,6 +3,7 @@ import start from './start'
import stop from './stop'
import fetchUpdate from './fetchUpdate'
import fetchUserInfo from './fetchUserInfo'
import collectQuotes from './collectQuotes'
import startGame from './startGame'
import resetGame from './resetGame'
import continueGame from './continueGame'
@ -22,6 +23,7 @@ export default (context, inject) => {
stop,
fetchUpdate,
fetchUserInfo,
collectQuotes,
startGame,
resetGame,
continueGame,

View File

@ -3,10 +3,10 @@ info:
@perl -ne 'm/^([a-zA-Z0-9\-]+):/ && print(" $$1\n");' Makefile
build:
cd src/ && go build -o ../knyt knyt.go
cd src/ && go build -o ../knowyt knowyt.go
run:
cd src/ && go run knyt.go
cd src/ && go run knowyt.go
run-loop:
pexec -R -c -e TARGET \
@ -15,7 +15,7 @@ run-loop:
-- $(MAKE) '$$TARGET'
run-standalone:
cd src/ && ../knyt
cd src/ && ../knowyt
_run-endless-loop:
while true; do $(MAKE) run || sleep 3; done

View File

@ -0,0 +1,25 @@
package application
import (
"fmt"
"net/http"
"sirlab.de/go/knyt/user"
)
func (app *Application) CollectQuotes(usr *user.User, w http.ResponseWriter, r *http.Request) {
gameRef := r.URL.Query().Get("g")
gm, err := app.GetGameById(gameRef)
if err != nil {
w.WriteHeader(http.StatusNotFound)
fmt.Fprintf(w, "game not found")
return
}
if usr.GetGameId() != gameRef || !usr.IsGamemaster() {
w.WriteHeader(http.StatusForbidden)
fmt.Fprintf(w, "forbidden")
return
}
gm.CollectQuotes()
}

View File

@ -0,0 +1,15 @@
package game
import (
"fmt"
)
func (gm *Game) CollectQuotes() {
err := gm.changeGameState(STATE_ANY, STATE_COLLECT, PHASE_NONE)
if err != nil {
fmt.Println(err)
return
}
gm.notifyClients()
}

View File

@ -6,8 +6,8 @@ import (
func (gm *Game) runRound() {
state, _ := gm.GetState()
if state != STATE_IDLE && state != STATE_PLAY {
fmt.Println(fmt.Errorf("expected state \"IDLE\" | \"PLAY\" != \"%s\"", state))
if state != STATE_IDLE && state != STATE_PLAY && state != STATE_COLLECT {
fmt.Println(fmt.Errorf("expected state \"IDLE\" | \"PLAY\" | \"COLLECT\" != \"%s\"", state))
return
}

View File

@ -8,6 +8,7 @@ import (
const (
STATE_ANY = "*"
STATE_COLLECT = "collect"
STATE_IDLE = "idle"
STATE_READY_SET = "ready-set"
STATE_PLAY = "play"

View File

@ -23,6 +23,7 @@ func main() {
mux.PublicHandleFunc("/api/logout", mux.Logout)
mux.PrivateHandleFunc("/api/userinfo", mux.GetUserInfo)
mux.PrivateHandleFunc("/api/sync", app.SyncHandler)
mux.PrivateHandleFunc("/api/collectQuotes", app.CollectQuotes)
mux.PrivateHandleFunc("/api/startGame", app.StartGame)
mux.PrivateHandleFunc("/api/resetGame", app.ResetGame)
mux.PrivateHandleFunc("/api/continueGame", app.ContinueGame)