#!/usr/bin/env python # -*- coding: utf-8 -*- """ NexusLauncher 插件系统 提供 DCC 软件的插件启动功能 """ import os from typing import Optional, Dict # 导入模块 from plugins.maya import launch_maya from plugins.substancepainter import launch_substance_painter from config.constants import APP_ICON_MAPPING class PluginLauncher: """插件启动器 - 统一的启动接口""" @staticmethod def _get_app_type(app_name: str) -> Optional[str]: """通过 APP_ICON_MAPPING 识别应用类型 Args: app_name: 应用名称 Returns: 应用类型 (Maya, SubstancePainter 等) 或 None """ app_name_lower = app_name.lower() # 遍历映射表查找匹配 for key, app_type in APP_ICON_MAPPING.items(): if key in app_name_lower: return app_type return None @staticmethod def launch_with_plugins(app_name: str, app_path: str, plugin_config: Optional[Dict[str, str]] = None, project_name: str = "NexusLauncher") -> bool: """根据应用类型启动应用并加载插件 Args: app_name: 应用名称 app_path: 应用可执行文件路径 plugin_config: 插件配置字典,包含 maya_plugin_path, sp_shelf_path 等 project_name: 项目名称,用于 SP 库名称等 Returns: 是否成功启动 """ if not plugin_config: print(f"[INFO] No plugin config provided, launching {app_name} normally") return False # 通过 APP_ICON_MAPPING 识别应用类型 app_type = PluginLauncher._get_app_type(app_name) if not app_type: print(f"[INFO] Unknown app type for {app_name}, launching normally") return False print(f"[INFO] Detected app type: {app_type}") # Maya if app_type == "Maya": maya_plugin_path = plugin_config.get('maya_plugin_path') if maya_plugin_path: print(f"[INFO] Launching Maya with plugins from: {maya_plugin_path}") return launch_maya(app_path, maya_plugin_path) else: print(f"[WARNING] maya_plugin_path not found in config") return False # Substance Painter elif app_type == "SubstancePainter": sp_shelf_path = plugin_config.get('sp_shelf_path') if sp_shelf_path: print(f"[INFO] Launching Substance Painter with shelf: {sp_shelf_path}") print(f"[INFO] Project: {project_name}") return launch_substance_painter(app_path, sp_shelf_path, project_name) else: print(f"[WARNING] sp_shelf_path not found in config") return False # 不支持的应用类型 else: print(f"[INFO] No plugin support for {app_type}, launching normally") return False __all__ = ['PluginLauncher', 'launch_maya', 'launch_substance_painter']