Ejemplo n.º 1
0
        //"url": "assets/singles/City1.png",
        //"type": "image",
        //"name": "City1"
        public static void Folder2Res(string folderPath, string urlRoot, List <Res> list)
        {
            if (!Directory.Exists(folderPath))
            {
                return;
            }
            DirectoryInfo folder     = new DirectoryInfo(folderPath);
            var           folderName = folder.Name;

            FileInfo[] files = folder.GetFiles();
            foreach (var item in files)
            {
                var ext       = item.Extension;
                var extension = ext.ToLower();
                var name      = item.Name.Split('.');
                var fileName  = name[0];

                Res res = new Res();
                var url = Helper.GetUrl(urlRoot, item.Name + VersionUtils.GetVersion(item.FullName));
                res.Url = url;
                if (Program.AddVersion)
                {
                    res.Url = Program.VersionFolder + "/" + res.Url;
                }
                res.Name = fileName;

                if (extension == ".png" || extension == ".jpg")
                {
                    var existImg = list.Find(n => n.Name == fileName && n.Type == "image");
                    if (existImg != null)
                    {
                        Program.ConsoleLog("存在重复文件名文件" + urlRoot + "/" + item.Name);
                    }

                    var jsonImg = list.Find(n => n.Name == fileName && n.Type == "json");
                    if (jsonImg != null)
                    {
                        //龙骨文件 _png _json
                        res.Name     = fileName + "_png";
                        jsonImg.Name = fileName + "_json";
                    }
                    var fontBin = list.Find(n => n.Name == fileName && n.Type == "font");
                    if (fontBin != null)
                    {
                        //字体 _png _fnt
                        res.Name     = fileName;// fileName + "_png";singles里的字体文件BattleDMG
                        fontBin.Name = fileName + "_fnt";
                    }
                    res.Type = "image";
                }
                else if (extension == ".json")
                {
                    var dragonImg = list.Find(n => n.Name == fileName && n.Type == "image");
                    if (dragonImg != null)
                    {
                        //龙骨文件 _png _json
                        res.Name       = fileName + "_json";
                        dragonImg.Name = fileName + "_png";
                    }
                    res.Type = "json";
                }
                else if (extension == ".txt")
                {
                    res.Type = "text";
                }
                else if (extension == ".ttf" || extension == ".font" || extension == ".fnt")
                {
                    string tempName = "";
                    for (int i = 0; i < name.Length - 1; i++)
                    {
                        tempName += name[i];
                        if (i < name.Length - 2)
                        {
                            tempName += "_";
                        }
                    }
                    res.Name = tempName;

                    var fontImg = list.Find(n => n.Name == fileName && n.Type == "image");
                    if (fontImg != null)
                    {
                        //字体 _png _fnt
                        res.Name     = fileName + "_fnt";
                        fontImg.Name = fileName;// fileName + "_png";singles里的字体文件BattleDMG
                    }

                    res.Type = "font";
                }
                else if (extension == ".mp3" || extension == ".wav" || extension == ".ogg")
                {
                    res.Type = "sound";
                }
                else if (extension == ".spb" || extension == ".sproto")
                {
                    res.Name = fileName + "_" + extension.Replace(".", "");

                    res.Type = "bin";
                }
                else
                {
                    //其他识别为二进制
                    //还有一个sheet

                    res.Type = "bin";
                }
                list.Add(res);

                //检测重名
                FolderGenerate.CheckRepeat(res);
            }
        }
Ejemplo n.º 2
0
        public static void SheetFolder2Res(string folderPath, string urlRoot, List <Res> list)
        {
            if (!Directory.Exists(folderPath))
            {
                return;
            }
            DirectoryInfo folder = new DirectoryInfo(folderPath);

            FileInfo[] files = folder.GetFiles();
            foreach (var item in files)
            {
                var ext       = item.Extension;
                var extension = ext.ToLower();
                var name      = item.Name.Split('.');
                var fileName  = name[0];

                Res res = new Res();
                var url = Helper.GetUrl(urlRoot, item.Name + VersionUtils.GetVersion(item.FullName));
                res.Url  = url;
                res.Name = fileName;

                if (extension == ".png" || extension == ".jpg")
                {
                    res.Type = "image";
                    var existImg = list.Find(n => n.Name == fileName && n.Type == "image");
                    if (existImg != null)
                    {
                        Program.ConsoleLog("存在重复文件名文件" + urlRoot + "/" + item.Name);
                    }
                    var sheetJson = list.Find(n => n.Name == fileName && n.Type == "json");
                    list.Add(res);

                    if (sheetJson != null)
                    {
                        //sheet
                        sheetJson.Type = "sheet";
                        list.Remove(res);

                        var fullName = item.FullName.Replace("png", "json");
                        //subKeys
                        sheetJson.SubKeys = SpecialFolderGenerate.GenerateSubKeys(fullName);
                    }
                }
                else if (extension == ".json")
                {
                    res.Type = "json";
                    var sheetImg = list.Find(n => n.Name == fileName && n.Type == "image");
                    list.Add(res);

                    if (sheetImg != null)
                    {
                        //sheet
                        res.Type = "sheet";
                        list.Remove(sheetImg);

                        //subKeys
                        res.SubKeys = SpecialFolderGenerate.GenerateSubKeys(item.FullName);
                    }
                }
            }
        }