From 48dde7a0ee1ba321753654dc92f9f54a6e08d003 Mon Sep 17 00:00:00 2001 From: Ben Date: Thu, 26 Mar 2020 22:18:44 +0000 Subject: [PATCH] Give waddles a "temporary" option Passing `temporary=true` into a waddle will cause it to destroy itself when all players have left --- houdini/data/room.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/houdini/data/room.py b/houdini/data/room.py index db75e4e..7d1c899 100644 --- a/houdini/data/room.py +++ b/houdini/data/room.py @@ -268,13 +268,13 @@ class RoomWaddle(db.Model): game = db.Column(db.String(20), nullable=False) GameClassMapping = { - 'sled': SledRacingLogic + self.temporary = kwargs.pop('temporary', False) } - - def __init__(self, *args, **kwargs): - super().__init__(*args, **kwargs) - self.penguins = [] + self.logic = None + self.room = None + + super().__init__(*args, **kwargs) async def add_penguin(self, p): if not self.penguins: @@ -293,6 +293,9 @@ class RoomWaddle(db.Model): await self.reset() + if self.temporary: + del p.server.rooms[self.room_id].waddles[self.id] + async def remove_penguin(self, p): seat_id = self.get_seat_id(p) self.penguins[seat_id] = None @@ -300,6 +303,9 @@ class RoomWaddle(db.Model): p.waddle = None + if self.temporary and self.penguins.count(None) == self.seats: + del p.server.rooms[self.room_id].waddles[self.id] + async def reset(self): for seat_id, penguin in enumerate(self.penguins): if penguin: