Ensured that an error midstep would be catched by expansionsManager
This commit is contained in:
@ -39,28 +39,43 @@ class Expansion:
|
|||||||
config: The config of the expansion. Can't be modified during execution.
|
config: The config of the expansion. Can't be modified during execution.
|
||||||
|
|
||||||
Methods:
|
Methods:
|
||||||
|
__call__: Execute a given action with the expansion
|
||||||
|
|
||||||
|
Subclass methods:
|
||||||
step:
|
step:
|
||||||
reset:
|
reset:
|
||||||
close:
|
close:
|
||||||
|
|
||||||
Signals:
|
Signals:
|
||||||
onError:
|
midStepError:
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, ID: str, expansionsManager: "ExpansionsManager"):
|
def __init__(self, ID: str, expansionsManager: "ExpansionsManager"):
|
||||||
"""
|
|
||||||
Initialise the creation of an expansion and raise an error if not
|
|
||||||
available.
|
|
||||||
"""
|
|
||||||
self._ID = ID
|
self._ID = ID
|
||||||
|
self._closed = False
|
||||||
self._manager = expansionsManager
|
self._manager = expansionsManager
|
||||||
self.onError = Hook()
|
self.midStepError = Hook()
|
||||||
|
self.midStepError.connect(expansionsManager._midStepError(ID))
|
||||||
|
|
||||||
|
def __call__(self, action):
|
||||||
|
try:
|
||||||
|
assert not self._closed, "Can't use an expansion that has been closed."
|
||||||
|
step_info = self.step(action)
|
||||||
|
except Exception as e:
|
||||||
|
step_info = {
|
||||||
|
"expansionID": self._ID,
|
||||||
|
"showOnScreen": None,
|
||||||
|
"error": e,
|
||||||
|
"done": False
|
||||||
|
}
|
||||||
|
self.midStepError()
|
||||||
|
return step_info
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def config(self):
|
def config(self):
|
||||||
"""
|
"""
|
||||||
The config of the expansion.
|
The config of the expansion.
|
||||||
NOTE Can't be modified during execution.
|
Can't be modified during execution.
|
||||||
"""
|
"""
|
||||||
return copy.deepcopy(self._manager.config[self._ID]["config"])
|
return copy.deepcopy(self._manager.config[self._ID]["config"])
|
||||||
|
|
||||||
@ -71,11 +86,11 @@ class Expansion:
|
|||||||
|
|
||||||
@players.setter
|
@players.setter
|
||||||
def players(self, newPlayers):
|
def players(self, newPlayers):
|
||||||
self._manager.expansionPlayersChanged(self._ID, newPlayers)
|
self._manager.expansionPlayersChange(self._ID, newPlayers)
|
||||||
|
|
||||||
@players.deleter
|
@players.deleter
|
||||||
def players(self):
|
def players(self):
|
||||||
self._manager.expansionPlayersChanged(self._ID, ())
|
self._manager.expansionPlayersChange(self._ID, ())
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def tags(self):
|
def tags(self):
|
||||||
@ -129,22 +144,16 @@ class serialShocker(Expansion):
|
|||||||
a positive float that defines the duration
|
a positive float that defines the duration
|
||||||
a float within the range [0.0, 1.0] that defines the intensity
|
a float within the range [0.0, 1.0] that defines the intensity
|
||||||
"""
|
"""
|
||||||
|
# Execute the step
|
||||||
vibrateInstead, duration, intensity = action
|
vibrateInstead, duration, intensity = action
|
||||||
callFunc = self.shocker.vibrate if vibrateInstead else self.shocker.shock
|
callFunc = self.shocker.vibrate if vibrateInstead else self.shocker.shock
|
||||||
# Try to execute the step
|
callFunc(duration=duration, intensity=intensity)
|
||||||
try:
|
|
||||||
callFunc(duration=duration, intensity=intensity)
|
|
||||||
error = None
|
|
||||||
done = True
|
|
||||||
except Exception as e:
|
|
||||||
error = e
|
|
||||||
done = False
|
|
||||||
# Return additionnal info
|
# Return additionnal info
|
||||||
step_info = {
|
step_info = {
|
||||||
"expansionID": self._ID,
|
"expansionID": self._ID,
|
||||||
"showOnScreen": None,
|
"showOnScreen": None,
|
||||||
"error": error,
|
"error": None,
|
||||||
"done": done
|
"done": True
|
||||||
}
|
}
|
||||||
return step_info
|
return step_info
|
||||||
|
|
||||||
|
|||||||
@ -239,7 +239,8 @@ class ExpansionsManager:
|
|||||||
Container of the relevent expansions
|
Container of the relevent expansions
|
||||||
|
|
||||||
Methods:
|
Methods:
|
||||||
expansionPlayersChanged
|
expansionPlayersChange: Change the assigned players of an expansion
|
||||||
|
lookupPlayer: Provide a list of expansion available to a player
|
||||||
"""
|
"""
|
||||||
defaultExpansionConfig = {"players": (), "types": ()}
|
defaultExpansionConfig = {"players": (), "types": ()}
|
||||||
keysConvert2Tuple = ("players", "types")
|
keysConvert2Tuple = ("players", "types")
|
||||||
@ -339,7 +340,6 @@ class ExpansionsManager:
|
|||||||
# Remove the expansion
|
# Remove the expansion
|
||||||
expansion = self._activeExpansions.pop(expansionID)
|
expansion = self._activeExpansions.pop(expansionID)
|
||||||
expansion.close()
|
expansion.close()
|
||||||
del expansion
|
|
||||||
|
|
||||||
def _includeChanged(self):
|
def _includeChanged(self):
|
||||||
"""
|
"""
|
||||||
@ -388,10 +388,10 @@ class ExpansionsManager:
|
|||||||
for expansionID in filteredRemoval:
|
for expansionID in filteredRemoval:
|
||||||
self._removeExpansion(expansionID)
|
self._removeExpansion(expansionID)
|
||||||
|
|
||||||
def _errorOccured(self, expansionID):
|
def _midStepError(self, expansionID):
|
||||||
self._removeExpansion(expansionID)
|
self._removeExpansion(expansionID)
|
||||||
|
|
||||||
def expansionPlayersChanged(self, expansionID, newPlayers):
|
def expansionPlayersChange(self, expansionID, newPlayers):
|
||||||
"""
|
"""
|
||||||
Method that allows changing the assigned players of an expansion.
|
Method that allows changing the assigned players of an expansion.
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user