update: added 'stage' method to actionflow

This commit is contained in:
2026-06-04 18:11:33 +08:00
parent 020576ff18
commit b5122948da
+13 -10
View File
@@ -21,17 +21,20 @@ class ActionFlow:
self.actions: list[type[Action]] = []
self.on: list[bool] = []
def do(self, action: type[Action], force=False):
try:
name = action.__name__
index = self.indices.get(name)
assert index is not None, "Action '%s' is not registered" % name
def queue(self, action: type[Action]):
name = action.__name__
index = self.indices.get(name)
assert index is not None, "Action '%s' is not registered" % name
if self.on[index]: raise Unavailable(name)
if self.on[index] is None: raise NotAllowed(name)
self.on[index] = bool(self.actions[index].prepare())
except Exception as e:
if force: raise e
if self.on[index]: raise Unavailable(name)
if self.on[index] is None: raise NotAllowed(name)
self.on[index] = bool(self.actions[index].prepare())
def stage(self, *actions: type[Action]):
for Actor in actions:
try: self.queue(Actor)
except: pass
self.react()
def react(self):
while any(self.on):