update: added 'force' argument to 'do' in ActionFlow

This commit is contained in:
2026-06-02 18:26:13 +08:00
parent f06c3dba0f
commit 996bda2298

View File

@@ -21,14 +21,17 @@ 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]): def do(self, action: type[Action], force=False):
name = action.__name__ try:
index = self.indices.get(name) name = action.__name__
assert index is not None, "Action '%s' is not registered" % 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]: 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 react(self): def react(self):
while any(self.on): while any(self.on):