Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save CodeOptimist/4463dca31ee4898dce56d6b9d87097ae to your computer and use it in GitHub Desktop.
Save CodeOptimist/4463dca31ee4898dce56d6b9d87097ae to your computer and use it in GitHub Desktop.
import re
from pathlib import Path
from ahkunwrapped import Script
def main() -> None:
rw_xml_folder = Path(r'C:\Program Files (x86)\Steam\steamapps\common\RimWorld\Data')
stat_bases_re = re.compile(r'<\s*statBases(.*?)statBases', flags=re.DOTALL | re.IGNORECASE)
integer_defs_re = re.compile(r'<\s*(\w+)\s*>\s*-?\s*\d+\s*<')
float_defs_re = re.compile(r'<\s*(\w+)\s*>[^<]*\..*?<')
integer_defs = set()
float_defs = set()
for xml_path in rw_xml_folder.rglob('*.xml'):
contents = xml_path.read_text()
stat_blocks = stat_bases_re.findall(contents)
for stat_block in stat_blocks:
integer_defs.update(integer_defs_re.findall(stat_block))
float_defs.update(float_defs_re.findall(stat_block))
always_integers = integer_defs - float_defs
for_cs = ",\n".join(f"StatDefOf.{name}" for name in (sorted(always_integers))) + ",\n"
print(for_cs)
ahk = Script()
ahk.set('Clipboard', for_cs)
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment