示例#1
0
        private static int Launch(Atlas args)
        {
            if (args.AtlasFile.Equals(""))
            {
                return((int)FailCode.FailedParsingArguments);
            }
            else
            {
                // make sure we found some images
                if (args.TextureList.Count == 0)
                {
                    Logging.Manager("No images to pack for " + args.AtlasFile);
                    return((int)FailCode.NoImages);
                }

                // generate our output
                ImagePacker imagePacker = new ImagePacker();

                // Logging.Manager("try to add " + args.TextureList.Count + " images to atlas file " + args.AtlasFile);

                // pack the image, generating a map only if desired
                int result = imagePacker.PackImage(args.TextureList, args.PowOf2, args.Square, args.FastImagePacker, args.AtlasWidth, args.AtlasHeight, args.Padding, args.mapExporter != null, out Bitmap outputImage, out Dictionary <string, Rectangle> outputMap);
                if (result != 0)
                {
                    Logging.Manager("There was an error making the image sheet.");
                    //error result 7 = "failed to pack image" most likely it won't fit
                    return(result);
                }
                else
                {
                    Logging.Manager(string.Format("Packing '{0}' to {1} x {2} pixel", Path.GetFileName(args.AtlasFile), outputImage.Height, outputImage.Width));
                }

                // try to save using our exporters
                try
                {
                    if (File.Exists(args.AtlasFile))
                    {
                        File.Delete(args.AtlasFile);
                    }
                    if (args.imageHandler.Save(args.AtlasFile, outputImage))
                    {
                        Logging.Manager("successfully created Atlas image: " + args.AtlasFile);
                    }
                    Logging.InstallerGroup("created Atlases");                                              // write comment
                    Logging.Installer(Utils.ReplaceDirectorySeparatorChar(args.AtlasFile));                 // write created filename with path
                }
                catch (Exception e)
                {
                    Logging.Manager("Error saving file: " + e.Message);
                    return((int)FailCode.FailedToSaveImage);
                }

                if (args.mapExporter != null)
                {
                    try
                    {
                        if (File.Exists(args.MapFile))
                        {
                            File.Delete(args.MapFile);
                        }
                        args.mapExporter.Save(args.MapFile, outputMap);
                        Logging.Installer(Utils.ReplaceDirectorySeparatorChar(args.MapFile));                 // write created filename with path
                    }
                    catch (Exception e)
                    {
                        Logging.Manager("Error saving file: " + e.Message);
                        return((int)FailCode.FailedToSaveMap);
                    }
                }
            }
            return(0);
        }