Example #1
0
        public void WriteCorrectNumOfLines()
        {
            CardArtDb.Write(_tempXml, CreateSampleDefs());
            var lineCount = File.ReadAllLines(_tempXml).Length;

            Assert.AreEqual(31, lineCount);
        }
Example #2
0
        private void SaveChanges()
        {
            var imgX = Canvas.GetLeft(ImgBase);
            var imgY = Canvas.GetTop(ImgBase);

            var rect = new Rectangle();

            rect.Width  = (int)Math.Round(512 / _imgScale);
            rect.Height = (int)Math.Round(117 / _imgScale);
            rect.X      = (int)Math.Round((imgX * -1) / _imgScale);
            var yFlip = (int)Math.Round((197.5 - imgY) / _imgScale);

            rect.Y = (int)Math.Round(512.0 - rect.Height - yFlip);

            var original = _barContext.GetRectangle();

            if (original != rect)
            {
                // rectangles are different save changes
                _barContext.SetRectangle(rect);
                _barContext.Save();
                StatusWrite($"Changes saved {_barContext.CardId}");
                // write the changes to the mapfile
                CardArtDb.Write(_mapFile, CardArtDb.Defs);
            }
        }
Example #3
0
        private void BtnMapBrowse_Click(object sender, RoutedEventArgs e)
        {
            var filepath = string.Empty;

            VistaOpenFileDialog dialog = new VistaOpenFileDialog();

            dialog.Title = "Select a folder";

            if ((bool)dialog.ShowDialog())
            {
                filepath = dialog.FileName;
            }

            if (!string.IsNullOrEmpty(filepath))
            {
                CardArtDb.Read(filepath);
                _fileList.UpdateBars();
                LoadFile(_fileList.Current);
                LblMapFile.Content = filepath;
                _mapFile           = filepath;
            }
        }
Example #4
0
        public static void Extract(CardArtExtractorOptions opts)
        {
            ValidateDirectories(opts.OutputDir, opts.HearthstoneDir);

            // Init set and type filters
            List <CardSet>  includeSets  = CardEnumConverter.SetIds(opts.Sets);
            List <CardType> includeTypes = CardEnumConverter.TypeIds(opts.Types);

            // Load card data from hearthstonejson
            LoadCardData(GetPatchVersion(opts.HearthstoneDir));

            // If a map file was supplied, use that instead of parsing cards files
            CardArtDefs defs = null;

            if (File.Exists(opts.MapFile))
            {
                Logger.Log(LogLevel.INFO, "using map file: {0}", opts.MapFile);
                CardArtDb.Read(opts.MapFile);
                var loadedPatch  = CardArtDb.GamePatch;
                var currentPatch = GetPatchVersion(opts.HearthstoneDir).ToString();
                if (loadedPatch != currentPatch)
                {
                    Console.WriteLine("Map file patch mismatch, attempting merge: {0} != {1}",
                                      loadedPatch, currentPatch);

                    var current = LoadCardDefs(opts.HearthstoneDir);
                    var loaded  = CardArtDb.Defs;
                    foreach (var item in current.Cards)
                    {
                        // replace any missing coords, from map defs if possible
                        if (!item.HasBarCoords() && CardArtDb.All.ContainsKey(item.Id))
                        {
                            var bar = CardArtDb.All[item.Id].GetMaterial(MaterialType.CardBar);
                            if (bar != null)
                            {
                                item.AddMaterial(
                                    bar.GetTransform(TransformType.Standard),
                                    bar.GetTransform(TransformType.Shader),
                                    MaterialType.CardBar);
                            }
                        }
                    }
                    defs = current;
                }
                else
                {
                    defs = CardArtDb.Defs;
                }
            }
            else
            {
                // map file not found, using default method
                Logger.Log(LogLevel.WARN, "map file not found: {0}", opts.MapFile);
                defs = LoadCardDefs(opts.HearthstoneDir);
            }

            // Create the list of cards we want to output
            List <ArtCard> filteredCards = null;

            if (opts.NoFiltering)
            {
                // don't use default filter, or option filters, just return all
                filteredCards = defs.Cards.Where(x => CardDb.All.ContainsKey(x.Id)).ToList();
            }
            else if (includeSets.Count > 0 || includeTypes.Count > 0)
            {
                // filter db list using options
                var filteredDb = CardDb.FilterBy(includeSets, includeTypes);
                // filter art card defs by only including those in filteredDb
                filteredCards = defs.Cards.Where(x => filteredDb.ContainsKey(x.Id)).ToList();
            }
            else
            {
                // filter art card defs by only including those that are in the default filtered db
                filteredCards = defs.Cards.Where(x => CardDb.Filtered.ContainsKey(x.Id)).ToList();
            }
            Logger.Log("Filtered art cards: " + filteredCards.Count);

            // get all textures (cardtextures<n>.unity3d)
            var textureFiles = new List <string>(Directory.GetFiles(_hsDataPath, "cardtextures?.unity3d"));
            // First pass over texture bundles, collect texture path data
            var textureRefs = LoadTextureInfo(textureFiles);

            // Add shared bundles to texture list (shared<n>.unity3d)
            textureFiles.AddRange(Directory.GetFiles(_hsDataPath, "shared?.unity3d"));
            // Extract all the texture files using the refs and required cards
            var tb        = new TexturesBundle(textureFiles, opts);
            var bundleMap = tb.Extract(textureRefs, filteredCards);

            // Update the cardartdb with found bundle names, and save
            if (opts.SaveMapFile)
            {
                UpdateAndSaveCardArtDefs(bundleMap, defs, opts.OutputDir);
            }
        }
Example #5
0
 public static void ClassInitialize(TestContext testContext)
 {
     CardArtDb.Read(@"Data\cardartdefs.xml");
     _db      = CardArtDb.All;
     _tempXml = @"Data\writetest.xml";
 }