Proof of concept for dungeon graph maker.
[open-adventure.git] / make_graph.py
1 #!/usr/bin/env python3
2
3 # Make a DOT graph of the dungeon
4 #
5 # Copyright (c) 2017 by Eric S. Raymond
6 # SPDX-License-Identifier: BSD-2-clause
7
8 import sys, yaml
9
10 def allalike(loc):
11     "Select out loci related to the Maze All Alike"
12     return (loc == "LOC_MISTWEST") or ("ALIKE" in loc) or ("DEADEND" in loc) or ("STALACTITE" in loc)
13
14 if __name__ == "__main__":
15     with open("adventure.yaml", "r") as f:
16         db = yaml.safe_load(f)
17
18     print("digraph G {")
19     for (loc, attrs) in db["locations"]:
20         if not allalike(loc):
21             continue
22         travel = attrs["travel"]
23         if len(travel) > 0:
24             for dest in travel:
25                 verbs = dest["verbs"]
26                 if len(verbs) == 0:
27                     continue
28                 action = dest["action"]
29                 if action[0] == "goto":
30                     arc = "%s -> %s" % (loc[4:], action[1][4:])
31                     label=",".join(verbs).lower()
32                     if len(label) > 0:
33                         arc += ' [label="%s"]' % label
34                     print("    " + arc)
35     print("}")
36
37