backend/app/models.py

91 lines
1.6 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
2019-07-07 23:10:02 +02:00
2019-07-06 21:54:35 +02:00
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] = []
2019-07-07 23:10:02 +02:00
packs: List[str] = []
2019-07-06 21:54:35 +02:00
class Answer(BaseModel):
2019-07-07 17:26:53 +02:00
text: List[str]
2019-07-06 21:54:35 +02:00
2019-07-07 23:10:02 +02:00
2019-07-06 21:54:35 +02:00
class AnswerReceived(Answer):
uuid: str
2019-07-07 23:10:02 +02:00
2019-07-06 21:54:35 +02:00
class AnswerSending(Answer):
index: int
2019-07-07 23:10:02 +02:00
2019-07-06 21:54:35 +02:00
class AnswerSendingButItHasAUUIDBecauseItIsImportantToCheckIfItWasSentByTheCzar(AnswerSending):
uuid: str
2019-07-07 23:10:02 +02:00
2019-07-06 21:54:35 +02:00
class Room(PubRoom):
players: List[Player] = [] # List of player's uuids
number: int
admin_uuid: UUID4 = None
2019-07-07 23:10:02 +02:00
answers: List[AnswerSending] = []
2019-07-06 21:54:35 +02:00
# 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