diff --git a/message/internal/message.py b/message/internal/message.py index aa27ca5..dd9cabc 100644 --- a/message/internal/message.py +++ b/message/internal/message.py @@ -1,5 +1,5 @@ from typing import Generic, TypeVar -from message.payload import Payload, FetchTilesPayload, TilesPayload, PointingPayload +from message.payload import Payload, FetchTilesPayload, TilesPayload, PointingPayload, MovingPayload from .exceptions import InvalidEventTypeException import json @@ -12,7 +12,8 @@ DECODABLE_PAYLOAD_DICT: dict[str, Payload] = { "fetch-tiles": FetchTilesPayload, "tiles": TilesPayload, - "pointing": PointingPayload + "pointing": PointingPayload, + "moving": MovingPayload } diff --git a/message/payload/__init__.py b/message/payload/__init__.py index 13b006e..7c0f1b5 100644 --- a/message/payload/__init__.py +++ b/message/payload/__init__.py @@ -4,3 +4,4 @@ from .internal.new_conn_payload import NewConnPayload, NewConnEvent, NearbyCursorPayload, CursorPayload, CursorAppearedPayload, NewCursorPayload from .internal.parsable_payload import ParsablePayload from .internal.pointing_payload import PointerSetPayload, PointingResultPayload, PointingPayload, TryPointingPayload, PointEvent, ClickType +from .internal.move_payload import MoveEvent, MovingPayload, MovedPayload, CheckMovablePayload, MovableResultPayload diff --git a/message/payload/internal/move_payload.py b/message/payload/internal/move_payload.py new file mode 100644 index 0000000..d59bcd4 --- /dev/null +++ b/message/payload/internal/move_payload.py @@ -0,0 +1,35 @@ +from board import Point +from cursor import Color +from dataclasses import dataclass +from .base_payload import Payload +from enum import Enum + + +class MoveEvent(str, Enum): + MOVING = "moving" + MOVED = "moved" + CHECK_MOVABLE = "check-movable" + MOVABLE_RESULT = "movable-result" + + +@dataclass +class MovingPayload(Payload): + position: Point + + +@dataclass +class MovedPayload(Payload): + origin_position: Point + new_position: Point + color: Color + + +@dataclass +class CheckMovablePayload(Payload): + position: Point + + +@dataclass +class MovableResultPayload(Payload): + position: Point + movable: bool