private string GetTexturePackerArguments_PVR_CCZ_TC2_ALPHA(ConvertionParameters parameters)
        {
            string argument;

            if (parameters.NoTrim)
            {
                argument = string.Format(
                    "--format cocos2d-v2 --data \"{0}\" {1}--texture-format pvr3ccz --pvr-quality {2} --opt PVRTCI_2BPP_RGBA --premultiply-alpha --max-size 4096 --size-constraints POT --force-squared --scale {3} --scale-mode Smooth --algorithm MaxRects --maxrects-heuristics Best --pack-mode Best --border-padding 0 --shape-padding 2 --inner-padding 0 --extrude 0 --disable-rotation --trim-mode None \"{4}\"",
                    getPlistFullPath(parameters),
                    GetTrimSpriteNamesArgument(),
                    GetPvrCczQuality(parameters),
                    parameters.Scale,
                    parameters.SrcDir.FullName);
            }
            else
            {
                argument = string.Format(
                    "--format cocos2d-v2 --data \"{0}\" {1}--texture-format pvr3ccz --pvr-quality {2} --opt PVRTCI_2BPP_RGBA --premultiply-alpha --max-size 4096 --size-constraints POT --force-squared --scale {3} --scale-mode Smooth --algorithm MaxRects --maxrects-heuristics Best --pack-mode Best --border-padding 0 --shape-padding 2 --inner-padding 0 --extrude 0 --enable-rotation --trim-mode Trim --trim-threshold 2 \"{4}\"",
                    getPlistFullPath(parameters),
                    GetTrimSpriteNamesArgument(),
                    GetPvrCczQuality(parameters),
                    parameters.Scale,
                    parameters.SrcDir.FullName);
            }

            return argument;
        }
        private static string GetTexturePackerArguments_PNG_4444(ConvertionParameters parameters)
        {
            string plistFullPath;
            string argument;

            plistFullPath = parameters.DstDir.FullName;

            if (!plistFullPath.EndsWith("\\"))
            {
                plistFullPath += "\\";
            }

            plistFullPath += parameters.SrcDir.Name;

            if (parameters.NoTrim)
            {
                argument = string.Format(
                    "--format cocos2d --data \"{0}\" --texture-format png --png-opt-level 1 --dpi 72 --opt RGBA4444 --dither-type FloydSteinbergAlpha --max-size 16384 --size-constraints AnySize --force-word-aligned --scale {1} --scale-mode Smooth --algorithm MaxRects --maxrects-heuristics Best --pack-mode Best --border-padding 0 --shape-padding 2 --inner-padding 0 --extrude 0 --disable-rotation --trim-mode None \"{2}\"",
                    plistFullPath,
                    parameters.Scale,
                    parameters.SrcDir.FullName);
            }
            else
            {
                argument = string.Format(
                    "--format cocos2d --data \"{0}\" --texture-format png --png-opt-level 1 --dpi 72 --opt RGBA4444 --dither-type FloydSteinbergAlpha --max-size 16384 --size-constraints AnySize --force-word-aligned --scale {1} --scale-mode Smooth --algorithm MaxRects --maxrects-heuristics Best --pack-mode Best --border-padding 0 --shape-padding 2 --inner-padding 0 --extrude 0 --enable-rotation --trim-mode Trim --trim-threshold 2 \"{2}\"",
                    plistFullPath,
                    parameters.Scale,
                    parameters.SrcDir.FullName);
            }

            return argument;
        }
        private string GetTexturePackerArguments_PVR_TC2_ALPHA(ConvertionParameters parameters)
        {
            string argument;

            if (parameters.NoTrim)
            {
                argument = string.Format(
                    "--format cocos2d-v2 --data \"{0}\" {1}--texture-format pvr3 --pvr-quality {2} --opt PVRTCI_2BPP_RGBA --premultiply-alpha --max-size 4096 --size-constraints POT --force-squared --scale {3} --scale-mode Smooth --algorithm MaxRects --maxrects-heuristics Best --pack-mode Best --border-padding 0 --shape-padding 2 --inner-padding 0 --extrude 0 --disable-rotation --trim-mode None \"{4}\"",
                    getPlistFullPath(parameters),
                    GetTrimSpriteNamesArgument(),
                    GetPvrQuality(parameters),
                    parameters.Scale,
                    parameters.SrcDir.FullName);
            }
            else
            {
                argument = string.Format(
                    "--format cocos2d-v2 --data \"{0}\" {1}--texture-format pvr3 --pvr-quality {2} --opt PVRTCI_2BPP_RGBA --premultiply-alpha --max-size 4096 --size-constraints POT --force-squared --scale {3} --scale-mode Smooth --algorithm MaxRects --maxrects-heuristics Best --pack-mode Best --border-padding 0 --shape-padding 2 --inner-padding 0 --extrude 0 --enable-rotation --trim-mode Trim --trim-threshold 2 \"{4}\"",
                    getPlistFullPath(parameters),
                    GetTrimSpriteNamesArgument(),
                    GetPvrQuality(parameters),
                    parameters.Scale,
                    parameters.SrcDir.FullName);
            }

            return(argument);
        }
        private string GetTexturePackerArguments_PNG_565(ConvertionParameters parameters)
        {
            string argument;

            if (parameters.NoTrim)
            {
                argument = string.Format(
                    "--format cocos2d-v2 --data \"{0}\" {1}--texture-format png --png-opt-level 1 --dpi 72 --opt RGB565 --dither-type FloydSteinberg --max-size 4096 --size-constraints WordAligned --scale {2} --scale-mode Smooth --algorithm MaxRects --maxrects-heuristics Best --pack-mode Best --border-padding 0 --shape-padding 2 --inner-padding 0 --extrude 0 --disable-rotation --trim-mode None \"{3}\"",
                    getPlistFullPath(parameters),
                    GetTrimSpriteNamesArgument(),
                    parameters.Scale,
                    parameters.SrcDir.FullName);
            }
            else
            {
                argument = string.Format(
                    "--format cocos2d-v2 --data \"{0}\" {1}--texture-format png --png-opt-level 1 --dpi 72 --opt RGB565 --dither-type FloydSteinberg --max-size 4096 --size-constraints WordAligned --scale {2} --scale-mode Smooth --algorithm MaxRects --maxrects-heuristics Best --pack-mode Best --border-padding 0 --shape-padding 2 --inner-padding 0 --extrude 0 --enable-rotation --trim-mode Trim --trim-threshold 2 \"{3}\"",
                    getPlistFullPath(parameters),
                    GetTrimSpriteNamesArgument(),
                    parameters.Scale,
                    parameters.SrcDir.FullName);
            }

            return(argument);
        }
