Esempio n. 1
0
        public static void Save(string filename, Dictionary <string, Rectangle> map, Dictionary <string, List <string> > animations, SpriteAtlasPacker.Config arguments)
        {
            var images = new List <string>(map.Keys);

            using (var writer = new StreamWriter(filename))
            {
                foreach (var image in images)
                {
                    // get the destination rectangle
                    var destination = map[image];

                    // write out the destination rectangle for this bitmap
                    writer.WriteLine("{0}\n\t{1},{2},{3},{4}\n\t{5},{6}",
                                     Path.GetFileNameWithoutExtension(image),
                                     destination.X,
                                     destination.Y,
                                     destination.Width,
                                     destination.Height,
                                     arguments.OriginX, arguments.OriginY);
                }

                if (animations.Count > 0)
                {
                    writer.WriteLine();

                    foreach (var kvPair in animations)
                    {
                        writer.WriteLine("{0}", kvPair.Key);
                        writer.WriteLine("\t{0}", arguments.FrameRate);

                        var indexes = new List <int>();
                        foreach (var image in kvPair.Value)
                        {
                            indexes.Add(images.IndexOf(image));
                        }
                        writer.WriteLine("\t{0}", string.Join(",", indexes));
                    }
                }
            }
        }
Esempio n. 2
0
        public static void Save(string filename, Dictionary <string, Rectangle> map, Dictionary <string, List <string> > animations, SpriteAtlasPacker.Config arguments)
        {
            // copy the files list and sort alphabetically
            var keys = new string[map.Count];

            map.Keys.CopyTo(keys, 0);
            List <string> outputFiles = new List <string>(keys);

            outputFiles.Sort();

            // compute the names of images to write
            IDictionary <string, string> imagesNames;

            if (arguments.WritePaths)
            {
                string commonPath = MiscHelper.GetCommonPath(outputFiles);
                imagesNames = outputFiles.ToDictionary(k => k, v => v.Substring(commonPath.Length));
            }
            else
            {
                imagesNames = outputFiles.ToDictionary(k => k, v => Path.GetFileNameWithoutExtension(v));
            }

            using (StreamWriter writer = new StreamWriter(filename))
            {
                writer.NewLine = arguments.LF ? "\n" : "\r\n";

                foreach (var image in outputFiles)
                {
                    // get the destination rectangle
                    Rectangle destination = map[image];

                    // write out the destination rectangle for this bitmap
                    writer.WriteLine(string.Format(
                                         "{0} = {1} {2} {3} {4}",
                                         imagesNames[image],
                                         destination.X,
                                         destination.Y,
                                         destination.Width,
                                         destination.Height));
                }
            }
        }
Esempio n. 3
0
        public static void Save(string filename, Dictionary <string, Rectangle> map, Dictionary <string, List <string> > animations, SpriteAtlasPacker.Config arguments, string relativeTo)
        {
            var images = new List <string>(map.Keys);

            using (var writer = new StreamWriter(filename))
            {
                foreach (var image in images)
                {
                    // get the destination rectangle
                    var destination = map[image];

                    // write out the destination rectangle for this bitmap
                    writer.WriteLine("{0}\n\t{1},{2},{3},{4}\n\t{5},{6}",
                                     MakeSpriteName(image, relativeTo),
                                     destination.X,
                                     destination.Y,
                                     destination.Width,
                                     destination.Height,
                                     arguments.OriginX.ToString(System.Globalization.CultureInfo.InvariantCulture), arguments.OriginY.ToString(System.Globalization.CultureInfo.InvariantCulture));
                }

                if (animations.Count > 0)
                {
                    writer.WriteLine();

                    foreach (var kvPair in animations)
                    {
                        writer.WriteLine("{0}", kvPair.Key);
                        writer.WriteLine("\t{0}", arguments.FrameRate);

                        var indexes = new List <int>();
                        foreach (var image in kvPair.Value)
                        {
                            indexes.Add(images.IndexOf(image));
                        }
                        writer.WriteLine("\t{0}", string.Join(",", indexes));
                    }
                }
            }
        }
