new migrations in apps.epic for .models additions, incl. Significator select order (= Start Role seat order), which cards of whom go into which deck, which are brought into Sig select; new select-sig urlpattern in .views; room.html supports this stage of game now
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
This commit is contained in:
@@ -10,8 +10,8 @@ from django.utils import timezone
|
||||
|
||||
from apps.drama.models import GameEvent, record
|
||||
from apps.epic.models import (
|
||||
GateSlot, Room, RoomInvite, TableSeat, TarotDeck,
|
||||
debit_token, select_token,
|
||||
GateSlot, Room, RoomInvite, TableSeat, TarotCard, TarotDeck,
|
||||
active_sig_seat, debit_token, select_token, sig_deck_cards, sig_seat_order,
|
||||
)
|
||||
from apps.lyric.models import Token
|
||||
|
||||
@@ -64,6 +64,13 @@ def _notify_role_select_start(room_id):
|
||||
)
|
||||
|
||||
|
||||
def _notify_sig_selected(room_id):
|
||||
async_to_sync(get_channel_layer().group_send)(
|
||||
f'room_{room_id}',
|
||||
{'type': 'sig_selected'},
|
||||
)
|
||||
|
||||
|
||||
def _expire_reserved_slots(room):
|
||||
cutoff = timezone.now() - RESERVE_TIMEOUT
|
||||
room.gate_slots.filter(
|
||||
@@ -187,6 +194,8 @@ def _role_select_context(room, user):
|
||||
ctx["user_seat"] = user_seat
|
||||
ctx["partner_seat"] = partner_seat
|
||||
ctx["revealed_seats"] = room.table_seats.filter(role_revealed=True).order_by("slot_number")
|
||||
ctx["sig_cards"] = sig_deck_cards(room)
|
||||
ctx["sig_seats"] = sig_seat_order(room)
|
||||
return ctx
|
||||
|
||||
|
||||
@@ -468,6 +477,32 @@ def gate_status(request, room_id):
|
||||
return render(request, "apps/gameboard/_partials/_gatekeeper.html", ctx)
|
||||
|
||||
|
||||
@login_required
|
||||
def select_sig(request, room_id):
|
||||
if request.method != "POST":
|
||||
return redirect("epic:gatekeeper", room_id=room_id)
|
||||
room = Room.objects.get(id=room_id)
|
||||
if room.table_status != Room.SIG_SELECT:
|
||||
return redirect("epic:gatekeeper", room_id=room_id)
|
||||
active_seat = active_sig_seat(room)
|
||||
if active_seat is None or active_seat.gamer != request.user:
|
||||
return HttpResponse(status=403)
|
||||
card_id = request.POST.get("card_id")
|
||||
try:
|
||||
card = TarotCard.objects.get(pk=card_id)
|
||||
except TarotCard.DoesNotExist:
|
||||
return HttpResponse(status=400)
|
||||
sig_card_ids = {c.pk for c in sig_deck_cards(room)}
|
||||
if card.pk not in sig_card_ids:
|
||||
return HttpResponse(status=400)
|
||||
if room.table_seats.filter(significator=card).exists():
|
||||
return HttpResponse(status=409)
|
||||
active_seat.significator = card
|
||||
active_seat.save()
|
||||
_notify_sig_selected(room_id)
|
||||
return HttpResponse(status=200)
|
||||
|
||||
|
||||
@login_required
|
||||
def tarot_deck(request, room_id):
|
||||
room = Room.objects.get(id=room_id)
|
||||
|
||||
Reference in New Issue
Block a user