Exemplo n.º 5
0
        private string GetTexturePackerArguments_JPG_ULTRA_HIGH(ConvertionParameters parameters)
        {
            string argument;

            if (parameters.NoTrim)
            {
                argument = string.Format(
                    "--format cocos2d-v2 --data \"{0}\" {1}" + "--texture-format jpg --jpg-quality {2}" +
                    " --dpi 72 --opt RGB888 --max-size 4096 --size-constraints WordAligned {3}" + "--scale {4}" +
                    " --scale-mode Smooth --algorithm MaxRects --maxrects-heuristics Best --pack-mode Best --border-padding 0 --shape-padding 1 --inner-padding 0 --extrude 0 --disable-rotation --trim-mode None \"{5}\"",
                    getPlistFullPath(parameters), GetTrimSpriteNamesArgument(), 100,
                    parameters.Forcesquared ? "--force-squared " : "", parameters.Scale, parameters.SrcDir.FullName);
            }
            else
            {
                argument = string.Format(
                    "--format cocos2d-v2 --data \"{0}\" {1}" + "--texture-format jpg --jpg-quality {2}" +
                    " --dpi 72 --opt RGB888 --max-size 4096 --size-constraints WordAligned {3}" + "--scale {4}" +
                    " --scale-mode Smooth --algorithm MaxRects --maxrects-heuristics Best --pack-mode Best --border-padding 0 --shape-padding 1 --inner-padding 0 --extrude 0 --enable-rotation --trim-mode Trim --trim-threshold 2 \"{5}\"",
                    getPlistFullPath(parameters), GetTrimSpriteNamesArgument(), 100,
                    parameters.Forcesquared ? "--force-squared " : "", parameters.Scale, parameters.SrcDir.FullName);
            }

            return(argument);
        }
        private string GetTexturePackerArguments_WEBP_888(ConvertionParameters parameters)
        {
            string argument;

            if (parameters.NoTrim)
            {
                argument = string.Format(
                    "--format cocos2d-v2 --data \"{0}\" {1}--texture-format webp --webp-quality {2} --opt RGB888 --max-size 4096 --size-constraints WordAligned --scale {3} --scale-mode Smooth --algorithm MaxRects --maxrects-heuristics Best --pack-mode Best --border-padding 0 --shape-padding 2 --inner-padding 0 --extrude 0 --disable-rotation --trim-mode None \"{4}\"",
                    getPlistFullPath(parameters),
                    GetTrimSpriteNamesArgument(),
                    GetWebpQuality(parameters),
                    parameters.Scale,
                    parameters.SrcDir.FullName);
            }
            else
            {
                argument = string.Format(
                    "--format cocos2d-v2 --data \"{0}\" {1}--texture-format webp --webp-quality {2} --opt RGB888 --max-size 4096 --size-constraints WordAligned --scale {3} --scale-mode Smooth --algorithm MaxRects --maxrects-heuristics Best --pack-mode Best --border-padding 0 --shape-padding 2 --inner-padding 0 --extrude 0 --enable-rotation --trim-mode Trim --trim-threshold 2 \"{4}\"",
                    getPlistFullPath(parameters),
                    GetTrimSpriteNamesArgument(),
                    GetWebpQuality(parameters),
                    parameters.Scale,
                    parameters.SrcDir.FullName);
            }

            return argument;
        }
        private static string GetTexturePackerArguments_PKM(ConvertionParameters parameters)
        {
            string plistFullPath;
            string argument;

            plistFullPath = parameters.DstDir.FullName;

            if (!plistFullPath.EndsWith("\\"))
            {
                plistFullPath += "\\";
            }

            plistFullPath += parameters.SrcDir.Name;

            if (parameters.NoTrim)
            {
                argument = string.Format(
                    "--format cocos2d --data \"{0}\" --texture-format pkm --etc1-quality {1} --max-size 16384 --size-constraints AnySize --force-word-aligned --scale {2} --scale-mode Smooth --algorithm MaxRects --maxrects-heuristics Best --pack-mode Best --border-padding 0 --shape-padding 2 --inner-padding 0 --extrude 0 --disable-rotation --trim-mode None \"{3}\"",
                    plistFullPath,
                    GetPkmQuality(parameters),
                    parameters.Scale,
                    parameters.SrcDir.FullName);
            }
            else
            {
                argument = string.Format(
                    "--format cocos2d --data \"{0}\" --texture-format pkm --etc1-quality {1} --max-size 16384 --size-constraints AnySize --force-word-aligned --scale {2} --scale-mode Smooth --algorithm MaxRects --maxrects-heuristics Best --pack-mode Best --border-padding 0 --shape-padding 2 --inner-padding 0 --extrude 0 --enable-rotation --trim-mode Trim --trim-threshold 2 \"{3}\"",
                    plistFullPath,
                    GetPkmQuality(parameters),
                    parameters.Scale,
                    parameters.SrcDir.FullName);
            }

            return argument;
        }
        private string GetTexturePackerArguments_PNG_565(ConvertionParameters parameters)
        {
            string argument;

            if (parameters.NoTrim)
            {
                argument = string.Format(
                    "--format cocos2d-v2 --data \"{0}\" {1}--texture-format png --png-opt-level 1 --dpi 72 --opt RGB565 --dither-type FloydSteinberg --max-size 4096 --size-constraints WordAligned --scale {2} --scale-mode Smooth --algorithm MaxRects --maxrects-heuristics Best --pack-mode Best --border-padding 0 --shape-padding 2 --inner-padding 0 --extrude 0 --disable-rotation --trim-mode None \"{3}\"",
                    getPlistFullPath(parameters),
                    GetTrimSpriteNamesArgument(),
                    parameters.Scale,
                    parameters.SrcDir.FullName);
            }
            else
            {
                argument = string.Format(
                    "--format cocos2d-v2 --data \"{0}\" {1}--texture-format png --png-opt-level 1 --dpi 72 --opt RGB565 --dither-type FloydSteinberg --max-size 4096 --size-constraints WordAligned --scale {2} --scale-mode Smooth --algorithm MaxRects --maxrects-heuristics Best --pack-mode Best --border-padding 0 --shape-padding 2 --inner-padding 0 --extrude 0 --enable-rotation --trim-mode Trim --trim-threshold 2 \"{3}\"",
                    getPlistFullPath(parameters),
                    GetTrimSpriteNamesArgument(),
                    parameters.Scale,
                    parameters.SrcDir.FullName);
            }

            return argument;
        }
