diff --git a/src/common/actionflow.py b/src/common/actionflow.py index 4201167..ced0da6 100644 --- a/src/common/actionflow.py +++ b/src/common/actionflow.py @@ -20,17 +20,14 @@ class ActionFlow: self.indices: dict[str, int] = {} self.actions: list[type[Action]] = [] self.on: list[bool] = [] - - @classmethod - def normalize(cls, kind): - return str.upper(kind.__name__) - def do(self, action: str): - index = self.indices.get(action) + def do(self, action: type[Action]): + name = action.__name__ + index = self.indices.get(name) assert index is not None - if self.on[index]: raise Unavailable(action) - if self.on[index] is None: raise NotAllowed(action) + if self.on[index]: raise Unavailable(name) + if self.on[index] is None: raise NotAllowed(name) value = self.actions[index].prepare() self.on[index] = bool(value) @@ -40,27 +37,27 @@ class ActionFlow: self.on[index] = False self.actions[index].perform() - def index(self, kind: type[Action]) -> int: - name = self.normalize(kind) + def index(self, action: type[Action]) -> int: + name = action.__name__ index = self.indices.get(name) assert index is not None return index - def allow(self, kind, value=True): - index = self.index(kind) + def allow(self, action: type[Action], value=True): + index = self.index(action) self.on[index] = False if value else None - def append(self, kind): - name = self.normalize(kind) + def append(self, action: type[Action]): + name = action.__name__ index = len(self.indices) self.indices[name] = index - self.actions.insert(index, kind) + self.actions.insert(index, action) self.on.insert(index, None) - def remove(self, kind): - name = self.normalize(kind) - index = self.index(kind) + def remove(self, action: type[Action]): + name = action.__name__ + index = self.index(action) self.indices.pop(name) self.actions.pop(index)