#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ BallController配置导入修复验证脚本 用于验证config_manager.py中的BallController导入功能是否正常工作 """ import sys import os import json from pathlib import Path # 添加当前目录到Python路径 sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) def test_ballcontroller_import(): """测试BallController配置导入功能""" print("=== BallController配置导入修复验证 ===") # 检查必要文件是否存在 excel_file = Path("BallController标准配置表.xlsx") json_file = Path("../ballController.json") if not excel_file.exists(): print(f"❌ Excel文件不存在: {excel_file}") return False if not json_file.exists(): print(f"❌ JSON文件不存在: {json_file}") return False print(f"✓ Excel文件存在: {excel_file}") print(f"✓ JSON文件存在: {json_file}") # 读取JSON配置 try: with open(json_file, 'r', encoding='utf-8') as f: config_data = json.load(f) print(f"✓ JSON文件读取成功") except Exception as e: print(f"❌ JSON文件读取失败: {e}") return False # 验证必要参数 expected_params = [ 'baseSpeed', 'maxReflectionRandomness', 'antiTrapTimeWindow', 'antiTrapHitThreshold', 'deflectionAttemptThreshold', 'antiTrapDeflectionMultiplier', 'FIRE_COOLDOWN', 'ballRadius', 'gravityScale', 'linearDamping', 'angularDamping', 'colliderGroup', 'colliderTag', 'friction', 'restitution', 'safeDistance', 'edgeOffset', 'sensor', 'maxAttempts' ] missing_params = [param for param in expected_params if param not in config_data] if missing_params: print(f"❌ 缺少参数: {missing_params}") return False print(f"✓ 所有19个参数都存在") # 验证数据类型 type_checks = { 'baseSpeed': (int, float), 'sensor': (bool,), 'colliderGroup': (int,), 'maxAttempts': (int,) } for param, expected_types in type_checks.items(): actual_type = type(config_data[param]) if actual_type not in expected_types: print(f"❌ 参数 {param} 类型错误: 期望 {expected_types}, 实际 {actual_type}") return False print(f"✓ 关键参数数据类型正确") # 显示配置摘要 print(f"\n=== 配置摘要 ===") print(f"基础速度: {config_data['baseSpeed']}") print(f"球半径: {config_data['ballRadius']}") print(f"重力缩放: {config_data['gravityScale']}") print(f"传感器模式: {config_data['sensor']}") print(f"碰撞组: {config_data['colliderGroup']}") print(f"\n✅ BallController配置导入功能验证通过!") return True def main(): """主函数""" try: success = test_ballcontroller_import() if success: print(f"\n🎉 修复验证成功!BallController配置导入功能正常工作。") return 0 else: print(f"\n❌ 修复验证失败!请检查配置导入功能。") return 1 except Exception as e: print(f"\n💥 验证过程中发生错误: {e}") import traceback traceback.print_exc() return 1 if __name__ == "__main__": exit(main())