Esempio n. 4
0
        public static void Save(string filename, Dictionary <string, Rectangle> map, Dictionary <string, List <string> > animations, Dictionary <string, Vector2> origins, SpriteAtlasPacker.Config arguments)
        {
            var images = new List <string>(map.Keys);

            IDictionary <string, string> imagesNames;

            if (arguments.WritePaths)
            {
                string commonPath = MiscHelper.GetCommonPath(images);
                imagesNames = images.ToDictionary(k => k, v => v.Substring(commonPath.Length));
            }
            else
            {
                imagesNames = images.ToDictionary(k => k, v => Path.GetFileNameWithoutExtension(v));
            }

            using (var writer = new StreamWriter(filename))
            {
                writer.NewLine = arguments.LF ? "\n" : "\r\n";

                foreach (var image in images)
                {
                    writer.WriteLine(imagesNames[image]);

                    // write out the destination rectangle for this bitmap
                    var destination = map[image];
                    writer.WriteLine("\t{0},{1},{2},{3}",
                                     destination.X,
                                     destination.Y,
                                     destination.Width,
                                     destination.Height);

                    // write images origins
                    if (!arguments.NoOrigins)
                    {
                        Vector2 origin = new Vector2(arguments.OriginX, arguments.OriginY);
                        if (origins != null)
                        {
                            var name = imagesNames[image];
                            if (origins.ContainsKey(name))
                            {
                                origin = origins[name];
                            }
                        }
                        writer.WriteLine("\t{0},{1}",
                                         origin.X.ToString(System.Globalization.CultureInfo.InvariantCulture),
                                         origin.Y.ToString(System.Globalization.CultureInfo.InvariantCulture));
                    }
                }

                if (animations.Count > 0)
                {
                    writer.WriteLine();

                    foreach (var kvPair in animations)
                    {
                        writer.WriteLine("{0}", kvPair.Key);
                        writer.WriteLine("\t{0}", arguments.FrameRate);

                        var indexes = new List <int>();
                        foreach (var image in kvPair.Value)
                        {
                            indexes.Add(images.IndexOf(image));
                        }
                        writer.WriteLine("\t{0}", string.Join(",", indexes));
                    }
                }
            }
        }
Esempio n. 5
0
        public static void Save(string filename, Dictionary <string, Rectangle> map, Dictionary <string, List <string> > animations, SpriteAtlasPacker.Config arguments)
        {
            // copy the files list and sort alphabetically
            var keys = new string[map.Count];

            map.Keys.CopyTo(keys, 0);
            List <string> outputFiles = new List <string>(keys);

            outputFiles.Sort();

            using (StreamWriter writer = new StreamWriter(filename))
            {
                foreach (var image in outputFiles)
                {
                    // get the destination rectangle
                    Rectangle destination = map[image];

                    // write out the destination rectangle for this bitmap
                    writer.WriteLine(string.Format(
                                         "{0} = {1} {2} {3} {4}",
                                         Path.GetFileNameWithoutExtension(image),
                                         destination.X,
                                         destination.Y,
                                         destination.Width,
                                         destination.Height));
                }
            }
        }
Esempio n. 6
0
        public static void Save(string filename, Dictionary <string, Rectangle> map, Dictionary <string, List <string> > animations, int atlasWidth, int atlasHeight, SpriteAtlasPacker.Config arguments)
        {
            var images = ImagesNotInAnimations(map.Keys.ToArray(), animations);

            using (var writer = new StreamWriter(filename))
            {
                writer.NewLine = arguments.LF ? "\n" : "\r\n";

                writer.WriteLine("return {");

                writer.WriteLine($"\ttexture = love.graphics.newImage('{arguments.AtlasOutputFile}'),");

                if (images.Length > 0)
                {
                    writer.WriteLine("\timages = {");
                    foreach (var image in images)
                    {
                        // get the destination rectangle
                        var rect = map[image];
                        writer.WriteLine($"\t\t['{Path.GetFileNameWithoutExtension(image)}'] = love.graphics.newQuad({rect.X}, {rect.Y}, {rect.Width}, {rect.Height}, {atlasWidth}, {atlasHeight}),");
                    }
                    writer.WriteLine("\t},");
                }

                if (animations.Count > 0)
                {
                    writer.WriteLine("\tanimations = {");

                    foreach (var kvPair in animations)
                    {
                        writer.WriteLine($"\t\t['{kvPair.Key}'] = {{");
                        foreach (var image in kvPair.Value)
                        {
                            var rect = map[image];
                            writer.WriteLine($"\t\t\tlove.graphics.newQuad({rect.X}, {rect.Y}, {rect.Width}, {rect.Height}, {atlasWidth}, {atlasHeight}),");
                        }
                        writer.WriteLine("\t\t},");
                    }

                    writer.WriteLine("\t}");
                }
                writer.WriteLine("}");
            }
        }