Migrate docdump tool from sts2-re
Queries the game's shipped sts2.xml (19,635 documented members) to answer C# API questions without decompiling.
This commit is contained in:
parent
059e8c9f3c
commit
0aa77a5a57
1 changed files with 63 additions and 0 deletions
63
utils/docdump.py
Normal file
63
utils/docdump.py
Normal file
|
|
@ -0,0 +1,63 @@
|
|||
#!/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()
|
||||
Loading…
Add table
Add a link
Reference in a new issue