Exemplo n.º 9
0
        private string GetTexturePackerArguments_WEBP_4444(ConvertionParameters parameters)
        {
            string argument;

            if (parameters.NoTrim)
            {
                argument = string.Format(
                    "--format cocos2d-v2 --data \"{0}\" {1}--texture-format webp --webp-quality {2} --opt RGBA4444 --premultiply-alpha --dither-type FloydSteinbergAlpha --max-size 4096 --size-constraints WordAligned --scale {3} --scale-mode Smooth --algorithm MaxRects --maxrects-heuristics Best --pack-mode Best --border-padding 0 --shape-padding 2 --inner-padding 0 --extrude 0 --disable-rotation --trim-mode None \"{4}\"",
                    getPlistFullPath(parameters),
                    GetTrimSpriteNamesArgument(),
                    GetWebpQuality(parameters),
                    parameters.Scale,
                    parameters.SrcDir.FullName);
            }
            else
            {
                argument = string.Format(
                    "--format cocos2d-v2 --data \"{0}\" {1}--texture-format webp --webp-quality {2} --opt RGBA4444 --premultiply-alpha --dither-type FloydSteinbergAlpha --max-size 4096 --size-constraints WordAligned --scale {3} --scale-mode Smooth --algorithm MaxRects --maxrects-heuristics Best --pack-mode Best --border-padding 0 --shape-padding 2 --inner-padding 0 --extrude 0 --enable-rotation --trim-mode Trim --trim-threshold 2 \"{4}\"",
                    getPlistFullPath(parameters),
                    GetTrimSpriteNamesArgument(),
                    GetWebpQuality(parameters),
                    parameters.Scale,
                    parameters.SrcDir.FullName);
            }

            return(argument);
        }
 private static string GetPkmQuality(ConvertionParameters parameters)
 {
     switch (parameters.TextureQuality)
     {
         case TEXTURE_QUALITY.HIGH:
             return "high-perceptual";
         case TEXTURE_QUALITY.LOW:
             return "low-perceptual";
         default:
             return "low-perceptual";
     }
 }
 private static int GetJpgQuality(ConvertionParameters parameters)
 {
     switch (parameters.TextureQuality)
     {
         case TEXTURE_QUALITY.HIGH:
             return 85;
         case TEXTURE_QUALITY.LOW:
             return 65;
         default:
             return 75;
     }
 }
 private static string GetPvrCczQuality(ConvertionParameters parameters)
 {
     switch (parameters.TextureQuality)
     {
         case TEXTURE_QUALITY.HIGH:
             return "best";
         case TEXTURE_QUALITY.LOW:
             return "normal";
         default:
             return "high";
     }
 }
 private static int GetWebpQuality(ConvertionParameters parameters)
 {
     switch (parameters.TextureQuality)
     {
         case TEXTURE_QUALITY.HIGH:
             return 86;	// 高质量定义为无损
         case TEXTURE_QUALITY.LOW:
             return 60;
         default:
             return 72;
     }
 }
        private static string GetPkmQuality(ConvertionParameters parameters)
        {
            switch (parameters.TextureQuality)
            {
            case TEXTURE_QUALITY.HIGH:
                return("high-perceptual");

            case TEXTURE_QUALITY.LOW:
                return("low-perceptual");

            default:
                return("low-perceptual");
            }
        }
        private static int GetWebpQuality(ConvertionParameters parameters)
        {
            switch (parameters.TextureQuality)
            {
            case TEXTURE_QUALITY.HIGH:
                return(86);                             // 高质量定义为无损

            case TEXTURE_QUALITY.LOW:
                return(60);

            default:
                return(72);
            }
        }
        private static string GetPvrQuality(ConvertionParameters parameters)
        {
            switch (parameters.TextureQuality)
            {
            case TEXTURE_QUALITY.HIGH:
                return("best");

            case TEXTURE_QUALITY.LOW:
                return("normal");

            default:
                return("high");
            }
        }
        private static int GetJpgQuality(ConvertionParameters parameters)
        {
            switch (parameters.TextureQuality)
            {
            case TEXTURE_QUALITY.HIGH:
                return(85);

            case TEXTURE_QUALITY.LOW:
                return(65);

            default:
                return(75);
            }
        }
        private static string getPlistFullPath(ConvertionParameters parameters)
        {
            string plistFullPath = parameters.DstDir.FullName;

            if (!plistFullPath.EndsWith("\\"))
            {
                plistFullPath += "\\";
            }

            if (null == parameters.PlistFileName)
            {
                plistFullPath += parameters.SrcDir.Name;
            }
            else
            {
                plistFullPath += parameters.PlistFileName;
            }

            return plistFullPath;
        }
