From b5122948da2e5b7d05aa94c87ff0f0bb1bcbac38 Mon Sep 17 00:00:00 2001 From: break27 Date: Thu, 4 Jun 2026 18:11:33 +0800 Subject: [PATCH] update: added 'stage' method to actionflow --- src/common/actionflow.py | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/src/common/actionflow.py b/src/common/actionflow.py index 4814520..3dc37e0 100644 --- a/src/common/actionflow.py +++ b/src/common/actionflow.py @@ -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 - - 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 + 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()) + + 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):