Initial commit
This commit is contained in:
@ -0,0 +1,45 @@
|
||||
import logging
|
||||
import json
|
||||
|
||||
_log = logging.getLogger('NoPE-Lib')
|
||||
|
||||
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 []
|
||||
|
||||
7
NoPELib/expansion.py
Normal file
7
NoPELib/expansion.py
Normal file
@ -0,0 +1,7 @@
|
||||
class Expansion:
|
||||
def __init__(self, parent, globalConfig):
|
||||
setattr(parent, self.__class__.ID, self)
|
||||
|
||||
class PlayerExpansion:
|
||||
def __init__(self, player, localConfig):
|
||||
pass
|
||||
14
exampleExpansion/__init__.py
Normal file
14
exampleExpansion/__init__.py
Normal file
@ -0,0 +1,14 @@
|
||||
from NoPELib.expansion import Expansion
|
||||
from NoPELib.expansion import PlayerExpansion
|
||||
|
||||
class Example(Expansion):
|
||||
ID = 'Example'
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
|
||||
class PlayerExample(PlayerExpansion):
|
||||
ID = 'Example'
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
12
examplePlayers.json
Normal file
12
examplePlayers.json
Normal file
@ -0,0 +1,12 @@
|
||||
{
|
||||
"exampleExpansion": {
|
||||
"optionA": 1,
|
||||
"optionB": 2
|
||||
},
|
||||
|
||||
"players": [
|
||||
{"name": "Brosef", "flags": [], "exampleExpansion": {"playerOption": 5}},
|
||||
{"name": "TRS_MML", "flags": [], "exampleExpansion": {"playerOption": 2}},
|
||||
{"name": "Tango", "flags": [], "exampleExpansion": {"playerOption": 3}}
|
||||
]
|
||||
}
|
||||
Reference in New Issue
Block a user