private void ConvertFile()
        {
            TexturesToAtlasConverter texturesToAtlasConverter = new TexturesToAtlasConverter(TexturesFile, ScmlFile);

            atlasFile = texturesToAtlasConverter.GetAtlasFile();
            buildFile = texturesToAtlasConverter.GetBuildFile();
        }
示例#2
0
        public FileIdProvider(Build.File buildFile)
        {
            BuildFile    = buildFile;
            NameToFileId = new Dictionary <string, int>();
            HashSet <string> names = new HashSet <string>();
            int fileId             = 0;

            foreach (Build.Symbol symbol in BuildFile.Build.SymbolsList)
            {
                foreach (Build.Frame frame in symbol.FramesList)
                {
                    string name = BuildFile.HashToName[symbol.Hash] + '_' + frame.SourceFrameNum;
                    if (names.Contains(name))
                    {
                        Console.WriteLine($"Warning: symbol {name} was defined more than once!");
                        continue;
                    }

                    names.Add(name);
                    NameToFileId.Add(name, fileId++);
                }
            }
        }
 public AtlasToTexturesConverter(Atlas.File atlasFile, Build.File buildFile)
 {
     AtlasFile = atlasFile;
     BuildFile = buildFile;
 }
 public KAnimToScmlConverter(Atlas.File atlasFile, Build.File buildFile, Animation.File animationFile)
 {
     AtlasFile     = atlasFile;
     BuildFile     = buildFile;
     AnimationFile = animationFile;
 }
        private XmlElement MakeFileNode(XmlDocument scml, Build.Symbol symbol, Build.Frame frame, Build.File BuildFile, string name, FileIdProvider fileIdProvider)
        {
            int   imageWidth  = AtlasFile.Atlas.Width;
            int   imageHeight = AtlasFile.Atlas.Height;
            float x           = frame.PivotX - frame.PivotWidth / 2f;
            float y           = frame.PivotY - frame.PivotHeight / 2f;
            float pivotX      = 0 - x / frame.PivotWidth;
            float pivotY      = 1 + y / frame.PivotHeight;
            int   width       = (int)((frame.X2 - frame.X1) * imageWidth);
            int   height      = (int)((frame.Y2 - frame.Y1) * imageHeight);

            XmlElement file = scml.CreateElement(string.Empty, "file", string.Empty);

            file.SetAttribute("id", fileIdProvider.NameToFileId[name].ToString());
            file.SetAttribute("name", name);
            file.SetAttribute("width", width.ToString());
            file.SetAttribute("height", height.ToString());
            file.SetAttribute("pivot_x", pivotX.ToString());
            file.SetAttribute("pivot_y", pivotY.ToString());
            return(file);
        }