Feat: start game

This commit is contained in:
Grail Finder
2025-05-09 11:54:01 +03:00
parent 2b4bf2ec29
commit 45761446e5
4 changed files with 57 additions and 1 deletions

View File

@ -161,3 +161,27 @@ func HandleEndTurn(w http.ResponseWriter, r *http.Request) {
}
tmpl.ExecuteTemplate(w, "base", fi)
}
func HandleStartGame(w http.ResponseWriter, r *http.Request) {
fi, err := getFullInfoByCtx(r.Context())
if err != nil {
abortWithError(w, err.Error())
return
}
// TODO: check if enough players; also button should be hidden if already running
fi.Room.IsRunning = true
fi.Room.IsOver = false
fi.Room.TeamTurn = "blue"
fi.Room.LoadTestCards()
if err := saveFullInfo(fi); err != nil {
abortWithError(w, err.Error())
return
}
// return html
tmpl, err := template.ParseGlob("components/*.html")
if err != nil {
abortWithError(w, err.Error())
return
}
tmpl.ExecuteTemplate(w, "room", fi)
}