Esempio n. 1
0
        public static void BuildResources(AtlasProject atlasProj)
        {
            //1. load resouce
            //2. convert buffer to C# code
            List <ConvertedFile> selectedItems = new List <ConvertedFile>();

            foreach (AtlasItemSourceFile f in atlasProj.Items)
            {
                if (f.IsConfig)
                {
                    continue;
                }
                //------
                //load and convert
                ConvertedFile convertedFile = new ConvertedFile();
                convertedFile.Compression    = BinCompression.Deflate;
                convertedFile.itemSourceFile = f;
                convertedFile.Data           = BinToHexUtils.ReadBinaryAndConvertToHexArr(convertedFile, convertedFile.Compression);


                string url2 = f.Link.Replace("\\", "_");
                url2 = url2.Replace("//", "_");
                url2 = url2.Replace(".", "_");
                convertedFile.Name = url2;//field name
                selectedItems.Add(convertedFile);
            }
            BuildCsSource(atlasProj, selectedItems);
        }
Esempio n. 2
0
        static void BuildAtlasInEmbededSourceVersion(AtlasProject atlasProj, string info, string img, Dictionary <string, ushort> imgUrlDic)
        {
            //7. create an atlas file in a source file version, user can embed the source to file
            //easy, just read .info and .png then convert to binary buffer

            //PART1:
            string timestamp = DateTime.Now.ToString("s");
            {
                StringBuilder outputFile = new StringBuilder();
                outputFile.AppendLine("//AUTOGEN, " + timestamp);
                outputFile.AppendLine("//source: " + atlasProj.FullFilename);
                outputFile.AppendLine("//tools: " + System.Windows.Forms.Application.ExecutablePath);

                string onlyFilename = Path.GetFileNameWithoutExtension(atlasProj.Filename);

                //TODO: config this
                outputFile.AppendLine("namespace " + atlasProj.CsSourceNamespace + "{");

                outputFile.AppendLine("public partial class RawAtlasData{");

                outputFile.AppendLine("public static readonly string NAME=\"" + onlyFilename + "\";");

                outputFile.AppendLine("//img_links:");
                foreach (string url in imgUrlDic.Keys)
                {
                    outputFile.AppendLine("// " + url);
                }
                outputFile.AppendLine("");


                outputFile.AppendLine("//items names");
                outputFile.AppendLine("public static class Names{");
                foreach (string url in imgUrlDic.Keys)
                {
                    string url2 = url.Replace("\\", "_");
                    url2 = url2.Replace("//", "_");
                    url2 = url2.Replace(".", "_");

                    outputFile.AppendLine("public const string " + url2 + "=\"" + url + "\";");
                }
                outputFile.AppendLine("}");

                StringBuilder info_sb = BinToHexUtils.ReadBinaryAndConvertToHexArr(info, BinCompression.None);

                StringBuilder img_sb = BinToHexUtils.ReadBinaryAndConvertToHexArr(img, BinCompression.None);

                outputFile.AppendLine("//bitmap_atlas_info");
                outputFile.AppendLine("//" + info);
                outputFile.AppendLine("public static readonly byte[] info=" + info_sb.ToString() + ";");

                outputFile.AppendLine("//bitmap_atlas_total_img");
                outputFile.AppendLine("//" + img);
                outputFile.AppendLine("public static readonly byte[] img=" + img_sb.ToString() + ";");

                outputFile.AppendLine("}");
                outputFile.AppendLine("}");


                string dirname = Path.GetDirectoryName(atlasProj.OutputFilename);

                File.WriteAllText(dirname + Path.DirectorySeparatorChar + "x_" + onlyFilename + "_Atlas_AUTOGEN.cs", outputFile.ToString());
            }
            //----------------------
            //PART2: autogen atlas binder
            {
                StringBuilder outputFile = new StringBuilder();
                outputFile.AppendLine("//AUTOGEN, " + timestamp);
                outputFile.AppendLine("//source: " + atlasProj.FullFilename);
                outputFile.AppendLine("//tools: " + System.Windows.Forms.Application.ExecutablePath);

                string onlyFilename = Path.GetFileNameWithoutExtension(atlasProj.Filename);


                outputFile.AppendLine("using PixelFarm.Drawing;");

                outputFile.AppendLine("namespace " + atlasProj.CsSourceNamespace + "{");

                outputFile.AppendLine("public partial class Binders{");

                foreach (string url in imgUrlDic.Keys)
                {
                    string url2 = url.Replace("\\", "_");
                    url2 = url2.Replace("//", "_");
                    url2 = url2.Replace(".", "_");

                    outputFile.AppendLine("public readonly AtlasImageBinder " + url2 + "=new AtlasImageBinder(RawAtlasData.NAME, \"" + url + "\");");
                }

                outputFile.AppendLine(@"

                    static bool s_registered;
                    public Binders(){
                            if(!s_registered){        
                                    try{
                                         PixelFarm.Platforms.InMemStorage.AddData(RawAtlasData.NAME + "".info"", RawAtlasData.info);
                                         PixelFarm.Platforms.InMemStorage.AddData(RawAtlasData.NAME + "".png"", RawAtlasData.img);
                                    }catch(System.Exception ex){
                                    }
                            s_registered= true;
                            }
                    }
                ");

                outputFile.AppendLine("}"); //class
                outputFile.AppendLine("}"); //namespace

                string dirname = Path.GetDirectoryName(atlasProj.OutputFilename);
                File.WriteAllText(dirname + Path.DirectorySeparatorChar + "x_" + onlyFilename + "_Atlas_AUTOGEN_BINDERS.cs", outputFile.ToString());
            }
        }