#!/usr/bin/env python3 """ Extract enum definitions from Mag-Plugins C# files into JSON mappings. This script parses the IntValueKey.cs file to create a mapping between numeric enum values and their human-readable names for inventory processing. """ import re import json import os from pathlib import Path def extract_int_value_enums(cs_file_path): """Extract IntValueKey enum definitions from C# file.""" with open(cs_file_path, 'r') as f: content = f.read() # Pattern to match enum entries: EnumName = Value, pattern = r'^\s*(?:\[[^\]]+\])?\s*(\w+)\s*=\s*(\d+),?\s*(?://.*)?$' enums = {} in_enum = False for line in content.split('\n'): # Check if we're entering the enum if 'enum IntValueKey' in line: in_enum = True continue # Check if we're exiting the enum if in_enum and line.strip() == '}': break # Parse enum entries if in_enum: match = re.match(pattern, line) if match: name = match.group(1) value = int(match.group(2)) enums[value] = name return enums def create_property_mappings(): """Create organized property mappings for different item aspects.""" # Based on analysis of the enum values and common item properties property_categories = { 'basic': { 5: 'encumbrance', # EncumbranceVal 19: 'value', # Value 25: 'level', # Level 28: 'armor_level', # ArmorLevel 44: 'damage', # Damage 45: 'damage_type', # DamageType }, 'requirements': { 158: 'wield_requirement', # Common wield requirement key (from JSON data) 160: 'wield_level', # Common wield level key (from JSON data) 48: 'weapon_skill', # WeaponSkill }, 'combat': { 218103842: 'max_damage', # MaxDamage_Decal 36: 'resist_magic', # ResistMagic 56: 'shield_value', # ShieldValue }, 'display': { 218103809: 'icon', # Icon_Decal_DID 218103849: 'icon_overlay', # IconOverlay_Decal_DID 218103850: 'icon_underlay', # IconUnderlay_Decal_DID }, 'metadata': { 218103808: 'weenie_class_id', # WeenieClassId_Decal 218103847: 'physics_data_flags', # PhysicsDataFlags_Decal 218103831: 'object_desc_flags', # ObjectDescriptionFlags_Decal } } return property_categories def main(): """Main extraction process.""" # Paths mag_plugins_path = Path('/home/erik/MosswartOverlord/Mag-Plugins') int_value_key_path = mag_plugins_path / 'Shared' / 'Constants' / 'IntValueKey.cs' output_dir = Path('/home/erik/MosswartOverlord/inventory-service') # Create output directory output_dir.mkdir(exist_ok=True) # Extract all enum values print("Extracting IntValueKey enums...") int_enums = extract_int_value_enums(int_value_key_path) print(f"Found {len(int_enums)} enum definitions") # Create property categories property_categories = create_property_mappings() # Save complete enum mapping enum_output = output_dir / 'int_value_enums.json' with open(enum_output, 'w') as f: json.dump(int_enums, f, indent=2) print(f"Saved complete enum mapping to {enum_output}") # Save categorized mappings categories_output = output_dir / 'property_categories.json' with open(categories_output, 'w') as f: json.dump(property_categories, f, indent=2) print(f"Saved property categories to {categories_output}") # Print some interesting findings print("\nKey mappings found:") interesting_keys = [5, 19, 28, 44, 158, 160, 218103809, 218103842, 218103847, 218103849] for key in interesting_keys: if key in int_enums: print(f" {key}: {int_enums[key]}") print(f"\nFiles created in {output_dir}/") print("- int_value_enums.json: Complete enum mapping") print("- property_categories.json: Organized property categories") if __name__ == '__main__': main()