Make changes to the way actions work

This commit is contained in:
Marek Wolan
2023-08-28 22:34:20 +01:00
parent a9e969aa13
commit 319e87d200
8 changed files with 83 additions and 70 deletions

View File

@@ -17,15 +17,6 @@ class Network(SimComponent):
"""Initialise the network."""
super().__init__(**kwargs)
self.action_manager = ActionManager()
self.action_manager.add_action(
"node",
Action(
func=lambda request, context: self.nodes[request.pop(0)].apply_action(request, context),
validator=AllowAllValidator(),
),
)
def describe_state(self) -> Dict:
"""
Produce a dictionary describing the current state of this object.
@@ -44,6 +35,18 @@ class Network(SimComponent):
)
return state
def _init_action_manager(self) -> ActionManager:
am = super()._init_action_manager()
am.add_action(
"node",
Action(
func=lambda request, context: self.nodes[request.pop(0)].apply_action(request, context),
validator=AllowAllValidator(),
),
)
return am
def add_node(self, node: Node) -> None:
"""
Add an existing node to the network.