Moved the Hook class

This commit is contained in:
2025-07-04 20:06:55 -04:00
parent 53c86cb2dc
commit 6117d8c2ed
2 changed files with 22 additions and 21 deletions

View File

@ -2,12 +2,32 @@
"""
import abc
import copy
from typing import TYPE_CHECKING
if TYPE_CHECKING:
from NoPELib.player_settings import ExpansionsManager
class Hook:
"""
A class that allows the creation of hooks.
Methods:
connect: Connect a slot when the signal is launched.
"""
def __init__(self):
self._slot = []
def __call__(self, *args, **kwargs):
for fct in self._slot:
fct(*args, **kwargs)
def connect(self, fct):
""" Connect a slot when the signal is launched. """
self._slot.append(fct)
class Expansion:
"""
A meta class implementation meant to describe how to interact with any kind

View File

@ -11,25 +11,6 @@ import NoPELib.expansionsLib as expansionsLib
_log = logging.getLogger('NoPE-Lib')
class Hook:
"""
A class that allows the creation of hooks.
Methods:
connect: Connect a slot when the signal is launched.
"""
def __init__(self):
self._slot = []
def __call__(self, *args, **kwargs):
for fct in self._slot:
fct(*args, **kwargs)
def connect(self, fct):
""" Connect a slot when the signal is launched. """
self._slot.append(fct)
class PlayersManager:
"""
Manager of players for a given game.
@ -82,8 +63,8 @@ class PlayersManager:
if name in activePlayers
}
# Create the signals
self.onMadePlayerActive = Hook()
self.onMadePlayerInactive = Hook()
self.onMadePlayerActive = expansionsLib.Hook()
self.onMadePlayerInactive = expansionsLib.Hook()
def __getitem__(self, playerName: str):
"""