Made some expansions and removed PDOLib
This commit is contained in:
@ -1,10 +1,10 @@
|
|||||||
{
|
{
|
||||||
"expansions":
|
"expansions":
|
||||||
{
|
{
|
||||||
"ShockColar1": {"players": ["Brosef"], "tags": ["shock"]},
|
"ShockColar1": {"players": ["Brosef"], "tags": ["shock"], "config": {"COM_port": "COM3", "shocker_ID": 24770}},
|
||||||
"RobotBarman": {"players": ["Tango", "TRS_MML"], "tags": ["drink"]},
|
"RobotBarman": {"players": ["Tango", "TRS_MML"], "tags": ["drink"], "config": {}},
|
||||||
"ChallengeDB": {"players": ["TRS_MML"], "tags": ["challenge"]},
|
"ChallengeDB": {"players": ["TRS_MML"], "tags": ["challenge"], "config": {}},
|
||||||
"SourCandy": {"players": [], "tags": ["food"]}
|
"SourCandy": {"players": [], "tags": ["food"], "config": {}}
|
||||||
},
|
},
|
||||||
"players": {
|
"players": {
|
||||||
"Brosef": {"flags": [], "expansions": {"exampleExpansion": {"playerOption": 5}}, "gamesSave": {"gameID0": 2}},
|
"Brosef": {"flags": [], "expansions": {"exampleExpansion": {"playerOption": 5}}, "gamesSave": {"gameID0": 2}},
|
||||||
|
|||||||
@ -1,20 +0,0 @@
|
|||||||
from player_settings import Expansion
|
|
||||||
|
|
||||||
class serialShockers(Expansion):
|
|
||||||
_api = None
|
|
||||||
|
|
||||||
def __init__(self, ID, expansionsManager):
|
|
||||||
super().__init__(ID, expansionsManager)
|
|
||||||
if serialShockers._api is None:
|
|
||||||
pass
|
|
||||||
else:
|
|
||||||
pass
|
|
||||||
|
|
||||||
def step(self, action):
|
|
||||||
pass
|
|
||||||
|
|
||||||
def reset(self):
|
|
||||||
pass
|
|
||||||
|
|
||||||
def close(self):
|
|
||||||
pass
|
|
||||||
74
src/NoPELib/expansionsLib.py
Normal file
74
src/NoPELib/expansionsLib.py
Normal file
@ -0,0 +1,74 @@
|
|||||||
|
"""
|
||||||
|
|
||||||
|
"""
|
||||||
|
from .player_settings import Expansion
|
||||||
|
|
||||||
|
|
||||||
|
class serialShocker(Expansion):
|
||||||
|
"""
|
||||||
|
Shockers
|
||||||
|
|
||||||
|
TODO Describe the config file
|
||||||
|
"""
|
||||||
|
_api = {}
|
||||||
|
|
||||||
|
def __init__(self, ID, expansionsManager):
|
||||||
|
super().__init__(ID, expansionsManager)
|
||||||
|
if self.config["COM_port"] not in serialShocker._api:
|
||||||
|
self._assignApi()
|
||||||
|
self.shocker = serialShocker._api[self.config["COM_port"]].shocker(["shocker_ID"])
|
||||||
|
|
||||||
|
def _assignApi(self):
|
||||||
|
from pishock import SerialAPI
|
||||||
|
serialShocker._api[self.config["COM_port"]] = SerialAPI(self.config["COM_port"])
|
||||||
|
|
||||||
|
def step(self, action):
|
||||||
|
"""
|
||||||
|
Arguments:
|
||||||
|
action (tuple): Tuple containing:
|
||||||
|
a bool deciding if vibrate should be used instead of shock
|
||||||
|
a positive float that defines the duration
|
||||||
|
a float within the range [0.0, 1.0] that defines the intensity
|
||||||
|
"""
|
||||||
|
vibrateInstead, duration, intensity = action
|
||||||
|
if vibrateInstead:
|
||||||
|
self.shocker.vibrate(duration=duration, intensity=intensity)
|
||||||
|
else:
|
||||||
|
self.shocker.shock(duration=duration, intensity=intensity)
|
||||||
|
|
||||||
|
def close(self):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def reset(self):
|
||||||
|
if self.config["COM_port"] not in serialShocker._api:
|
||||||
|
serialShocker._api[self.config["COM_port"]].restart()
|
||||||
|
else:
|
||||||
|
self._assignApi()
|
||||||
|
|
||||||
|
|
||||||
|
class simplest(Expansion):
|
||||||
|
""" A very simple expansion that only prints on screen. """
|
||||||
|
def __init__(self, ID, expansionsManager):
|
||||||
|
super().__init__(ID, expansionsManager)
|
||||||
|
print(f"Initialising with config {self.config}")
|
||||||
|
|
||||||
|
def step(self, action):
|
||||||
|
"""
|
||||||
|
Arguments:
|
||||||
|
action (tuple): Tuple containing:
|
||||||
|
a bool deciding if vibrate should be used instead of shock
|
||||||
|
a positive float that defines the duration
|
||||||
|
a float within the range [0.0, 1.0] that defines the intensity
|
||||||
|
"""
|
||||||
|
vibrateInstead, duration, intensity = action
|
||||||
|
values = f"duration={duration}, intensity={intensity}"
|
||||||
|
if vibrateInstead:
|
||||||
|
print(f"Vibrate with {values}")
|
||||||
|
else:
|
||||||
|
print(f"Shock with {values}")
|
||||||
|
|
||||||
|
def close(self):
|
||||||
|
print("Closing")
|
||||||
|
|
||||||
|
def reset(self):
|
||||||
|
print("Reseting")
|
||||||
@ -7,7 +7,7 @@ import copy
|
|||||||
import json
|
import json
|
||||||
import logging
|
import logging
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
import PDOLib
|
import NoPELib.expansionsLib as expansionsLib
|
||||||
|
|
||||||
_log = logging.getLogger('NoPE-Lib')
|
_log = logging.getLogger('NoPE-Lib')
|
||||||
|
|
||||||
@ -275,7 +275,6 @@ class ExpansionsManager:
|
|||||||
defaultExpansionConfig = {"players": (), "types": ()}
|
defaultExpansionConfig = {"players": (), "types": ()}
|
||||||
keysConvert2Tuple = ("players", "types")
|
keysConvert2Tuple = ("players", "types")
|
||||||
tags = ["shock", "spice", "sour", "drink", "challenge"]
|
tags = ["shock", "spice", "sour", "drink", "challenge"]
|
||||||
# TODO Add an interface to allow the modification of the expansion settings
|
|
||||||
# (attributed players / types)
|
# (attributed players / types)
|
||||||
# TODO Allow to get a list of expansions with a specific tag/player
|
# TODO Allow to get a list of expansions with a specific tag/player
|
||||||
|
|
||||||
@ -341,20 +340,20 @@ class ExpansionsManager:
|
|||||||
|
|
||||||
def _listPossiblyValidExpansions(self):
|
def _listPossiblyValidExpansions(self):
|
||||||
"""
|
"""
|
||||||
List expansions that are included, defined in PDOLib and are available
|
List expansions that are included, defined in expansionsLib and are available
|
||||||
to at least one active player.
|
to at least one active player.
|
||||||
"""
|
"""
|
||||||
activePlayers = set(self.playersManager.keys())
|
activePlayers = set(self.playersManager.keys())
|
||||||
possiblyValidExpansions = [
|
possiblyValidExpansions = [
|
||||||
expansion for expansion in self._includedExpansions
|
expansionID for expansionID in self._includedExpansions
|
||||||
if hasattr(PDOLib, expansion) and
|
if hasattr(expansionsLib, expansionID) and
|
||||||
not self._getPlayersFillMissing(expansion).isdisjoint(activePlayers)
|
not self._getPlayersFillMissing(expansionID).isdisjoint(activePlayers)
|
||||||
]
|
]
|
||||||
return possiblyValidExpansions
|
return possiblyValidExpansions
|
||||||
|
|
||||||
def _createExpansion(self, expansionID):
|
def _createExpansion(self, expansionID):
|
||||||
try:
|
try:
|
||||||
expansion = getattr(PDOLib, expansionID)(expansionID, self)
|
expansion = getattr(expansionsLib, expansionID)(expansionID, self)
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
@ -387,7 +386,7 @@ class ExpansionsManager:
|
|||||||
possibleAddition = set(self._includedExpansions).difference(self._activeExpansions)
|
possibleAddition = set(self._includedExpansions).difference(self._activeExpansions)
|
||||||
filteredAddition = [
|
filteredAddition = [
|
||||||
expansionID for expansionID in possibleAddition
|
expansionID for expansionID in possibleAddition
|
||||||
if hasattr(PDOLib, expansionID) and
|
if hasattr(expansionsLib, expansionID) and
|
||||||
playerName in self._getPlayersFillMissing(expansionID)
|
playerName in self._getPlayersFillMissing(expansionID)
|
||||||
]
|
]
|
||||||
# Create the expansions
|
# Create the expansions
|
||||||
@ -411,30 +410,12 @@ class ExpansionsManager:
|
|||||||
expansionIsActive = expansionID in self._activeExpansions
|
expansionIsActive = expansionID in self._activeExpansions
|
||||||
activePlayers = set(self.playersManager.keys())
|
activePlayers = set(self.playersManager.keys())
|
||||||
expansionHasNoPlayers = self._getPlayersFillMissing(expansionID).isdisjoint(activePlayers)
|
expansionHasNoPlayers = self._getPlayersFillMissing(expansionID).isdisjoint(activePlayers)
|
||||||
expansionDefined = hasattr(PDOLib, expansionID)
|
expansionDefined = hasattr(expansionsLib, expansionID)
|
||||||
if expansionIsActive and expansionHasNoPlayers:
|
if expansionIsActive and expansionHasNoPlayers:
|
||||||
self._removeExpansion(expansionID)
|
self._removeExpansion(expansionID)
|
||||||
elif (not expansionIsActive) and (not expansionHasNoPlayers) and expansionDefined:
|
elif (not expansionIsActive) and (not expansionHasNoPlayers) and expansionDefined:
|
||||||
self._createExpansion(expansionID)
|
self._createExpansion(expansionID)
|
||||||
|
|
||||||
def initilizeExpansion(self, expansionID: str, suppressError: bool=False):
|
|
||||||
"""
|
|
||||||
Initilise (possibly again) the expansion.
|
|
||||||
|
|
||||||
Arguments:
|
|
||||||
expansionID (str):
|
|
||||||
suppressError (bool):
|
|
||||||
"""
|
|
||||||
if expansionID in self._activeExpansions:
|
|
||||||
self._removeExpansion(expansionID)
|
|
||||||
# Make sure that the expansion is relevent
|
|
||||||
if not suppressError:
|
|
||||||
# Verify that creating the expansion was successful
|
|
||||||
pass
|
|
||||||
# Try creating a new instance of the expansion
|
|
||||||
# Update the list of relevent expansions
|
|
||||||
# TODO Implement the rest
|
|
||||||
|
|
||||||
|
|
||||||
class Expansion:
|
class Expansion:
|
||||||
"""
|
"""
|
||||||
@ -462,6 +443,10 @@ class Expansion:
|
|||||||
self._ID = ID
|
self._ID = ID
|
||||||
self._manager = expansionsManager
|
self._manager = expansionsManager
|
||||||
self.onError = Hook()
|
self.onError = Hook()
|
||||||
|
|
||||||
|
@property
|
||||||
|
def config(self):
|
||||||
|
return copy.deepcopy(self._manager.config[self._ID]["config"])
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def players(self):
|
def players(self):
|
||||||
@ -522,3 +507,4 @@ if __name__ == "__main__":
|
|||||||
print(pm["Brosef"].gameSave)
|
print(pm["Brosef"].gameSave)
|
||||||
brosef.state = ["alive"]
|
brosef.state = ["alive"]
|
||||||
# TODO Verify that changing the gameID works as intended
|
# TODO Verify that changing the gameID works as intended
|
||||||
|
# TODO Test out the expansion manager
|
||||||
|
|||||||
Reference in New Issue
Block a user