Exemplo n.º 19
0
        private static string getPlistFullPath(ConvertionParameters parameters)
        {
            string plistFullPath = parameters.DstDir.FullName;

            if (!plistFullPath.EndsWith("\\"))
            {
                plistFullPath += "\\";
            }

            if (null == parameters.PlistFileName)
            {
                plistFullPath += parameters.SrcDir.Name;
            }
            else
            {
                plistFullPath += parameters.PlistFileName;
            }

            return(plistFullPath);
        }
 private static string GetTexturePackerArguments(ConvertionParameters parameters)
 {
     switch (parameters.TextureFormat)
     {
         case TEXTURE_FORMAT.PNG_8888:
             return GetTexturePackerArguments_PNG_8888(parameters);
         case TEXTURE_FORMAT.PNG_4444:
             return GetTexturePackerArguments_PNG_4444(parameters);
         case TEXTURE_FORMAT.PNG_888:
             return GetTexturePackerArguments_PNG_888(parameters);
         case TEXTURE_FORMAT.PNG_565:
             return GetTexturePackerArguments_PNG_565(parameters);
         case TEXTURE_FORMAT.PNG_INDEXED:
             return GetTexturePackerArguments_PNG_INDEXED(parameters);
         case TEXTURE_FORMAT.JPG_888:
             return GetTexturePackerArguments_JPG_888(parameters);
         case TEXTURE_FORMAT.JPG_565:
             return GetTexturePackerArguments_JPG_565(parameters);
         case TEXTURE_FORMAT.PKM:
             return GetTexturePackerArguments_PKM(parameters);
         default:
             return GetTexturePackerArguments_PNG_INDEXED(parameters);
     }
 }
        public void ScanDir(DirectoryInfo srcDir, DirectoryInfo dstDir)
        {
            if (SingleLevelOutput)
            {
                ScanDirSingleLevelOutput(srcDir, dstDir);
                return;
            }

            string srcDirFullPath = srcDir.FullName;

            if (!srcDirFullPath.EndsWith("\\"))
            {
                srcDirFullPath += "\\";
            }

            string dstDirFullPath = dstDir.FullName;

            if (!dstDirFullPath.EndsWith("\\"))
            {
                dstDirFullPath += "\\";
            }

            if (srcDir.Name.StartsWith("."))
            {
                return;
            }
            else if (srcDir.Name.EndsWith(".plist"))
            {
                if (dstDir.Name.EndsWith(".plist"))
                {
                    dstDir = dstDir.Parent;
                }

                ConvertionParameters parameters = new ConvertionParameters(
                    srcDir,
                    dstDir,
                    TextureFormat_Alpha_SQ,
                    Scale);

                bool noAlpha = false;

                foreach (FileInfo subFile in srcDir.GetFiles())
                {
                    if ("noalpha.txt" == subFile.Name)
                    {
                        noAlpha = true;
                    }
                    else if ("lq.txt" == subFile.Name)
                    {
                        parameters.TextureQuality = TEXTURE_QUALITY.LOW;
                    }
                    else if ("hq.txt" == subFile.Name)
                    {
                        parameters.TextureQuality = TEXTURE_QUALITY.HIGH;
                    }
                    else if ("notrim.txt" == subFile.Name)
                    {
                        parameters.NoTrim = true;
                    }
                }

                if (noAlpha)
                {
                    switch (parameters.TextureQuality)
                    {
                    case TEXTURE_QUALITY.HIGH:
                        parameters.TextureFormat = TextureFormat_NoAlpha_HQ;
                        break;

                    case TEXTURE_QUALITY.LOW:
                        parameters.TextureFormat = TextureFormat_NoAlpha_LQ;
                        break;

                    default:
                        parameters.TextureFormat = TextureFormat_NoAlpha_SQ;
                        break;
                    }
                }
                else
                {
                    switch (parameters.TextureQuality)
                    {
                    case TEXTURE_QUALITY.HIGH:
                        parameters.TextureFormat = TextureFormat_Alpha_HQ;
                        break;

                    case TEXTURE_QUALITY.LOW:
                        parameters.TextureFormat = TextureFormat_Alpha_LQ;
                        break;

                    default:
                        parameters.TextureFormat = TextureFormat_Alpha_SQ;
                        break;
                    }
                }

                TODOs.Add(parameters);
            }
            else
            {
                DirectoryInfo[] subDirs = srcDir.GetDirectories();

                if (subDirs.Length > 0)
                {
                    if (!dstDir.Exists)
                    {
                        dstDir.Create();
                    }

                    foreach (DirectoryInfo subDir in srcDir.GetDirectories())
                    {
                        string        dstSubDirFullPath = dstDirFullPath + subDir.Name;
                        DirectoryInfo dstSubDir         = new DirectoryInfo(dstSubDirFullPath);

                        ScanDir(subDir, dstSubDir);
                    }
                }
            }
        }
        public void ScanDirSingleLevelOutput(DirectoryInfo srcDir, DirectoryInfo dstDir, string relativePath = "")
        {
            string srcDirFullPath = srcDir.FullName;

            if (!srcDirFullPath.EndsWith("\\"))
            {
                srcDirFullPath += "\\";
            }

            if (!dstDir.Exists)
            {
                dstDir.Create();
            }

            if (srcDir.Name.StartsWith("."))
            {
                return;
            }
            else if (srcDir.Name.EndsWith(".plist"))
            {
                ConvertionParameters parameters = new ConvertionParameters(
                    srcDir,
                    dstDir,
                    TextureFormat_Alpha_SQ,
                    Scale);

                parameters.PlistFileName = (0 == relativePath.Length) ? srcDir.Name : relativePath;

                bool noAlpha = false;

                foreach (FileInfo subFile in srcDir.GetFiles())
                {
                    if ("noalpha.txt" == subFile.Name)
                    {
                        noAlpha = true;
                    }
                    else if ("lq.txt" == subFile.Name)
                    {
                        parameters.TextureQuality = TEXTURE_QUALITY.LOW;
                    }
                    else if ("hq.txt" == subFile.Name)
                    {
                        parameters.TextureQuality = TEXTURE_QUALITY.HIGH;
                    }
                    else if ("notrim.txt" == subFile.Name)
                    {
                        parameters.NoTrim = true;
                    }
                }

                if (noAlpha)
                {
                    switch (parameters.TextureQuality)
                    {
                        case TEXTURE_QUALITY.HIGH:
                            parameters.TextureFormat = TextureFormat_NoAlpha_HQ;
                            break;
                        case TEXTURE_QUALITY.LOW:
                            parameters.TextureFormat = TextureFormat_NoAlpha_LQ;
                            break;
                        default:
                            parameters.TextureFormat = TextureFormat_NoAlpha_SQ;
                            break;
                    }
                }
                else
                {
                    switch (parameters.TextureQuality)
                    {
                        case TEXTURE_QUALITY.HIGH:
                            parameters.TextureFormat = TextureFormat_Alpha_HQ;
                            break;
                        case TEXTURE_QUALITY.LOW:
                            parameters.TextureFormat = TextureFormat_Alpha_LQ;
                            break;
                        default:
                            parameters.TextureFormat = TextureFormat_Alpha_SQ;
                            break;
                    }
                }

                TODOs.Add(parameters);
            }
            else
            {
                DirectoryInfo[] subDirs = srcDir.GetDirectories();

                foreach (DirectoryInfo subDir in srcDir.GetDirectories())
                {
                    ScanDirSingleLevelOutput(subDir, dstDir, (0 == relativePath.Length) ? subDir.Name : (relativePath + "__" + subDir.Name));
                }
            }
        }
        private string GetTexturePackerArguments(ConvertionParameters parameters)
        {
            switch (parameters.TextureFormat)
            {
                case TEXTURE_FORMAT.PNG_8888:
                    return GetTexturePackerArguments_PNG_8888(parameters);
                case TEXTURE_FORMAT.PNG_4444:
                    return GetTexturePackerArguments_PNG_4444(parameters);
                case TEXTURE_FORMAT.PNG_888:
                    return GetTexturePackerArguments_PNG_888(parameters);
                case TEXTURE_FORMAT.PNG_565:
                    return GetTexturePackerArguments_PNG_565(parameters);
                case TEXTURE_FORMAT.PNG_INDEXED:
                    return GetTexturePackerArguments_PNG_INDEXED(parameters);

                case TEXTURE_FORMAT.PVR_CCZ_TC4_ALPHA:
                    return GetTexturePackerArguments_PVR_CCZ_TC4_ALPHA(parameters);
                case TEXTURE_FORMAT.PVR_CCZ_TC4_NOALPHA:
                    return GetTexturePackerArguments_PVR_CCZ_TC4_NOALPHA(parameters);
                case TEXTURE_FORMAT.PVR_CCZ_TC2_ALPHA:
                    return GetTexturePackerArguments_PVR_CCZ_TC2_ALPHA(parameters);
                case TEXTURE_FORMAT.PVR_CCZ_TC2_NOALPHA:
                    return GetTexturePackerArguments_PVR_CCZ_TC2_NOALPHA(parameters);
                case TEXTURE_FORMAT.PVR_CCZ_4444:
                    return GetTexturePackerArguments_PVR_CCZ_4444(parameters);
                case TEXTURE_FORMAT.PVR_CCZ_565:
                    return GetTexturePackerArguments_PVR_CCZ_565(parameters);

                case TEXTURE_FORMAT.PVR_TC4_ALPHA:
                    return GetTexturePackerArguments_PVR_TC4_ALPHA(parameters);
                case TEXTURE_FORMAT.PVR_TC4_NOALPHA:
                    return GetTexturePackerArguments_PVR_TC4_NOALPHA(parameters);
                case TEXTURE_FORMAT.PVR_TC2_ALPHA:
                    return GetTexturePackerArguments_PVR_TC2_ALPHA(parameters);
                case TEXTURE_FORMAT.PVR_TC2_NOALPHA:
                    return GetTexturePackerArguments_PVR_TC2_NOALPHA(parameters);
                case TEXTURE_FORMAT.PVR_4444:
                    return GetTexturePackerArguments_PVR_4444(parameters);
                case TEXTURE_FORMAT.PVR_565:
                    return GetTexturePackerArguments_PVR_565(parameters);

                case TEXTURE_FORMAT.JPG_888:
                    return GetTexturePackerArguments_JPG_888(parameters);
                case TEXTURE_FORMAT.JPG_565:
                    return GetTexturePackerArguments_JPG_565(parameters);

                case TEXTURE_FORMAT.WEBP_8888:
                    return GetTexturePackerArguments_WEBP_8888(parameters);
                case TEXTURE_FORMAT.WEBP_888:
                    return GetTexturePackerArguments_WEBP_888(parameters);
                case TEXTURE_FORMAT.WEBP_4444:
                    return GetTexturePackerArguments_WEBP_4444(parameters);
                case TEXTURE_FORMAT.WEBP_565:
                    return GetTexturePackerArguments_WEBP_565(parameters);

                case TEXTURE_FORMAT.PKM:
                    return GetTexturePackerArguments_PKM(parameters);
                default:
                    return GetTexturePackerArguments_PNG_INDEXED(parameters);
            }
        }
