Moved the Hook class
This commit is contained in:
@ -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
|
||||
|
||||
@ -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):
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user