Archived
architecture cleanup
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
"""controller handles the translation between
|
||||
netcode messages and model functions"""
|
||||
|
||||
from controller.interfaces import ClientControllerInterface, GameControllerInterface
|
||||
from controller.object_controller import ObjectController
|
||||
from controller.card import Card
|
||||
from controller.game import GameController
|
||||
from controller.client import ClientController
|
||||
from controller.game import GameController
|
||||
|
||||
@@ -0,0 +1,95 @@
|
||||
from abc import ABC, abstractmethod
|
||||
from typing import Callable, Any, List
|
||||
from model import Game
|
||||
from netcode import WSServer
|
||||
from netcode.models import Message, LoginMessage
|
||||
from netcode.ws_server import WebSocketServerProtocol
|
||||
|
||||
|
||||
class ClientControllerInterface(ABC):
|
||||
|
||||
@abstractmethod
|
||||
async def listen(self):
|
||||
"""Initializes the client controller"""
|
||||
|
||||
@abstractmethod
|
||||
async def send(self, message: Message):
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
async def send_error(self, error: str):
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
async def send_announce_dict(
|
||||
self,
|
||||
notification_type: str,
|
||||
data: dict,
|
||||
client_filter: Callable = lambda x: True,
|
||||
):
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
async def game_context(self, message: Message):
|
||||
"""Handles messages when the client is logged in"""
|
||||
|
||||
@abstractmethod
|
||||
async def login_context(self, message: LoginMessage):
|
||||
"""Handles messages when the client isn't logged in"""
|
||||
|
||||
@abstractmethod
|
||||
async def pregame_context(self, message: Message):
|
||||
"""Waits for players"""
|
||||
|
||||
|
||||
class GameControllerInterface(ABC):
|
||||
server: WSServer
|
||||
game: Game
|
||||
|
||||
clients: List[ClientControllerInterface]
|
||||
|
||||
@abstractmethod
|
||||
def __init__(self, game: Game, server: WSServer):
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
async def on_new_connection(self, websocket, callback: Callable):
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
async def send(self, message: Message, websocket: WebSocketServerProtocol):
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
async def broadcast(self, message: Message):
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
async def broadcast_announce_dict(
|
||||
self,
|
||||
notification_type: str,
|
||||
data: dict,
|
||||
client_filter: Callable[[ClientControllerInterface], Any],
|
||||
):
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
async def announce_dict(
|
||||
self,
|
||||
notification_type: str,
|
||||
data: dict,
|
||||
websocket: WebSocketServerProtocol,
|
||||
):
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
async def announce_game(self, websocket: WebSocketServerProtocol):
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
async def guest_handler(self, websocket: WebSocketServerProtocol):
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
async def start_game(self):
|
||||
pass
|
||||
Reference in New Issue
Block a user