from .events import Timeout from .anim import AnimatedObject import NoPELib import tomllib import time class Game: def __init__(self, surface): """ Initialises some things for the game developers. Args: surface (pygame.Surface): The surface the game devs draw on. """ with open('./game.toml', 'r') as f: self.cfg = tomllib.loads(f.read()) self.surf = surface self.size = self.surf.size self.pm = NoPELib.PlayersManager(self.cfg['name'], playersPath='../players.json') # Holds all the timeouts that haven't been fired yet self._timeouts = [] def update(self): """ Updates some core things in the background. """ for timeout in self._timeouts.copy(): if timeout.fireOn <= time.perf_counter(): self.onEvent(timeout) self._timeouts.remove(timeout) def onEvent(self, event): pass def close(self): pass def createAnimObj(self, *args, **kwargs): """ Creates an animated object. Args: objectID (str): The ID of the object. baseFrame (str): The path to the base frame. """ return AnimatedObject(self, *args, **kwargs) def timeout(self, id: str, delay: float): """ Fires a Timeout event with the specified ID after the specified delay. Args: id (str): The timeout ID. delay (float): How long (in seconds) to wait before firing. """ self._timeouts.append(Timeout(id, time.perf_counter()+delay))