update: added 'stage' method to actionflow
This commit is contained in:
@@ -21,8 +21,7 @@ class ActionFlow:
|
|||||||
self.actions: list[type[Action]] = []
|
self.actions: list[type[Action]] = []
|
||||||
self.on: list[bool] = []
|
self.on: list[bool] = []
|
||||||
|
|
||||||
def do(self, action: type[Action], force=False):
|
def queue(self, action: type[Action]):
|
||||||
try:
|
|
||||||
name = action.__name__
|
name = action.__name__
|
||||||
index = self.indices.get(name)
|
index = self.indices.get(name)
|
||||||
assert index is not None, "Action '%s' is not registered" % name
|
assert index is not None, "Action '%s' is not registered" % name
|
||||||
@@ -30,8 +29,12 @@ class ActionFlow:
|
|||||||
if self.on[index]: raise Unavailable(name)
|
if self.on[index]: raise Unavailable(name)
|
||||||
if self.on[index] is None: raise NotAllowed(name)
|
if self.on[index] is None: raise NotAllowed(name)
|
||||||
self.on[index] = bool(self.actions[index].prepare())
|
self.on[index] = bool(self.actions[index].prepare())
|
||||||
except Exception as e:
|
|
||||||
if force: raise e
|
def stage(self, *actions: type[Action]):
|
||||||
|
for Actor in actions:
|
||||||
|
try: self.queue(Actor)
|
||||||
|
except: pass
|
||||||
|
self.react()
|
||||||
|
|
||||||
def react(self):
|
def react(self):
|
||||||
while any(self.on):
|
while any(self.on):
|
||||||
|
|||||||
Reference in New Issue
Block a user