From 4c558c0df4d8340e7319c17642d3e267bbd9c939 Mon Sep 17 00:00:00 2001 From: Dennis Scheiba Date: Mon, 18 Sep 2023 12:59:25 +0200 Subject: [PATCH] fall back to default door if active door runs into dead end --- caster-back/story_graph/engine.py | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/caster-back/story_graph/engine.py b/caster-back/story_graph/engine.py index 929fcd44..ea12a566 100644 --- a/caster-back/story_graph/engine.py +++ b/caster-back/story_graph/engine.py @@ -388,13 +388,22 @@ async def get_next_node(self) -> Node: ).afirst() # else return default out - if exit_door is None: - raise GraphDeadEnd() - - try: - return (await exit_door.out_edges.order_by("?").select_related("in_node_door__node").afirst()).in_node_door.node # type: ignore - except AttributeError: - raise GraphDeadEnd() + while True: + if exit_door is None: + raise GraphDeadEnd() + try: + return (await exit_door.out_edges.order_by("?").select_related("in_node_door__node").afirst()).in_node_door.node # type: ignore + except AttributeError: + if exit_door.is_default: + raise GraphDeadEnd() + log.info( + f"Ran into a dead end on non-default door {exit_door.name} on node {self._current_node.name} - fallback to default door" + ) + exit_door = await NodeDoor.objects.filter( + node=self._current_node, + door_type=NodeDoor.DoorType.OUTPUT, + is_default=True, + ).afirst() async def start( self, max_steps: int = 1000