From 9eed6ed0cb5209f9237db3116fc2ec228804f9b0 Mon Sep 17 00:00:00 2001 From: onee-only Date: Thu, 28 Nov 2024 08:22:40 +0000 Subject: [PATCH] =?UTF-8?q?move=20payload=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- message/internal/message.py | 5 ++-- message/payload/__init__.py | 1 + message/payload/internal/move_payload.py | 35 ++++++++++++++++++++++++ 3 files changed, 39 insertions(+), 2 deletions(-) create mode 100644 message/payload/internal/move_payload.py 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