/*
文件名:OfficialProject.nut
路径:Dps_A/BaseClass/OfficialProject/OfficialProject.nut
创建日期:2025-03-30	00:03
文件用途:官方项目
*/
class _Official_Project_ {
    ReloadProjectMap = null;

    constructor() {
        //在全局中注册自己
        getroottable()._GlobalOfficial_Project <- this;
        ReloadProjectMap = {};


        Init();
    }

    function Init() {
        // 定义 ANSI 颜色代码
        local COLOR_RESET = "\x1b[0m";
        local COLOR_MAGENTA = "\x1b[95m";
        local COLOR_CYAN = "\x1b[96m";
        local COLOR_YELLOW = "\x1b[93m";
        local COLOR_RED = "\x1b[91m";


        local WorkPath = "/dp_s/OfficialProject";
        local Dirs = sq_GetListDirs(WorkPath);
        if (Dirs.len() > 0) {
            print(format("\n\n\t\t\t\t%s开始加载DP-S插件市场项目%s", COLOR_YELLOW, COLOR_RESET));
        }
        foreach(DirPath in Dirs) {
            local FilePaths = sq_GetListFiles(WorkPath + "/" + DirPath);

            foreach(FilePath in FilePaths) {
                //找到项目文件
                if (FilePath == "Proj.ifo") {
                    local Config = sq_ReadJsonFile(WorkPath + "/" + DirPath + "/" + FilePath);
                    if (Config) {
                        try {
                            //读取配置文件建立Map
                            local ProjectConfig = Config.ProjectConfig;
                            if (ProjectConfig.len() > 0) {
                                ReloadProjectMap.rawset(ProjectConfig, Config.ProjectRunFunc);
                            }

                            local ProjectFiles = Config.ProjectFiles;
                            //载入所有项目文件
                            foreach(ProjectFile in ProjectFiles) {
                                sq_RunScript("OfficialProject/" + DirPath + "/" + ProjectFile);
                            }
                            //调用启动函数
                            getroottable()[Config.ProjectRunFunc]();
                            //播报脚本已加载
                            print(format("%s[ %s ]%s" + " 脚本项目已加载 --- 当前版本: %s%.2f%s", COLOR_YELLOW, Config.ProjectName, COLOR_RESET, COLOR_YELLOW, Config.ProjectVersion, COLOR_RESET));
                        } catch (exception) {
                            //播报脚本未加载
                            print(format("%s[ %s ]%s" + " 脚本项目未加载 --- 当前版本: %s%.2f%s", COLOR_RED, Config.ProjectName, COLOR_RESET, COLOR_RED, Config.ProjectVersion, COLOR_RESET));
                            print(exception);
                        }
                    }
                }
            }
        }
    }
}