feat: наследование от BaseEvent и метод from_payload для каждого из классов Event
This commit is contained in:
@@ -1,36 +1,66 @@
|
||||
from dataclasses import dataclass
|
||||
|
||||
from ..base_event import BaseEvent
|
||||
from ..lobby.domain import Player
|
||||
from ..session.domain import ArrowDirection
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class PlayerHelloEvent:
|
||||
class PlayerHelloEvent(BaseEvent):
|
||||
player: Player
|
||||
|
||||
@classmethod
|
||||
def from_payload(cls, p: dict) -> "PlayerHelloEvent":
|
||||
return cls(player=Player.from_dict(p))
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class SetterMoveEvent:
|
||||
class SetterMoveEvent(BaseEvent):
|
||||
player: Player
|
||||
direction: ArrowDirection
|
||||
|
||||
@classmethod
|
||||
def from_payload(cls, p: dict) -> "SetterMoveEvent":
|
||||
return cls(
|
||||
player=Player.from_dict(p),
|
||||
direction=ArrowDirection(p["arrow_direction"]),
|
||||
)
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class GuesserMoveEvent:
|
||||
class GuesserMoveEvent(BaseEvent):
|
||||
player: Player
|
||||
direction: ArrowDirection
|
||||
|
||||
@classmethod
|
||||
def from_payload(cls, p: dict) -> "GuesserMoveEvent":
|
||||
return cls(
|
||||
player=Player.from_dict(p),
|
||||
direction=ArrowDirection(p["arrow_direction"]),
|
||||
)
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class RevealSecretEvent:
|
||||
class RevealSecretEvent(BaseEvent):
|
||||
player: Player
|
||||
direction: ArrowDirection
|
||||
|
||||
@classmethod
|
||||
def from_payload(cls, p: dict) -> "RevealSecretEvent":
|
||||
return cls(
|
||||
player=Player.from_dict(p),
|
||||
direction=ArrowDirection(p["arrow_direction"]),
|
||||
)
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class NextStepRequestedEvent:
|
||||
class NextStepRequestedEvent(BaseEvent):
|
||||
player: Player
|
||||
|
||||
@classmethod
|
||||
def from_payload(cls, p: dict) -> "NextStepRequestedEvent":
|
||||
return cls(player=Player.from_dict(p))
|
||||
|
||||
|
||||
SessionEvent = (
|
||||
PlayerHelloEvent
|
||||
|
||||
Reference in New Issue
Block a user