Exemplo n.º 24
0
        public void ScanDirSingleLevelOutput(DirectoryInfo srcDir, DirectoryInfo dstDir, string relativePath = "")
        {
            string srcDirFullPath = srcDir.FullName;

            if (!srcDirFullPath.EndsWith("\\"))
            {
                srcDirFullPath += "\\";
            }

            if (!dstDir.Exists)
            {
                dstDir.Create();
            }

            if (srcDir.Name.StartsWith("."))
            {
                return;
            }
            else if (srcDir.Name.EndsWith(".plist"))
            {
                ConvertionParameters parameters = new ConvertionParameters(
                    srcDir,
                    dstDir,
                    TextureFormat_Alpha_SQ,
                    Scale);

                parameters.PlistFileName = (0 == relativePath.Length) ? srcDir.Name : relativePath;

                bool noAlpha = false;

                foreach (FileInfo subFile in srcDir.GetFiles())
                {
                    if ("noalpha.txt" == subFile.Name)
                    {
                        noAlpha = true;
                    }
                    else if ("lq.txt" == subFile.Name)
                    {
                        parameters.TextureQuality = TEXTURE_QUALITY.LOW;
                    }
                    else if ("hq.txt" == subFile.Name)
                    {
                        parameters.TextureQuality = TEXTURE_QUALITY.HIGH;
                    }
                    else if ("sfx.txt" == subFile.Name)
                    {
                        parameters.TextureQuality = TEXTURE_QUALITY.SFX;
                    }
                    else if ("notrim.txt" == subFile.Name)
                    {
                        parameters.NoTrim = true;
                    }
                }

                if (noAlpha)
                {
                    switch (parameters.TextureQuality)
                    {
                    case TEXTURE_QUALITY.SFX:
                        parameters.TextureFormat = TextureFormat_NoAlpha_SFX;
                        break;

                    case TEXTURE_QUALITY.HIGH:
                        parameters.TextureFormat = TextureFormat_NoAlpha_HQ;
                        break;

                    case TEXTURE_QUALITY.LOW:
                        parameters.TextureFormat = TextureFormat_NoAlpha_LQ;
                        break;

                    default:
                        parameters.TextureFormat = TextureFormat_NoAlpha_SQ;
                        break;
                    }
                }
                else
                {
                    switch (parameters.TextureQuality)
                    {
                    case TEXTURE_QUALITY.SFX:
                        parameters.TextureFormat = TextureFormat_Alpha_SFX;
                        break;

                    case TEXTURE_QUALITY.HIGH:
                        parameters.TextureFormat = TextureFormat_Alpha_HQ;
                        break;

                    case TEXTURE_QUALITY.LOW:
                        parameters.TextureFormat = TextureFormat_Alpha_LQ;
                        break;

                    default:
                        parameters.TextureFormat = TextureFormat_Alpha_SQ;
                        break;
                    }
                }

                TODOs.Add(parameters);
            }
            else
            {
                DirectoryInfo[] subDirs = srcDir.GetDirectories();

                foreach (DirectoryInfo subDir in srcDir.GetDirectories())
                {
                    ScanDirSingleLevelOutput(subDir, dstDir, (0 == relativePath.Length) ? subDir.Name : (relativePath + "__" + subDir.Name));
                }
            }
        }
