noita_entangled_worlds/scripts/parse_components.py

62 lines
1.4 KiB
Python
Raw Normal View History

import shlex
import json
2024-11-03 16:06:41 +03:00
all_types = set()
renames = {
"std_string": "std::string",
}
def parse_component(component):
it = iter(component)
2024-11-03 16:06:41 +03:00
c_name = next(it)
c_name = c_name.strip("\n")
if "-" in c_name or "\n" in c_name:
print(component)
exit(-1)
fields = []
2024-11-03 16:06:41 +03:00
for line in it:
line = line.strip()
if line.startswith("-"):
continue
typ, name, *range_info, desc = shlex.split(line)
2024-11-03 16:06:41 +03:00
name = name.strip("\n")
if name == "-":
print(f"Field of type {typ} skipped")
continue
typ = renames.get(typ, typ)
fields.append({
"field": name,
"typ": typ,
"desc": desc,
})
2024-11-03 16:06:41 +03:00
all_types.add(typ)
#print(name, typ, desc, range_info)
return {
2024-11-03 16:06:41 +03:00
"name": c_name,
"fields": fields,
}
path = "/home/quant/.local/share/Steam/steamapps/common/Noita/tools_modding/component_documentation.txt"
components = []
current = []
2024-11-03 16:06:41 +03:00
for i, line in enumerate(open(path)):
if line == "\n":
if current:
components.append(current)
current = []
else:
current.append(line)
assert not current
parsed = [parse_component(component) for component in components]
2024-11-03 16:06:41 +03:00
json.dump(parsed, open("ewext/noita_api_macro/src/components.json", "w"), indent=None)
#print(*all_types, sep="\n")