X-Git-Url: https://jxself.org/git/?a=blobdiff_plain;f=make_graph.py;h=facc05ce21836399e07c917dd714310f0af6d913;hb=ceba6482a19688d6cceb520c60a166cdbb8e1ddc;hp=a2b0afc6453572fb61491cbcbf79f8a13ac3c361;hpb=9e6095afa0a3354daab554501e82c2c03bf588cd;p=open-adventure.git diff --git a/make_graph.py b/make_graph.py index a2b0afc..facc05c 100755 --- a/make_graph.py +++ b/make_graph.py @@ -29,6 +29,33 @@ def abbreviate(d): m = {"NORTH":"N", "EAST":"E", "SOUTH":"S", "WEST":"W", "UPWAR":"U", "DOWN":"D"} return m.get(d, d) +def roomlabel(loc): + "Generate a room label from the description, if possible" + loc_descriptions = dict(db["locations"])[loc]['description'] + description = loc[4:] + short = loc_descriptions["short"] + maptag = loc_descriptions["maptag"] + if short is not None: + if short.startswith("You're "): + short = short[7:] + if short.startswith("You are "): + short = short[8 :] + if short.startswith("in ") or short.startswith("at ") or short.startswith("on "): + short = short[3:] + if short[:3] in {"n/s", "e/w"}: + short = short[:3].upper() + short[3:] + elif short[:2] in {"ne", "sw", "se", "nw"}: + short = short[:2].upper() + short[2:] + else: + short = short[0].upper() + short[1:] + elif loc_descriptions["maptag"] is not None: + short = loc_descriptions["maptag"] + elif loc_descriptions["long"] is not None and len(loc_descriptions["long"]) < 20: + short = loc_descriptions["long"] + if short is not None: + description += "\\n" + short + return description + if __name__ == "__main__": with open("adventure.yaml", "r") as f: db = yaml.safe_load(f) @@ -78,7 +105,7 @@ if __name__ == "__main__": continue if subset == "maze" and not allalike(loc): continue; - node_label = loc[4:] + node_label = roomlabel(loc) if loc in startlocs: node_label += "\\n" + ",".join(startlocs[loc]).lower() print(' %s [shape=box,label="%s"]' % (loc[4:], node_label))