Exemplo n.º 25
0
        private void Pack(object convertionParameters)
        {
            ConvertionParameters parameters = (ConvertionParameters)convertionParameters;

            Thread.Sleep(20);

            lock (ConverterLocks[parameters.LockNumber])
            {
                Process processTP = new Process();

                processTP.StartInfo.FileName  = "TexturePacker.exe";
                processTP.StartInfo.Arguments = "--quiet " + GetTexturePackerArguments(parameters);

                //将cmd的标准输入和输出全部重定向到.NET的程序里
                processTP.StartInfo.UseShellExecute = false;                 //此处必须为false否则引发异常

                //processTP.StartInfo.RedirectStandardInput = true; //标准输入
                processTP.StartInfo.RedirectStandardOutput = true;                 //标准输出

                //不显示命令行窗口界面
                processTP.StartInfo.CreateNoWindow = true;
                processTP.StartInfo.WindowStyle    = ProcessWindowStyle.Hidden;

                processTP.Start();                 //启动进程
                StringBuilder sb = new StringBuilder();
                sb.AppendLine("------");
                sb.AppendLine(parameters.SrcDir.FullName);
                sb.AppendLine(processTP.StandardOutput.ReadToEnd());

                processTP.WaitForExit();
                processTP.Dispose();

                if (null != parameters.PlistFileName)
                {
                    string PlistFullPath = getPlistFullPath(parameters);
                    string prefix        = parameters.PlistFileName.Substring(0, parameters.PlistFileName.Length - ".plist".Length);

                    try
                    {
                        XmlDocument xmlDoc = new XmlDocument();

                        xmlDoc.Load(PlistFullPath);

                        if (4 >= xmlDoc.ChildNodes[2].ChildNodes[0].ChildNodes.Count)
                        {
                            XmlNode rootDicNode = xmlDoc.ChildNodes[2].ChildNodes[0];

                            for (int i = 0; i < rootDicNode.ChildNodes.Count; i++)
                            {
                                if ("key" == rootDicNode.ChildNodes[i].Name && "frames" == rootDicNode.ChildNodes[i].InnerText)
                                {
                                    XmlNode frameDicNode = rootDicNode.ChildNodes[++i];

                                    if (null != frameDicNode)
                                    {
                                        foreach (XmlNode frameSubNode in frameDicNode.ChildNodes)
                                        {
                                            if ("key" == frameSubNode.Name)
                                            {
                                                frameSubNode.InnerText = prefix + "__" + frameSubNode.InnerText;
                                            }
                                        }
                                    }
                                }
                            }

                            XmlElement modifiedNode = xmlDoc.CreateElement("key", xmlDoc.NamespaceURI);
                            modifiedNode.InnerText = "Modified";
                            xmlDoc.ChildNodes[2].ChildNodes[0].AppendChild(modifiedNode);

                            XmlElement trueNode = xmlDoc.CreateElement("true", xmlDoc.NamespaceURI);
                            xmlDoc.ChildNodes[2].ChildNodes[0].AppendChild(trueNode);

                            xmlDoc.Save(PlistFullPath);
                            Thread.Sleep(100);

                            byte[] plistContent       = null;
                            string plistContentString = null;

                            using (FileStream fsPlist = File.OpenRead(PlistFullPath))
                            {
                                FileInfo fiPlist = new FileInfo(PlistFullPath);
                                plistContent = new byte[fiPlist.Length];
                                fsPlist.Read(plistContent, 0, (int)fiPlist.Length);
                            }

                            if (0xEF == plistContent[0] && 0xBB == plistContent[1] && 0xBF == plistContent[2])
                            {
                                plistContentString = Encoding.UTF8.GetString(plistContent, 3, plistContent.Length - 3).Replace("1.0.dtd\"[]>", "1.0.dtd\">");
                            }
                            else
                            {
                                plistContentString = Encoding.UTF8.GetString(plistContent).Replace("1.0.dtd\"[]>", "1.0.dtd\">");
                            }

                            plistContent = Encoding.UTF8.GetBytes(plistContentString);

                            using (FileStream fsPlist = File.Create(PlistFullPath))
                            {
                                fsPlist.Write(plistContent, 0, plistContent.Length);
                                fsPlist.Flush();
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        sb.AppendLine(ex.Message);
                    }
                }

                sb.AppendLine("------");
                Console.WriteLine(sb.ToString());
            }
        }
        public void ScanDir(DirectoryInfo srcDir, DirectoryInfo dstDir)
        {
            string srcDirFullPath = srcDir.FullName;

            if (!srcDirFullPath.EndsWith("\\"))
            {
                srcDirFullPath += "\\";
            }

            string dstDirFullPath = dstDir.FullName;

            if (!dstDirFullPath.EndsWith("\\"))
            {
                dstDirFullPath += "\\";
            }

            if (srcDir.Name.StartsWith("."))
            {
                return;
            }
            else if (srcDir.Name.EndsWith(".plist"))
            {
                if (dstDir.Name.EndsWith(".plist"))
                {
                    dstDir = dstDir.Parent;
                }

                ConvertionParameters parameters = new ConvertionParameters(
                    srcDir,
                    dstDir,
                    TextureFormat_Alpha_SQ,
                    Scale);

                bool noAlpha = false;

                foreach (FileInfo subFile in srcDir.GetFiles())
                {
                    if ("noalpha.txt" == subFile.Name)
                    {
                        noAlpha = true;
                    }
                    else if ("lq.txt" == subFile.Name)
                    {
                        parameters.TextureQuality = TEXTURE_QUALITY.LOW;
                    }
                    else if ("hq.txt" == subFile.Name)
                    {
                        parameters.TextureQuality = TEXTURE_QUALITY.HIGH;
                    }
                    else if ("notrim.txt" == subFile.Name)
                    {
                        parameters.NoTrim = true;
                    }
                }

                if (noAlpha)
                {
                    switch (parameters.TextureQuality)
                    {
                        case TEXTURE_QUALITY.HIGH:
                            parameters.TextureFormat = TextureFormat_NoAlpha_HQ;
                            break;
                        case TEXTURE_QUALITY.LOW:
                            parameters.TextureFormat = TextureFormat_NoAlpha_LQ;
                            break;
                        default:
                            parameters.TextureFormat = TextureFormat_NoAlpha_SQ;
                            break;
                    }
                }
                else
                {
                    switch (parameters.TextureQuality)
                    {
                        case TEXTURE_QUALITY.HIGH:
                            parameters.TextureFormat = TextureFormat_Alpha_HQ;
                            break;
                        case TEXTURE_QUALITY.LOW:
                            parameters.TextureFormat = TextureFormat_Alpha_LQ;
                            break;
                        default:
                            parameters.TextureFormat = TextureFormat_Alpha_SQ;
                            break;
                    }
                }

                TODOs.Add(parameters);
            }
            else
            {
                DirectoryInfo[] subDirs = srcDir.GetDirectories();

                if (subDirs.Length > 0)
                {
                    if (!dstDir.Exists)
                    {
                        dstDir.Create();
                    }

                    foreach (DirectoryInfo subDir in srcDir.GetDirectories())
                    {
                        string dstSubDirFullPath = dstDirFullPath + subDir.Name;
                        DirectoryInfo dstSubDir = new DirectoryInfo(dstSubDirFullPath);

                        ScanDir(subDir, dstSubDir);
                    }
                }
            }
        }
        public void ScanDirSingleLevelOutput(DirectoryInfo srcDir, DirectoryInfo dstDir, string relativePath = "")
        {
            var srcDirFullPath = srcDir.FullName;

            if (!srcDirFullPath.EndsWith("\\"))
            {
                srcDirFullPath += "\\";
            }

            if (!dstDir.Exists)
            {
                dstDir.Create();
            }

            if (srcDir.Name.StartsWith("."))
            {
                return;
            }
            else if (srcDir.Name.EndsWith(".plist"))
            {
                ConvertionParameters parameters = new ConvertionParameters(
                    srcDir, dstDir, TextureFormat_Alpha_SQ, Scale);

                parameters.PlistFileName = (0 == relativePath.Length) ? srcDir.Name : relativePath;

                var noAlpha  = false;
                var images   = 0;
                var jpegOnly = true;

                foreach (FileInfo subFile in srcDir.GetFiles())
                {
                    var lowerCasedName    = subFile.Name.ToLower();
                    var lowerCasedExtName = subFile.Extension.ToLower();

                    if (".bmp" == lowerCasedExtName || ".jpg" == lowerCasedExtName || ".jpeg" == lowerCasedExtName ||
                        ".png" == lowerCasedExtName || ".gif" == lowerCasedExtName || ".webp" == lowerCasedExtName ||
                        ".psd" == lowerCasedExtName)
                    {
                        ++images;

                        if (".jpg" != lowerCasedExtName && ".jpeg" != lowerCasedExtName)
                        {
                            jpegOnly = false;
                        }
                    }
                    else if ("noalpha.txt" == lowerCasedName)
                    {
                        noAlpha = true;
                    }
                    else if ("lq.txt" == lowerCasedName)
                    {
                        parameters.TextureQuality = TEXTURE_QUALITY.LOW;
                    }
                    else if ("hq.txt" == lowerCasedName)
                    {
                        parameters.TextureQuality = TEXTURE_QUALITY.HIGH;
                    }
                    else if ("sfx.txt" == lowerCasedName)
                    {
                        parameters.TextureQuality = TEXTURE_QUALITY.SFX;
                    }
                    else if ("notrim.txt" == lowerCasedName)
                    {
                        parameters.NoTrim = true;
                    }
                }

                if (images <= 0)
                {
                    Console.WriteLine(srcDir.Name + " 下没有任何图片文件。");
                    return;
                }

                parameters.Forcesquared = (1 != images);

                if (jpegOnly)
                {
                    noAlpha = true;
                }

                if (noAlpha)
                {
                    switch (parameters.TextureQuality)
                    {
                    case TEXTURE_QUALITY.SFX:
                        parameters.TextureFormat = TextureFormat_NoAlpha_SFX;
                        break;

                    case TEXTURE_QUALITY.HIGH:
                        parameters.TextureFormat = TextureFormat_NoAlpha_HQ;
                        break;

                    case TEXTURE_QUALITY.LOW:
                        parameters.TextureFormat = TextureFormat_NoAlpha_LQ;
                        break;

                    default:
                        parameters.TextureFormat = TextureFormat_NoAlpha_SQ;
                        break;
                    }
                }
                else
                {
                    switch (parameters.TextureQuality)
                    {
                    case TEXTURE_QUALITY.SFX:
                        parameters.TextureFormat = TextureFormat_Alpha_SFX;
                        break;

                    case TEXTURE_QUALITY.HIGH:
                        parameters.TextureFormat = TextureFormat_Alpha_HQ;
                        break;

                    case TEXTURE_QUALITY.LOW:
                        parameters.TextureFormat = TextureFormat_Alpha_LQ;
                        break;

                    default:
                        parameters.TextureFormat = TextureFormat_Alpha_SQ;
                        break;
                    }
                }

                TODOs.Add(parameters);
            }
            else
            {
                DirectoryInfo[] subDirs = srcDir.GetDirectories();

                foreach (DirectoryInfo subDir in srcDir.GetDirectories())
                {
                    ScanDirSingleLevelOutput(subDir, dstDir,
                                             (0 == relativePath.Length) ? subDir.Name : (relativePath + "__" + subDir.Name));
                }
            }
        }
Exemplo n.º 28
0
        private string GetTexturePackerArguments(ConvertionParameters parameters)
        {
            switch (parameters.TextureFormat)
            {
            case TEXTURE_FORMAT.PNG_8888:
                return(GetTexturePackerArguments_PNG_8888(parameters));

            case TEXTURE_FORMAT.PNG_4444:
                return(GetTexturePackerArguments_PNG_4444(parameters));

            case TEXTURE_FORMAT.PNG_888:
                return(GetTexturePackerArguments_PNG_888(parameters));

            case TEXTURE_FORMAT.PNG_565:
                return(GetTexturePackerArguments_PNG_565(parameters));

            case TEXTURE_FORMAT.PNG_INDEXED:
                return(GetTexturePackerArguments_PNG_INDEXED(parameters));

            case TEXTURE_FORMAT.PVR_CCZ_TC4_ALPHA:
                return(GetTexturePackerArguments_PVR_CCZ_TC4_ALPHA(parameters));

            case TEXTURE_FORMAT.PVR_CCZ_TC4_NOALPHA:
                return(GetTexturePackerArguments_PVR_CCZ_TC4_NOALPHA(parameters));

            case TEXTURE_FORMAT.PVR_CCZ_TC2_ALPHA:
                return(GetTexturePackerArguments_PVR_CCZ_TC2_ALPHA(parameters));

            case TEXTURE_FORMAT.PVR_CCZ_TC2_NOALPHA:
                return(GetTexturePackerArguments_PVR_CCZ_TC2_NOALPHA(parameters));

            case TEXTURE_FORMAT.PVR_CCZ_4444:
                return(GetTexturePackerArguments_PVR_CCZ_4444(parameters));

            case TEXTURE_FORMAT.PVR_CCZ_565:
                return(GetTexturePackerArguments_PVR_CCZ_565(parameters));

            case TEXTURE_FORMAT.PVR_TC4_ALPHA:
                return(GetTexturePackerArguments_PVR_TC4_ALPHA(parameters));

            case TEXTURE_FORMAT.PVR_TC4_NOALPHA:
                return(GetTexturePackerArguments_PVR_TC4_NOALPHA(parameters));

            case TEXTURE_FORMAT.PVR_TC2_ALPHA:
                return(GetTexturePackerArguments_PVR_TC2_ALPHA(parameters));

            case TEXTURE_FORMAT.PVR_TC2_NOALPHA:
                return(GetTexturePackerArguments_PVR_TC2_NOALPHA(parameters));

            case TEXTURE_FORMAT.PVR_4444:
                return(GetTexturePackerArguments_PVR_4444(parameters));

            case TEXTURE_FORMAT.PVR_565:
                return(GetTexturePackerArguments_PVR_565(parameters));

            case TEXTURE_FORMAT.JPG_888:
                return(GetTexturePackerArguments_JPG_888(parameters));

            case TEXTURE_FORMAT.JPG_565:
                return(GetTexturePackerArguments_JPG_565(parameters));

            case TEXTURE_FORMAT.WEBP_8888:
                return(GetTexturePackerArguments_WEBP_8888(parameters));

            case TEXTURE_FORMAT.WEBP_888:
                return(GetTexturePackerArguments_WEBP_888(parameters));

            case TEXTURE_FORMAT.WEBP_4444:
                return(GetTexturePackerArguments_WEBP_4444(parameters));

            case TEXTURE_FORMAT.WEBP_565:
                return(GetTexturePackerArguments_WEBP_565(parameters));

            case TEXTURE_FORMAT.PKM:
                return(GetTexturePackerArguments_PKM(parameters));

            default:
                return(GetTexturePackerArguments_PNG_INDEXED(parameters));
            }
        }