|
|
|
|
@ -1,9 +1,11 @@
|
|
|
|
|
from .events import Timeout
|
|
|
|
|
from .anim import AnimatedObject
|
|
|
|
|
import NoPELib
|
|
|
|
|
import tomllib
|
|
|
|
|
import time
|
|
|
|
|
|
|
|
|
|
import NoPELib
|
|
|
|
|
|
|
|
|
|
from .events import Timeout
|
|
|
|
|
from .anim import AnimatedObject
|
|
|
|
|
|
|
|
|
|
class Game:
|
|
|
|
|
def __init__(self, surface):
|
|
|
|
|
"""
|
|
|
|
|
@ -21,23 +23,55 @@ class Game:
|
|
|
|
|
self.pm = NoPELib.PlayersManager(self.cfg['name'], playersPath='../players.json')
|
|
|
|
|
# Holds all the timeouts that haven't been fired yet
|
|
|
|
|
self._timeouts = []
|
|
|
|
|
# The following are used by self.popup() to halt some events
|
|
|
|
|
self._haltUpdate = False
|
|
|
|
|
self._haltEvents = False
|
|
|
|
|
# Will become a pygame.Surface with the popup contents
|
|
|
|
|
self._popupMenu = None
|
|
|
|
|
|
|
|
|
|
def update(self):
|
|
|
|
|
"""
|
|
|
|
|
Updates some core things in the background.
|
|
|
|
|
Intended to be overridden by the game developer.
|
|
|
|
|
See BaseGame for documentation.
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _update(self):
|
|
|
|
|
"""
|
|
|
|
|
Updates some core things in the background, and calls update()
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
# Handle timeouts
|
|
|
|
|
for timeout in self._timeouts.copy():
|
|
|
|
|
if timeout.fireOn <= time.perf_counter():
|
|
|
|
|
self.onEvent(timeout)
|
|
|
|
|
self._timeouts.remove(timeout)
|
|
|
|
|
|
|
|
|
|
# Game update
|
|
|
|
|
if not self._haltUpdate:
|
|
|
|
|
self.update()
|
|
|
|
|
|
|
|
|
|
# TODO: Draw things like debug menu, etc.
|
|
|
|
|
|
|
|
|
|
def onEvent(self, event):
|
|
|
|
|
pass
|
|
|
|
|
"""
|
|
|
|
|
Intended to be overridden by the game developer.
|
|
|
|
|
See BaseGame for documentation.
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
def _onEvent(self, event):
|
|
|
|
|
"""
|
|
|
|
|
Updates some core things in the background, and calls onEvent()
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
if not self._haltEvents:
|
|
|
|
|
self.onEvent(event)
|
|
|
|
|
|
|
|
|
|
def close(self):
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
Intended to be overridden by the game developer.
|
|
|
|
|
See BaseGame for documentation.
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
def createAnimObj(self, *args, **kwargs):
|
|
|
|
|
"""
|
|
|
|
|
Creates an animated object.
|
|
|
|
|
@ -59,23 +93,48 @@ class Game:
|
|
|
|
|
delay (float): How long (in seconds)
|
|
|
|
|
to wait before firing.
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
self._timeouts.append(Timeout(id, time.perf_counter()+delay))
|
|
|
|
|
|
|
|
|
|
def awaitingTimeout(self, id: str):
|
|
|
|
|
|
|
|
|
|
def awaitingTimeout(self, timeoutID: str):
|
|
|
|
|
"""
|
|
|
|
|
Tells you if a timeout ID is on the timeout stack.
|
|
|
|
|
|
|
|
|
|
Args:
|
|
|
|
|
id (str): The timeout ID.
|
|
|
|
|
timeoutID (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])
|
|
|
|
|
|
|
|
|
|
# TODO: Add popup method
|
|
|
|
|
return any(timeout.timeoutID == timeoutID for timeout in self._timeouts)
|
|
|
|
|
|
|
|
|
|
# TODO: add punish(player, intensity)
|
|
|
|
|
def popup(self, title: str, text: str, haltUpdate: bool=False, haltEvents: bool=True):
|
|
|
|
|
"""
|
|
|
|
|
Pops up a dialogue box.
|
|
|
|
|
|
|
|
|
|
Args:
|
|
|
|
|
title (str): The big "title" text to be displayed.
|
|
|
|
|
text (str): The main body text to be displayed.
|
|
|
|
|
haltUpdate (bool): If True, the games update() method will not be called until
|
|
|
|
|
the popup is dismissed. Default: False.
|
|
|
|
|
haltEvents (bool): If True, the games onEvent() method will not be called until
|
|
|
|
|
the popup is dismissed. Default: True.
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
self._haltUpdate = haltUpdate
|
|
|
|
|
self._haltEvents = haltEvents
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def punish(self, player, intensity: float):
|
|
|
|
|
"""
|
|
|
|
|
Handles punishing players for most games.
|
|
|
|
|
Handles games preferences on PDO order?
|
|
|
|
|
Handles auto popups for messaged events.
|
|
|
|
|
|
|
|
|
|
Args:
|
|
|
|
|
player (NoPELib.Player): The player to punish.
|
|
|
|
|
intensity (float): The intensity to punish the player.
|
|
|
|
|
"""
|
|
|
|
|
|