验证BallController导入修复.py 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. """
  4. BallController配置导入修复验证脚本
  5. 用于验证config_manager.py中的BallController导入功能是否正常工作
  6. """
  7. import sys
  8. import os
  9. import json
  10. from pathlib import Path
  11. # 添加当前目录到Python路径
  12. sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
  13. def test_ballcontroller_import():
  14. """测试BallController配置导入功能"""
  15. print("=== BallController配置导入修复验证 ===")
  16. # 检查必要文件是否存在
  17. excel_file = Path("BallController标准配置表.xlsx")
  18. json_file = Path("../ballController.json")
  19. if not excel_file.exists():
  20. print(f"❌ Excel文件不存在: {excel_file}")
  21. return False
  22. if not json_file.exists():
  23. print(f"❌ JSON文件不存在: {json_file}")
  24. return False
  25. print(f"✓ Excel文件存在: {excel_file}")
  26. print(f"✓ JSON文件存在: {json_file}")
  27. # 读取JSON配置
  28. try:
  29. with open(json_file, 'r', encoding='utf-8') as f:
  30. config_data = json.load(f)
  31. print(f"✓ JSON文件读取成功")
  32. except Exception as e:
  33. print(f"❌ JSON文件读取失败: {e}")
  34. return False
  35. # 验证必要参数
  36. expected_params = [
  37. 'baseSpeed', 'maxReflectionRandomness', 'antiTrapTimeWindow', 'antiTrapHitThreshold',
  38. 'deflectionAttemptThreshold', 'antiTrapDeflectionMultiplier', 'FIRE_COOLDOWN', 'ballRadius',
  39. 'gravityScale', 'linearDamping', 'angularDamping', 'colliderGroup',
  40. 'colliderTag', 'friction', 'restitution', 'safeDistance',
  41. 'edgeOffset', 'sensor', 'maxAttempts'
  42. ]
  43. missing_params = [param for param in expected_params if param not in config_data]
  44. if missing_params:
  45. print(f"❌ 缺少参数: {missing_params}")
  46. return False
  47. print(f"✓ 所有19个参数都存在")
  48. # 验证数据类型
  49. type_checks = {
  50. 'baseSpeed': (int, float),
  51. 'sensor': (bool,),
  52. 'colliderGroup': (int,),
  53. 'maxAttempts': (int,)
  54. }
  55. for param, expected_types in type_checks.items():
  56. actual_type = type(config_data[param])
  57. if actual_type not in expected_types:
  58. print(f"❌ 参数 {param} 类型错误: 期望 {expected_types}, 实际 {actual_type}")
  59. return False
  60. print(f"✓ 关键参数数据类型正确")
  61. # 显示配置摘要
  62. print(f"\n=== 配置摘要 ===")
  63. print(f"基础速度: {config_data['baseSpeed']}")
  64. print(f"球半径: {config_data['ballRadius']}")
  65. print(f"重力缩放: {config_data['gravityScale']}")
  66. print(f"传感器模式: {config_data['sensor']}")
  67. print(f"碰撞组: {config_data['colliderGroup']}")
  68. print(f"\n✅ BallController配置导入功能验证通过!")
  69. return True
  70. def main():
  71. """主函数"""
  72. try:
  73. success = test_ballcontroller_import()
  74. if success:
  75. print(f"\n🎉 修复验证成功!BallController配置导入功能正常工作。")
  76. return 0
  77. else:
  78. print(f"\n❌ 修复验证失败!请检查配置导入功能。")
  79. return 1
  80. except Exception as e:
  81. print(f"\n💥 验证过程中发生错误: {e}")
  82. import traceback
  83. traceback.print_exc()
  84. return 1
  85. if __name__ == "__main__":
  86. exit(main())