backend/app/models.py

84 lines
1.5 KiB
Python
Raw Normal View History

2019-07-06 21:54:35 +02:00
from pydantic import BaseModel, UUID4
from typing import List, Any
from enum import Enum, auto
import uuid
class Card(BaseModel):
text: str
pick: int
deck: str
icon: str
class Pack(BaseModel):
icon: str
official: bool
name: str
class RoundStart(BaseModel):
czar: int
card: Card
class PubPlayer(BaseModel):
name: str
points: int = 0
class Player(PubPlayer):
uuid: UUID4
# def __init__(self, name):
# self.name = name
# self.uuid = uuid.uuid4()
class PubRoom(BaseModel):
code: str
czar: int = 0
players: List[PubPlayer] = [] # List of player's uuids
started: bool = False
played_cards: List[int] = []
class Answer(BaseModel):
2019-07-07 17:26:53 +02:00
text: List[str]
2019-07-06 21:54:35 +02:00
class AnswerReceived(Answer):
uuid: str
class AnswerSending(Answer):
index: int
class AnswerSendingButItHasAUUIDBecauseItIsImportantToCheckIfItWasSentByTheCzar(AnswerSending):
uuid: str
class Room(PubRoom):
players: List[Player] = [] # List of player's uuids
number: int
admin_uuid: UUID4 = None
answers:List[AnswerSending] = []
# def __init__(self, number):
# super().__init__()
# self.number = number
# self.code = hashes.encode(number)
class AutoName(Enum):
# pylint: disable=no-self-argument
def _generate_next_value_(name, start, count, last_values):
return name
class MessageType(AutoName):
JOIN = auto()
START = auto()
ANSWER = auto()
PICK = auto()
2019-07-07 17:26:53 +02:00
ROOM = auto()
2019-07-06 21:54:35 +02:00
class Message(BaseModel):
msgtype: MessageType
data: Any