Fixes and updates
This commit is contained in:
@@ -36,8 +36,11 @@ def home(request: Request):
|
||||
return templates.TemplateResponse("index.html", {"request": request})
|
||||
|
||||
@app.post("/game/create")
|
||||
def create_game_route(db: Session = Depends(get_session)):
|
||||
game = crud.create_game(db)
|
||||
def create_game_route(
|
||||
crew_name: str = Form(...),
|
||||
db: Session = Depends(get_session)
|
||||
):
|
||||
game = crud.create_game(db, crew_name=crew_name.strip())
|
||||
# Redirect creator to the join page with creator flag
|
||||
return RedirectResponse(url=f"/game/{game.id}/join?creator=true", status_code=status.HTTP_303_SEE_OTHER)
|
||||
|
||||
@@ -194,6 +197,13 @@ def get_game_phase_view(
|
||||
inbox_tasks.append({"player": p, "type": "like"})
|
||||
if p.other_hate_from_player_id == player.id and not p.other_hate:
|
||||
inbox_tasks.append({"player": p, "type": "hate"})
|
||||
|
||||
# Freshly fetch votes to avoid cache stale
|
||||
from sqlmodel import select
|
||||
votes = db.exec(select(Vote).where(Vote.game_id == game_id)).all()
|
||||
|
||||
# Calculate eligible deep players
|
||||
eligible_deeps = [p for p in game.players if p.previous_role != "deep"]
|
||||
|
||||
context = {
|
||||
"request": request,
|
||||
@@ -210,7 +220,9 @@ def get_game_phase_view(
|
||||
"json_loads": json.loads,
|
||||
"deck_count": len(crud.get_game_deck(game)),
|
||||
"inbox_tasks": inbox_tasks,
|
||||
"edit_mode": edit
|
||||
"votes": votes,
|
||||
"edit_mode": edit,
|
||||
"eligible_deeps": eligible_deeps
|
||||
}
|
||||
|
||||
# Select template based on current game phase
|
||||
@@ -224,6 +236,8 @@ def get_game_phase_view(
|
||||
return templates.TemplateResponse("scene_partial.html", context)
|
||||
elif game.phase == "between_scenes":
|
||||
return templates.TemplateResponse("between_scenes_partial.html", context)
|
||||
elif game.phase == "deep_upkeep":
|
||||
return templates.TemplateResponse("deep_upkeep_partial.html", context)
|
||||
|
||||
return HTMLResponse("<p>Unknown game state.</p>")
|
||||
|
||||
@@ -613,7 +627,7 @@ def submit_vote_route(
|
||||
db: Session = Depends(get_session)
|
||||
):
|
||||
crud.submit_rank_vote(db, game_id, player_id, nominated_id)
|
||||
return HTMLResponse(status_code=204)
|
||||
return RedirectResponse(url=f"/game/{game_id}/player/{player_id}/view", status_code=status.HTTP_303_SEE_OTHER)
|
||||
|
||||
# 16. Player Ready for Next Scene
|
||||
@app.post("/game/{game_id}/player/{player_id}/ready-next")
|
||||
@@ -626,12 +640,27 @@ def ready_next_route(game_id: str, player_id: str, db: Session = Depends(get_ses
|
||||
db.add(player)
|
||||
db.commit()
|
||||
|
||||
# Check if all players in the game are ready. If so, transition to next scene!
|
||||
# Check if all players in the game are ready. If so, transition to deep upkeep!
|
||||
game = crud.get_game(db, game_id)
|
||||
if game and all(p.is_ready for p in game.players):
|
||||
crud.proceed_to_next_scene_setup(db, game_id)
|
||||
crud.transition_to_deep_upkeep(db, game_id)
|
||||
|
||||
return HTMLResponse(status_code=204)
|
||||
return RedirectResponse(url=f"/game/{game_id}/player/{player_id}/view", status_code=status.HTTP_303_SEE_OTHER)
|
||||
|
||||
# 17. Confirm Hand Refresh for Deep player
|
||||
@app.post("/game/{game_id}/player/{player_id}/confirm-refresh")
|
||||
def confirm_deep_refresh_route(
|
||||
game_id: str,
|
||||
player_id: str,
|
||||
discard_cards: str = Form("[]"),
|
||||
db: Session = Depends(get_session)
|
||||
):
|
||||
try:
|
||||
discards = json.loads(discard_cards)
|
||||
except Exception:
|
||||
discards = []
|
||||
crud.confirm_deep_refresh(db, player_id, discards)
|
||||
return RedirectResponse(url=f"/game/{game_id}/player/{player_id}/view", status_code=status.HTTP_303_SEE_OTHER)
|
||||
|
||||
def main():
|
||||
import argparse
|
||||
|
||||
Reference in New Issue
Block a user