change callback to filter by player instead of client

This commit is contained in:
2024-04-20 09:20:33 +02:00
parent 792f18e274
commit e400a7e770
6 changed files with 18 additions and 38 deletions
+4 -26
View File
@@ -3,9 +3,7 @@ from typing import List
import random
from model import (
Card,
CardType,
CardRole,
CardFaction,
CardParser,
Player,
Team,
@@ -87,7 +85,6 @@ class Game(Serializable):
async def create_card(self, card: Card) -> Card:
self.cards.append(card)
await self.notify_controller("create", card.serialize_guest())
return card
async def create_base_deck(self, base_deck_name: str = "base") -> List[Card]:
@@ -120,7 +117,7 @@ class Game(Serializable):
if team is None:
team = await self.create_team()
player = Player(username, team)
player = Player(self, username, team)
self.players.append(player)
player.stack_pile = await self.create_base_deck("base")
@@ -152,8 +149,7 @@ class Game(Serializable):
await self.notify_controller("update", self.serialize_guest())
def serialize_guest(self) -> dict:
return super().serialize_guest() | {
"loaded_cards": None,
data = super().serialize_guest() | {
"cards": [card.uuid for card in self.cards],
"market_stack": [None for card in self.market_stack],
"market": [None if card is None else card.uuid for card in self.market],
@@ -165,6 +161,8 @@ class Game(Serializable):
"turn": None if self.turn is None else self.turn.uuid,
}
return {k: data[k] for k in data.keys() - ["loaded_cards"]}
async def start_game(self):
self.started = True
self.turn = random.choice(self.teams)
@@ -183,26 +181,6 @@ class Game(Serializable):
notifications = []
# Send cards in hand to teams
# TODO : Migrate this to player (when player draw)
for p in self.players:
notifications.append(p.team.notify_controller("update", p.serialize_team()))
# for t in self.teams:
# current_team = [p for p in self.players if p.team == t]
# for p in current_team:
# for o in current_team:
# notifications.append(
# p.notify_controller("update", o.serialize_team())
# )
# Send cards in hand to all others
for p in self.players:
for o in self.players:
if p.team == o.team:
continue
notifications.append(p.notify_controller("update", o.serialize_guest()))
await asyncio.gather(*notifications)
print(