60 lines
2 KiB
Python
60 lines
2 KiB
Python
#\!/usr/bin/env python3
|
|
"""Extract dictionaries from Mag-Plugins Dictionaries.cs file."""
|
|
|
|
import re
|
|
import json
|
|
|
|
def extract_dictionary(dict_name):
|
|
"""Extract a dictionary from Dictionaries.cs by name."""
|
|
with open('/home/erik/MosswartOverlord/unused/Mag-Plugins/Shared/Constants/Dictionaries.cs', 'r') as f:
|
|
content = f.read()
|
|
|
|
# Find the dictionary - handle multiline definitions
|
|
pattern = rf'{dict_name}\s*=\s*new\s+Dictionary<int,\s*string>\s*\{{(.*?)^\s*\}};'
|
|
match = re.search(pattern, content, re.DOTALL < /dev/null | re.MULTILINE)
|
|
|
|
if not match:
|
|
print(f"{dict_name} not found\!")
|
|
return {}
|
|
|
|
dict_content = match.group(1)
|
|
|
|
# Extract entries - handle both decimal and hex values
|
|
entry_pattern = r'\{\s*(0x[0-9A-Fa-f]+|\d+),\s*"([^"]+)"\s*\}'
|
|
entries = re.findall(entry_pattern, dict_content)
|
|
|
|
result = {}
|
|
for key, value in entries:
|
|
# Convert hex to decimal if needed
|
|
if key.startswith('0x'):
|
|
key = str(int(key, 16))
|
|
result[key] = value
|
|
|
|
return result
|
|
|
|
def main():
|
|
"""Extract all dictionaries and save to JSON."""
|
|
dictionaries = {
|
|
'AttributeSetInfo': extract_dictionary('AttributeSetInfo'),
|
|
'MaterialInfo': extract_dictionary('MaterialInfo'),
|
|
'SkillInfo': extract_dictionary('SkillInfo'),
|
|
'MasteryInfo': extract_dictionary('MasteryInfo')
|
|
}
|
|
|
|
# Print summary
|
|
for dict_name, dict_data in dictionaries.items():
|
|
print(f"{dict_name}: {len(dict_data)} entries")
|
|
if dict_data and dict_name == 'AttributeSetInfo':
|
|
# Show some equipment set examples
|
|
for set_id in ['13', '14', '16', '21']:
|
|
if set_id in dict_data:
|
|
print(f" {set_id} -> {dict_data[set_id]}")
|
|
|
|
# Save to file
|
|
with open('extracted_dictionaries.json', 'w') as f:
|
|
json.dump(dictionaries, f, indent=2)
|
|
|
|
print("\nDictionaries saved to extracted_dictionaries.json")
|
|
|
|
if __name__ == "__main__":
|
|
main()
|