validate_shader_config.py 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. #!/usr/bin/env python3
  2. """
  3. Validation script for nation-troop shader configurations.
  4. Ensures all 12 combinations have proper vertex and fragment shaders.
  5. """
  6. import os
  7. import re
  8. import sys
  9. # Configuration
  10. SHADER_DIR = "assets/shaders"
  11. STYLE_DIR = "render/entity/nations"
  12. NATIONS = {
  13. # Maps directory name to nation ID used in shader naming
  14. "roman": "roman_republic",
  15. "carthage": "carthage"
  16. }
  17. TROOPS = ["archer", "swordsman", "spearman", "horse_swordsman"]
  18. def check_shader_files():
  19. """Check if all required shader files exist."""
  20. missing = []
  21. for troop in TROOPS:
  22. for nation_short, nation_full in NATIONS.items():
  23. shader_name = f"{troop}_{nation_full}"
  24. vert_file = os.path.join(SHADER_DIR, f"{shader_name}.vert")
  25. frag_file = os.path.join(SHADER_DIR, f"{shader_name}.frag")
  26. if not os.path.exists(vert_file):
  27. missing.append(f"Vertex shader: {vert_file}")
  28. if not os.path.exists(frag_file):
  29. missing.append(f"Fragment shader: {frag_file}")
  30. return missing
  31. def check_style_configs():
  32. """Check if style configurations match shader files."""
  33. issues = []
  34. for troop in TROOPS:
  35. for nation_short, nation_full in NATIONS.items():
  36. expected_shader = f"{troop}_{nation_full}"
  37. style_file = os.path.join(STYLE_DIR, nation_short, f"{troop}_style.cpp")
  38. if not os.path.exists(style_file):
  39. issues.append(f"Missing style file: {style_file}")
  40. continue
  41. with open(style_file, 'r') as f:
  42. content = f.read()
  43. # Look for shader_id assignment
  44. shader_id_pattern = r'shader_id\s*=\s*"([^"]+)"'
  45. matches = re.findall(shader_id_pattern, content)
  46. if not matches:
  47. issues.append(f"{nation_short}/{troop}: No shader_id found in {style_file}")
  48. elif matches[0] != expected_shader:
  49. issues.append(
  50. f"{nation_short}/{troop}: shader_id is '{matches[0]}' "
  51. f"but should be '{expected_shader}'"
  52. )
  53. return issues
  54. def main():
  55. """Run all validations and report results."""
  56. print("=" * 80)
  57. print("Nation-Troop Shader Configuration Validation")
  58. print("=" * 80)
  59. print()
  60. # Check shader files
  61. print("Checking shader files...")
  62. missing_shaders = check_shader_files()
  63. if missing_shaders:
  64. print("✗ Missing shader files:")
  65. for item in missing_shaders:
  66. print(f" - {item}")
  67. else:
  68. print("✓ All shader files present")
  69. print()
  70. # Check style configurations
  71. print("Checking style configurations...")
  72. config_issues = check_style_configs()
  73. if config_issues:
  74. print("✗ Configuration issues:")
  75. for item in config_issues:
  76. print(f" - {item}")
  77. else:
  78. print("✓ All style configurations valid")
  79. print()
  80. print("=" * 80)
  81. # Summary
  82. total_issues = len(missing_shaders) + len(config_issues)
  83. total_combinations = len(TROOPS) * len(NATIONS)
  84. if total_issues == 0:
  85. print("✓ VALIDATION PASSED")
  86. print()
  87. print(f"All {total_combinations} nation-troop combinations ({len(NATIONS)} nations × {len(TROOPS)} troop types) are properly configured.")
  88. return 0
  89. else:
  90. print("✗ VALIDATION FAILED")
  91. print()
  92. print(f"Found {total_issues} issue(s) that need to be fixed.")
  93. return 1
  94. if __name__ == "__main__":
  95. sys.exit(main())