|
|
|
@ -11,12 +11,10 @@ class Game(db.Model):
@@ -11,12 +11,10 @@ class Game(db.Model):
|
|
|
|
|
state = db.Column(db.Enum(GameState), server_default=GameState(1).name, nullable=False) |
|
|
|
|
start_time = db.Column(db.DateTime) |
|
|
|
|
end_time = db.Column(db.DateTime) |
|
|
|
|
game_players = db.relationship( |
|
|
|
|
players = db.relationship( |
|
|
|
|
'GamePlayer', |
|
|
|
|
back_populates='game', |
|
|
|
|
cascade="save-update, merge, delete, delete-orphan") |
|
|
|
|
players = association_proxy('game_players', 'user', |
|
|
|
|
creator=lambda user: GamePlayer(user=user)) |
|
|
|
|
users = association_proxy('game_players', 'user', |
|
|
|
|
creator=lambda user: GamePlayer(user=user)) |
|
|
|
|
objectives = db.relationship( |
|
|
|
@ -31,19 +29,22 @@ class Game(db.Model):
@@ -31,19 +29,22 @@ class Game(db.Model):
|
|
|
|
|
cascade="save-update, merge, delete, delete-orphan") |
|
|
|
|
|
|
|
|
|
def last_player_locations(self): |
|
|
|
|
return [user.last_location(self) for user in self.players if user.locations] |
|
|
|
|
|
|
|
|
|
def bunnies(self): |
|
|
|
|
# pylint: disable=not-an-iterable |
|
|
|
|
return [gameplayer.user for gameplayer in self.game_players if gameplayer.role == Role.bunny] |
|
|
|
|
return [player.last_location() for player in self.players if player.user.locations] |
|
|
|
|
|
|
|
|
|
def last_locations(self, players): |
|
|
|
|
locations = [] |
|
|
|
|
for player in players: |
|
|
|
|
if isinstance(player, GamePlayer): |
|
|
|
|
player = player.user |
|
|
|
|
locations.append(player.last_location(self)) |
|
|
|
|
return locations |
|
|
|
|
|
|
|
|
|
def bunnies(self): |
|
|
|
|
# pylint: disable=not-an-iterable |
|
|
|
|
return [gameplayer for gameplayer in self.players if gameplayer.role == Role.bunny] |
|
|
|
|
|
|
|
|
|
def owned_by(self, user): |
|
|
|
|
# pylint: disable=not-an-iterable |
|
|
|
|
'''given user is an owner of this game''' |
|
|
|
|
return user in [gameplayer.user for gameplayer in self.game_players if gameplayer.role == Role.owner] |
|
|
|
|
return user in [gameplayer.user for gameplayer in self.players if gameplayer.role == Role.owner] |
|
|
|
|