game: add: class: point and segment, add: type docstring

This commit is contained in:
2024-01-21 00:33:30 +01:00
parent 6f8768e149
commit 8da7e09af7
19 changed files with 478 additions and 125 deletions

View File

@ -23,6 +23,7 @@ class GameWebSocket(WebsocketConsumer):
super().__init__(*args, **kwargs)
self.channel_name = "games"
self.group_name = "games"
self.member = None
def connect(self):
@ -30,20 +31,23 @@ class GameWebSocket(WebsocketConsumer):
if (self.user.pk is None):
self.user.pk = 0
self.channel_layer.group_add(self.group_name, self.channel_name)
self.accept()
self.game_id = int(self.scope['url_route']['kwargs']['game_id'])
self.game: Game = game_manager.get(self.game_id)
if (self.game is None):
self.send("Game not found.")
self.disconnect(1017)
self.send(text_data=json.dumps({"detail": "Game not found"}))
self.disconnect(1404)
return
self.member: Player | Spectator = self.game.join(self.user.pk, self)
def disconnect(self, code):
self.member.disconnect()
if (self.member is not None):
self.member.disconnect()
super().disconnect(code)
def receive(self, text_data: str = None, bytes_data: bytes = None):