50 lines
1.4 KiB
Python
50 lines
1.4 KiB
Python
import json
|
|
|
|
class Players:
|
|
def __init__(self, playersPath: str='./players.json', loggerID: str='Players'):
|
|
"""
|
|
Initialises a list of players.
|
|
|
|
Args:
|
|
playersPath (str, optional): The path of the players.json file. Defaults to './players.json'.
|
|
loggerID (str, optional): The ID used for logging. Defaults to 'Players'.
|
|
"""
|
|
self._log = _log.getChild(loggerID)
|
|
|
|
with open(playersPath, 'r') as f:
|
|
self._cfg = json.loads(f.read())
|
|
|
|
def addExpansion(self, expansion):
|
|
"""
|
|
Adds an expansion, used by things like PDO-Lib.
|
|
|
|
Args:
|
|
expansion (Expansion): The expansion to add.
|
|
"""
|
|
|
|
expID = expansion.__class__.ID
|
|
_log.debug(f'Adding expansion {expID}...')
|
|
expansion = expansion(self._cfg.get(expID))
|
|
|
|
def loadPlayers(self):
|
|
"""
|
|
Actually loads all the players as objects.
|
|
|
|
The reason this isn't done in __init__ is
|
|
simply because no expansions have been loaded
|
|
yet.
|
|
"""
|
|
pass
|
|
|
|
class Player:
|
|
def __init__(self, name, flags: list[str] = None):
|
|
self.name = name
|
|
self.flags = flags if flags != None else []
|
|
|
|
class Expansion:
|
|
def __init__(self, parent, globalConfig):
|
|
setattr(parent, self.__class__.ID, self)
|
|
|
|
class PlayerExpansion:
|
|
def __init__(self, player, localConfig):
|
|
pass |