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