72 lines
		
	
	
		
			2.8 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
		
		
			
		
	
	
			72 lines
		
	
	
		
			2.8 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
| 
								 | 
							
								import json
							 | 
						|||
| 
								 | 
							
								import os
							 | 
						|||
| 
								 | 
							
								import argparse
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
							 | 
						|||
| 
								 | 
							
								EXPORT_ENEMIES = os.path.join(ROOT, 'warframe-public-export-plus', 'ExportEnemies.json')
							 | 
						|||
| 
								 | 
							
								DICT_DIR = os.path.join(ROOT, 'warframe-public-export-plus')
							 | 
						|||
| 
								 | 
							
								OUTPUT = os.path.join(ROOT, 'Scripts', 'EnemyNameOverrides.pluto')
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								# 解析命令行:选择语言(默认 zh)
							 | 
						|||
| 
								 | 
							
								parser = argparse.ArgumentParser(description='生成 Agent 路径到本地化名称的覆盖表(Pluto 模块)')
							 | 
						|||
| 
								 | 
							
								parser.add_argument('--lang', default='zh', help='语言代码,如 zh/en/ko/ja 等;默认 zh')
							 | 
						|||
| 
								 | 
							
								args = parser.parse_args()
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								dict_path = os.path.join(DICT_DIR, f'dict.{args.lang}.json')
							 | 
						|||
| 
								 | 
							
								if not os.path.exists(dict_path):
							 | 
						|||
| 
								 | 
							
								    fallback = os.path.join(DICT_DIR, 'dict.en.json')
							 | 
						|||
| 
								 | 
							
								    if not os.path.exists(fallback):
							 | 
						|||
| 
								 | 
							
								        raise SystemExit(f'找不到语言文件 {dict_path},且英文回退 {fallback} 也不存在。')
							 | 
						|||
| 
								 | 
							
								    print(f'警告:{dict_path} 不存在,改用 {fallback}')
							 | 
						|||
| 
								 | 
							
								    dict_path = fallback
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								# 读取导出文件与语言字典
							 | 
						|||
| 
								 | 
							
								with open(EXPORT_ENEMIES, 'r', encoding='utf-8') as f:
							 | 
						|||
| 
								 | 
							
								    enemies = json.load(f)
							 | 
						|||
| 
								 | 
							
								with open(dict_path, 'r', encoding='utf-8') as f:
							 | 
						|||
| 
								 | 
							
								    dict_lang = json.load(f)
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								# 构建映射:本地化名称 -> Agent 路径
							 | 
						|||
| 
								 | 
							
								name_to_path = {}
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								agents = enemies.get('agents') or {}
							 | 
						|||
| 
								 | 
							
								avatars = enemies.get('avatars') or {}
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								for agent_path, agent_def in agents.items():
							 | 
						|||
| 
								 | 
							
								    if not isinstance(agent_def, dict):
							 | 
						|||
| 
								 | 
							
								        continue
							 | 
						|||
| 
								 | 
							
								    avatar_types = agent_def.get('avatarTypes') or {}
							 | 
						|||
| 
								 | 
							
								    avatar_path = avatar_types.get('STANDARD')
							 | 
						|||
| 
								 | 
							
								    if not avatar_path:
							 | 
						|||
| 
								 | 
							
								        continue
							 | 
						|||
| 
								 | 
							
								    # Find avatar entry to get name locTag
							 | 
						|||
| 
								 | 
							
								    avatar_def = avatars.get(avatar_path)
							 | 
						|||
| 
								 | 
							
								    if not isinstance(avatar_def, dict):
							 | 
						|||
| 
								 | 
							
								        continue
							 | 
						|||
| 
								 | 
							
								    loc_tag = avatar_def.get('name')
							 | 
						|||
| 
								 | 
							
								    if not isinstance(loc_tag, str):
							 | 
						|||
| 
								 | 
							
								        continue
							 | 
						|||
| 
								 | 
							
								    name = dict_lang.get(loc_tag) or loc_tag
							 | 
						|||
| 
								 | 
							
								    if name not in name_to_path:  # 避免重名覆盖
							 | 
						|||
| 
								 | 
							
								        name_to_path[name] = agent_path
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								# 输出 Pluto 表:键=名称,值=路径
							 | 
						|||
| 
								 | 
							
								lines = []
							 | 
						|||
| 
								 | 
							
								lines.append(f"-- 由 Tools/generate_enemy_name_overrides.py 自动生成(语言: {os.path.basename(dict_path)})\n")
							 | 
						|||
| 
								 | 
							
								lines.append("-- 键:本地化名称;值:Agent 路径\n")
							 | 
						|||
| 
								 | 
							
								lines.append("return {\n")
							 | 
						|||
| 
								 | 
							
								sorted_names = sorted(name_to_path.keys())
							 | 
						|||
| 
								 | 
							
								for i, name in enumerate(sorted_names):
							 | 
						|||
| 
								 | 
							
								    k = str(name).replace('\\', '\\\\').replace('"', '\\"').replace('\n', ' ').replace('\r', '')
							 | 
						|||
| 
								 | 
							
								    v = str(name_to_path[name]).replace('\\', '\\\\').replace('"', '\\"')
							 | 
						|||
| 
								 | 
							
								    # 最后一项不加逗号
							 | 
						|||
| 
								 | 
							
								    comma = "," if i < len(sorted_names) - 1 else ""
							 | 
						|||
| 
								 | 
							
								    lines.append(f'    ["{k}"] = "{v}"{comma}\n')
							 | 
						|||
| 
								 | 
							
								lines.append("}\n")
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								os.makedirs(os.path.dirname(OUTPUT), exist_ok=True)
							 | 
						|||
| 
								 | 
							
								with open(OUTPUT, 'w', encoding='utf-8') as f:
							 | 
						|||
| 
								 | 
							
								    f.writelines(lines)
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								print(f"已写入 {len(name_to_path)} 条到 {OUTPUT}")
							 |