from __future__ import annotations from dataclasses import dataclass, field import typing import pygame from chat_selector import ChatSelector from active_chat import ActiveChat from config import FPS import degeon_core as dc @dataclass class Degeon: """ The main class with everything connected to the app: the data, the Attributes """ core: 'dc.Degeon' chat_selector: ChatSelector active_chat: typing.Optional[ActiveChat] = None has_profile_popup_opened: bool = False has_no_peers_popup: bool = False clock: pygame.time.Clock = field(default_factory=pygame.time.Clock) fps: int = FPS @classmethod def new(cls) -> Degeon: """ Create a new default instance with settings from file :return: a Degeon instance """ core: dc.Degeon = dc.new_degeon() chat_selector = ChatSelector() return cls(core=core, chat_selector=chat_selector) def render(self, screen: pygame.Surface): """ Render everything on the screen :param screen: the main screen """ chats_surface = self.chat_selector.render() screen.blit(chats_surface, (0, 0)) def process_core_messages(self): """ Do all the necessary Rust work """ pass # todo def tick(self): """ Handle incoming messages, update chats, create no_peers popup if necessary """ # process events in core self.process_core_messages() self.chat_selector.chats = self.core.chats if self.chat_selector.active_chat < len(self.chat_selector.chats): self.active_chat = ActiveChat.new(self.chat_selector.chats[self.chat_selector.active_chat]) def process_event(self, event: pygame.event.Event): """ Process an event :param event: pygame event """ self.chat_selector.process_event(event) def main_loop(self, screen: pygame.Surface): """ Drawing everything and handling events """ while True: self.clock.tick(self.fps) for event in pygame.event.get(): if event.type == pygame.QUIT: return self.process_event(event) self.tick() self.render(screen) pygame.display.update()