From: Eric S. Raymond Date: Wed, 20 Apr 2022 00:55:23 +0000 (-0400) Subject: More grapher improvement. X-Git-Tag: 1.12~11 X-Git-Url: https://jxself.org/git/?a=commitdiff_plain;h=81c7bb6d5bf9f16bcd3a1b456dc2937d27660eee;p=open-adventure.git More grapher improvement. --- diff --git a/make_graph.py b/make_graph.py index 1da5a76..f4e1b11 100755 --- a/make_graph.py +++ b/make_graph.py @@ -95,11 +95,21 @@ def forward(loc): loc = location_lookup[loc]["travel"][0]["action"][1] return loc +def reveal(objname): + "Should this object be revealed when mappinmg?" + if "OBJ_" in objname: + return False + if objname == "VEND": + return True + obj = object_lookup[objname] + return not obj.get("immovable") + if __name__ == "__main__": with open("adventure.yaml", "r") as f: db = yaml.safe_load(f) location_lookup = dict(db["locations"]) + object_lookup = dict(db["objects"]) try: (options, arguments) = getopt.getopt(sys.argv[1:], "admsv") @@ -128,7 +138,7 @@ if __name__ == "__main__": for obj in db["objects"]: objname = obj[0] location = obj[1].get("locations") - if "OBJ" not in objname and location != "LOC_NOWHERE" and ("immovable" not in obj[1] or not obj[1]["immovable"]): + if location != "LOC_NOWHERE" and reveal(objname): if location in startlocs: startlocs[location].append(objname) else: @@ -138,9 +148,9 @@ if __name__ == "__main__": # Dictionary ke6y is (from, to) iff its a valid link, # value is correspoinding motion verbs. links = {} - nodes = set() + nodes = [] for (loc, attrs) in db["locations"]: - nodes.add(loc) + nodes.append(loc) travel = attrs["travel"] if len(travel) > 0: for dest in travel: @@ -166,13 +176,12 @@ if __name__ == "__main__": print("digraph G {") for loc in nodes: - if is_forwarder(loc): - continue - node_label = roomlabel(loc) - if subset(loc): - print(' %s [shape=box,label="%s"]' % (loc[4:], node_label)) - elif loc in neighbors: - print(' %s [label="%s"]' % (loc[4:], node_label)) + if not is_forwarder(loc): + node_label = roomlabel(loc) + if subset(loc): + print(' %s [shape=box,label="%s"]' % (loc[4:], node_label)) + elif loc in neighbors: + print(' %s [label="%s"]' % (loc[4:], node_label)) # Draw arcs for (f, t) in links: