#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ BallController配置应用验证脚本 用于验证BallController.ts是否正确应用了ballController.json中的配置数据 """ import json import os from pathlib import Path def verify_ballcontroller_config_application(): """验证BallController配置应用""" print("=== BallController配置应用验证 ===") # 检查配置文件 config_file = Path("assets/resources/data/ballController.json") if not config_file.exists(): print(f"❌ 配置文件不存在: {config_file}") return False # 读取配置数据 try: with open(config_file, 'r', encoding='utf-8') as f: config_data = json.load(f) print(f"✓ 配置文件读取成功: {config_file}") except Exception as e: print(f"❌ 配置文件读取失败: {e}") return False # 检查BallController.ts文件 ballcontroller_file = Path("assets/scripts/CombatSystem/BallController.ts") if not ballcontroller_file.exists(): print(f"❌ BallController.ts文件不存在: {ballcontroller_file}") return False # 读取BallController.ts内容 try: with open(ballcontroller_file, 'r', encoding='utf-8') as f: ts_content = f.read() print(f"✓ BallController.ts文件读取成功") except Exception as e: print(f"❌ BallController.ts文件读取失败: {e}") return False # 验证配置接口 config_interface_file = Path("assets/scripts/Core/ConfigManager.ts") if not config_interface_file.exists(): print(f"❌ ConfigManager.ts文件不存在: {config_interface_file}") return False try: with open(config_interface_file, 'r', encoding='utf-8') as f: interface_content = f.read() print(f"✓ ConfigManager.ts文件读取成功") except Exception as e: print(f"❌ ConfigManager.ts文件读取失败: {e}") return False print(f"\n=== 配置数据分析 ===") print(f"配置文件中的参数数量: {len(config_data)}") # 验证关键配置参数 key_params = { 'baseSpeed': config_data.get('baseSpeed'), 'maxReflectionRandomness': config_data.get('maxReflectionRandomness'), 'FIRE_COOLDOWN': config_data.get('FIRE_COOLDOWN'), 'ballRadius': config_data.get('ballRadius'), 'maxAttempts': config_data.get('maxAttempts') } for param, value in key_params.items(): print(f"{param}: {value}") # 检查接口定义 print(f"\n=== 接口定义检查 ===") interface_checks = { 'baseSpeed: number': 'baseSpeed: number' in interface_content, 'maxReflectionRandomness: number': 'maxReflectionRandomness: number' in interface_content, 'FIRE_COOLDOWN: number': 'FIRE_COOLDOWN: number' in interface_content, 'ballRadius: number': 'ballRadius: number' in interface_content, 'maxAttempts: number': 'maxAttempts: number' in interface_content } for check, result in interface_checks.items(): status = "✓" if result else "❌" print(f"{status} {check}: {result}") # 检查BallController中的配置应用 print(f"\n=== BallController配置应用检查 ===") application_checks = { '配置加载方法': 'loadConfig()' in ts_content, '配置应用方法': 'applyConfig()' in ts_content, 'baseSpeed应用': 'this.baseSpeed = this.config.baseSpeed' in ts_content, 'FIRE_COOLDOWN应用': 'this.FIRE_COOLDOWN = this.config.FIRE_COOLDOWN' in ts_content, 'maxAttempts getter': 'get maxAttempts()' in ts_content, '默认配置包含maxAttempts': 'maxAttempts: 50' in ts_content } for check, result in application_checks.items(): status = "✓" if result else "❌" print(f"{status} {check}: {result}") # 检查配置值的一致性 print(f"\n=== 配置值一致性检查 ===") # 检查JSON中的值是否与预期一致 expected_values = { 'baseSpeed': 30, 'FIRE_COOLDOWN': 0.05, 'ballRadius': 25, 'maxAttempts': 50 } consistency_passed = True for param, expected in expected_values.items(): actual = config_data.get(param) if actual == expected: print(f"✓ {param}: {actual} (符合预期)") else: print(f"❌ {param}: {actual} (预期: {expected})") consistency_passed = False # 总结 print(f"\n=== 验证总结 ===") all_interface_checks_passed = all(interface_checks.values()) all_application_checks_passed = all(application_checks.values()) if all_interface_checks_passed and all_application_checks_passed and consistency_passed: print(f"✅ BallController配置应用验证通过!") print(f" - 配置接口定义完整") print(f" - 配置应用逻辑正确") print(f" - 配置值一致性良好") return True else: print(f"❌ BallController配置应用验证失败!") if not all_interface_checks_passed: print(f" - 配置接口定义不完整") if not all_application_checks_passed: print(f" - 配置应用逻辑有问题") if not consistency_passed: print(f" - 配置值不一致") return False def main(): """主函数""" try: success = verify_ballcontroller_config_application() 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())