Queries the game's shipped sts2.xml (19,635 documented members) to answer C# API questions without decompiling.
63 lines
2 KiB
Python
63 lines
2 KiB
Python
#!/usr/bin/env python3
|
|
"""Dump .NET XML doc members (with summaries) for a namespace prefix."""
|
|
import sys, re, xml.etree.ElementTree as ET
|
|
|
|
XML = ("/Users/rasyidanakbar/Library/Application Support/Steam/steamapps/common/"
|
|
"Slay the Spire 2/SlayTheSpire2.app/Contents/Resources/"
|
|
"data_sts2_macos_arm64/sts2.xml")
|
|
|
|
def clean(el):
|
|
if el is None: return ""
|
|
txt = "".join(el.itertext())
|
|
return re.sub(r"\s+", " ", txt).strip()
|
|
|
|
def main():
|
|
prefix = sys.argv[1] if len(sys.argv) > 1 else ""
|
|
show_docs = "--docs" in sys.argv
|
|
types_only = "--types" in sys.argv
|
|
members_only = "--members" in sys.argv
|
|
|
|
tree = ET.parse(XML)
|
|
root = tree.getroot()
|
|
members = root.find("members")
|
|
if members is None:
|
|
print("no members"); return
|
|
|
|
types, mem = {}, []
|
|
for m in members.findall("member"):
|
|
name = m.get("name", "")
|
|
body = name[2:] if len(name) > 1 else name
|
|
kind = name[0]
|
|
if not body.startswith(prefix) and prefix:
|
|
continue
|
|
if kind == "T":
|
|
types[body] = m
|
|
elif kind in ("M", "P", "F"):
|
|
mem.append((body, m))
|
|
|
|
if not members_only:
|
|
for tname in sorted(types):
|
|
m = types[tname]
|
|
if types_only:
|
|
print("T: " + tname)
|
|
else:
|
|
print("=" * 78)
|
|
print("TYPE " + tname)
|
|
s = clean(m.find("summary"))
|
|
if s: print(" summary: " + s)
|
|
for tag in ("remarks", "example"):
|
|
v = clean(m.find(tag))
|
|
if v: print(f" {tag}: {v}")
|
|
if not types_only:
|
|
for body, m in sorted(mem):
|
|
s = clean(m.find("summary"))
|
|
params = [(p.get("name"), clean(p)) for p in m.findall("param")]
|
|
ret = clean(m.find("returns"))
|
|
print("-" * 78)
|
|
print(body)
|
|
if s: print(" " + s)
|
|
for pn, pd in params:
|
|
print(f" param {pn}: {pd}")
|
|
if ret: print(" returns: " + ret)
|
|
|
|
main()
|