Skip to content

Commit

Permalink
fall back to default door if active door runs into dead end
Browse files Browse the repository at this point in the history
  • Loading branch information
capital-G committed Sep 18, 2023
1 parent cd4a02f commit 4c558c0
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions caster-back/story_graph/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 4c558c0

Please sign in to comment.