Compare commits

...

4 Commits

Author SHA1 Message Date
265322f58b My bad team, this one will work for sure 2025-06-22 18:09:09 +01:00
5dbd9211de Added awaitingTimeout function (not tested, good luck team) 2025-06-22 18:00:42 +01:00
2a0def7fa6 Added NoPELib integration 2025-06-22 17:36:43 +01:00
08d6261d3f Updated version 2025-06-21 23:08:39 +01:00
2 changed files with 23 additions and 8 deletions

View File

@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
[project] [project]
name = "gameUtils" name = "gameUtils"
version = "0.0.1.dev0" version = "1.0.0"
description = "A set of utilities to make the game development process less painful (despite the organisation name) and more unified." description = "A set of utilities to make the game development process less painful (despite the organisation name) and more unified."
authors = [{ name = "Brosef" }] authors = [{ name = "Brosef" }]
dependencies = ["pygame-ce"] dependencies = ["pygame-ce"]

View File

@ -1,5 +1,6 @@
from .events import Timeout from .events import Timeout
from .anim import AnimatedObject from .anim import AnimatedObject
import NoPELib
import tomllib import tomllib
import time import time
@ -12,15 +13,15 @@ class Game:
surface (pygame.Surface): The surface the game devs draw on. surface (pygame.Surface): The surface the game devs draw on.
""" """
self.surf = surface
self.size = self.surf.size
self.pm = None
# Holds all the timeouts that haven't been fired yet
self._timeouts = []
with open('./game.toml', 'r') as f: with open('./game.toml', 'r') as f:
self.cfg = tomllib.loads(f.read()) 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): def update(self):
""" """
Updates some core things in the background. Updates some core things in the background.
@ -59,4 +60,18 @@ class Game:
to wait before firing. to wait before firing.
""" """
self._timeouts.append(Timeout(id, time.perf_counter()+delay)) self._timeouts.append(Timeout(id, time.perf_counter()+delay))
def awaitingTimeout(self, id: str):
"""
Tells you if a timeout ID is on the timeout stack.
Args:
id (str): The timeout ID.
Returns:
bool: True if there is a timeout with that ID
ID on the stack, False otherwise.
"""
return any([timeout.timeoutID == id for timeout in self._timeouts])