121 lines
No EOL
4.2 KiB
Python
121 lines
No EOL
4.2 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
Extract spell names from Mag-Plugins/Shared/Spells/Spells.csv for spell ID translation.
|
|
"""
|
|
|
|
import csv
|
|
import json
|
|
from pathlib import Path
|
|
|
|
def extract_spell_names():
|
|
"""Extract spell ID to name mappings from Spells.csv."""
|
|
|
|
csv_path = Path('/home/erik/MosswartOverlord/Mag-Plugins/Shared/Spells/Spells.csv')
|
|
|
|
if not csv_path.exists():
|
|
print(f"❌ Spells.csv not found at {csv_path}")
|
|
return {}
|
|
|
|
spell_mappings = {}
|
|
|
|
# Try different encodings
|
|
encodings = ['utf-8', 'latin-1', 'windows-1252', 'utf-8-sig']
|
|
|
|
for encoding in encodings:
|
|
try:
|
|
with open(csv_path, 'r', encoding=encoding) as f:
|
|
reader = csv.DictReader(f)
|
|
print(f"✓ Successfully opened with {encoding} encoding")
|
|
|
|
for row in reader:
|
|
try:
|
|
spell_id = int(row['Id'])
|
|
spell_name = row['Name'].strip()
|
|
spell_description = row.get('Description', '').strip()
|
|
spell_school = row.get('School', '').strip()
|
|
spell_family = row.get('Family', '').strip()
|
|
spell_difficulty = row.get('Difficulty', '').strip()
|
|
spell_duration = row.get('Duration', '').strip()
|
|
spell_mana = row.get('Mana', '').strip()
|
|
|
|
# Create comprehensive spell data
|
|
spell_data = {
|
|
'name': spell_name,
|
|
'description': spell_description,
|
|
'school': spell_school,
|
|
'family': spell_family,
|
|
'difficulty': spell_difficulty,
|
|
'duration': spell_duration,
|
|
'mana': spell_mana
|
|
}
|
|
|
|
spell_mappings[spell_id] = spell_data
|
|
|
|
except (ValueError, KeyError) as e:
|
|
print(f"⚠️ Skipping invalid row: {e}")
|
|
continue
|
|
|
|
# If we get here successfully, we're done
|
|
break
|
|
|
|
except Exception as e:
|
|
print(f"❌ Error with {encoding} encoding: {e}")
|
|
continue
|
|
|
|
if spell_mappings:
|
|
print(f"✓ Extracted {len(spell_mappings)} spell entries")
|
|
else:
|
|
print("❌ Failed to extract spells with any encoding")
|
|
|
|
return spell_mappings
|
|
|
|
def save_spell_database(spell_mappings):
|
|
"""Save spell mappings to JSON file."""
|
|
|
|
output_path = Path('/home/erik/MosswartOverlord/inventory-service/spell_database.json')
|
|
|
|
spell_database = {
|
|
'metadata': {
|
|
'version': '1.0.0',
|
|
'source': 'Mag-Plugins/Shared/Spells/Spells.csv',
|
|
'total_spells': len(spell_mappings),
|
|
'description': 'Spell ID to name/data mappings for Asheron\'s Call'
|
|
},
|
|
'spells': spell_mappings
|
|
}
|
|
|
|
try:
|
|
with open(output_path, 'w', encoding='utf-8') as f:
|
|
json.dump(spell_database, f, indent=2, ensure_ascii=False)
|
|
|
|
print(f"✓ Spell database saved to {output_path}")
|
|
return True
|
|
|
|
except Exception as e:
|
|
print(f"❌ Error saving spell database: {e}")
|
|
return False
|
|
|
|
def main():
|
|
"""Main extraction process."""
|
|
print("Extracting spell names from Spells.csv...")
|
|
|
|
# Extract spell mappings
|
|
spell_mappings = extract_spell_names()
|
|
|
|
if not spell_mappings:
|
|
print("❌ No spells extracted")
|
|
return
|
|
|
|
# Save to JSON file
|
|
if save_spell_database(spell_mappings):
|
|
# Show some sample spells
|
|
print("\nSample spell entries:")
|
|
for spell_id, spell_data in list(spell_mappings.items())[:5]:
|
|
print(f" {spell_id}: {spell_data['name']} ({spell_data['school']})")
|
|
|
|
print(f"\n✓ Successfully processed {len(spell_mappings)} spells")
|
|
else:
|
|
print("❌ Failed to save spell database")
|
|
|
|
if __name__ == "__main__":
|
|
main() |