AeThex-Engine-Core/tools/generate_from_config.py

127 lines
3.9 KiB
Python

#!/usr/bin/env python3
"""
Generate logos from logo-config.toml
Edit the config file in VS Code, then run this script
"""
import sys
from pathlib import Path
try:
import tomli
except ImportError:
print("❌ tomli not installed. Installing...")
import subprocess
subprocess.check_call([sys.executable, '-m', 'pip', 'install', 'tomli'])
import tomli
def create_svg_defs():
"""Standard gradients and filters"""
return ''' <defs>
<linearGradient id="grad1" x1="0%" y1="0%" x2="100%" y2="100%">
<stop offset="0%" style="stop-color:#A855F7"/>
<stop offset="50%" style="stop-color:#8B5CF6"/>
<stop offset="100%" style="stop-color:#7C3AED"/>
</linearGradient>
<linearGradient id="textGrad" x1="0%" y1="0%" x2="100%" y2="0%">
<stop offset="0%" style="stop-color:#8B5CF6"/>
<stop offset="100%" style="stop-color:#06B6D4"/>
</linearGradient>
<filter id="glow">
<feGaussianBlur stdDeviation="2" result="coloredBlur"/>
<feMerge>
<feMergeNode in="coloredBlur"/>
<feMergeNode in="SourceGraphic"/>
</feMerge>
</filter>
</defs>
'''
def element_to_svg(elem):
"""Convert element dict to SVG tag"""
elem_type = elem.pop('type')
# Handle special cases
if 'filter' in elem and elem['filter'] == 'glow':
elem['filter'] = 'url(#glow)'
# Build attributes string
attrs = ' '.join(f'{k.replace("_", "-")}="{v}"' for k, v in elem.items() if k != 'content')
# Return appropriate tag
if elem_type == 'text':
content = elem.get('content', '')
return f' <text {attrs}>{content}</text>'
elif elem_type in ['circle', 'rect', 'line']:
return f' <{elem_type} {attrs}/>'
elif elem_type in ['path', 'polygon']:
return f' <{elem_type} {attrs}/>'
else:
return f' <!-- Unknown type: {elem_type} -->'
def generate_logo(logo_config):
"""Generate SVG from logo config"""
width = logo_config.get('width', 200)
height = logo_config.get('height', 200)
name = logo_config.get('name', 'logo')
svg = f'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 {width} {height}" width="{width}" height="{height}">\n'
svg += create_svg_defs()
# Add all elements
for elem in logo_config.get('elements', []):
# Make a copy to avoid modifying original
elem_copy = elem.copy()
svg += element_to_svg(elem_copy) + '\n'
svg += '</svg>'
return svg
def main():
config_file = Path('logo-config.toml')
if not config_file.exists():
print(f"❌ Config file not found: {config_file}")
print("Create logo-config.toml first!")
return
print("🎨 Reading logo configuration...\n")
with open(config_file, 'rb') as f:
config = tomli.load(f)
if 'logo' not in config:
print("❌ No [[logo]] sections found in config")
return
logos = config['logo']
if not isinstance(logos, list):
logos = [logos]
print(f"Found {len(logos)} logo(s) to generate\n")
for logo_config in logos:
name = logo_config.get('name', 'unnamed')
output_path = Path(logo_config.get('output', f'assets/{name}.svg'))
# Ensure output directory exists
output_path.parent.mkdir(parents=True, exist_ok=True)
# Generate SVG
svg_content = generate_logo(logo_config)
# Write to file
output_path.write_text(svg_content)
element_count = len(logo_config.get('elements', []))
print(f"{name}")
print(f" └─ {output_path} ({element_count} elements)")
print(f"\n✅ Generated {len(logos)} logo(s)!")
print("\nTo modify logos:")
print("1. Edit logo-config.toml in VS Code")
print("2. Run: python3 tools/generate_from_config.py")
print("3. View: xdg-open assets/logo.svg")
if __name__ == '__main__':
main()