Пример #1
0
        public void CardIdCollisionDeck_ValidShortId()
        {
            var hearthDbDeck = DeckSerializer.Deserialize("AAEBAf0EHnGeAcABwwG7Au4CqwSWBewF9w2JDroWwxbXtgLrugLYuwLZuwKHvQLBwQKP0wKi0wLu9gKnggP1iQP8owOSpAO+pAO/pAPdqQP0qwMAAA==");
            var deck         = HearthDbConverter.FromHearthDbDeck(hearthDbDeck);
            var shortid      = ShortIdHelper.GetShortId(deck);

            Assert.AreEqual(shortid, "mA9O7wXvzxMsx1KO7EuFve");
        }
Пример #2
0
        public void HighlanderHunter_ValidShortId()
        {
            var hearthDbDeck = DeckSerializer.Deserialize("AAECAR8engGoArUDxwOHBMkErgbFCNsJ7Qn+DJjwAp7wAu/xAqCAA6eCA5uFA/WJA+aWA/mWA76YA7acA56dA/yjA+WkA5+lA6KlA6alA4SnA5+3AwAA");
            var deck         = HearthDbConverter.FromHearthDbDeck(hearthDbDeck);
            var shortid      = ShortIdHelper.GetShortId(deck);

            Assert.AreEqual(shortid, "O2VpFDQokIrwww8iOmE3Lc");
        }
Пример #3
0
        public void ComboPriest_ValidShortId()
        {
            var hearthDbDeck = DeckSerializer.Deserialize("AAECAa0GBqUJ+wzl9wLQ/gKnhwOppQMM+ALlBPYH1QjRCtIK8gz3DK+lA9KlA/2nA4SoAwA=");
            var deck         = HearthDbConverter.FromHearthDbDeck(hearthDbDeck);
            var shortid      = ShortIdHelper.GetShortId(deck);

            Assert.AreEqual(shortid, "0gsPp02q8ajKsGVstRwLpb");
        }
Пример #4
0
        public void BasicMageDeck_ValidShortId()
        {
            var hearthDbDeck = DeckSerializer.Deserialize("AAECAf0EAA9NWtgBtAK7AosDqwS0BOAE+wSWBYoH7AeeCZYNAA==");
            var deck         = HearthDbConverter.FromHearthDbDeck(hearthDbDeck);
            var shortid      = ShortIdHelper.GetShortId(deck);

            Assert.AreEqual(shortid, "KtYDbAkM8IjSSyLMWQn5zb");
        }
Пример #5
0
        public static async Task <Deck> TryFindDeck(string url)
        {
            try
            {
                var doc = await ImportingHelper.GetHtmlDoc(url);

                var deck      = new Deck();
                var metaNodes = doc.DocumentNode.SelectNodes("//meta");
                if (!metaNodes.Any())
                {
                    return(null);
                }
                deck.Name = GetMetaProperty(metaNodes, "x-hearthstone:deck");
                deck.Url  = GetMetaProperty(metaNodes, "x-hearthstone:deck:url") ?? url;

                var deckString = GetMetaProperty(metaNodes, "x-hearthstone:deck:deckstring");
                if (!string.IsNullOrEmpty(deckString))
                {
                    try
                    {
                        var hearthDbDeck   = DeckSerializer.Deserialize(deckString);
                        var fromDeckString = HearthDbConverter.FromHearthDbDeck(hearthDbDeck);
                        fromDeckString.Name = deck.Name;
                        fromDeckString.Url  = deck.Url;
                        return(fromDeckString);
                    }
                    catch (Exception e)
                    {
                        Log.Error(e);
                    }
                }

                var heroId = GetMetaProperty(metaNodes, "x-hearthstone:deck:hero");
                if (!string.IsNullOrEmpty(heroId))
                {
                    deck.Class = Hearthstone.Database.GetCardFromId(heroId).PlayerClass;
                }
                var cardList = GetMetaProperty(metaNodes, "x-hearthstone:deck:cards").Split(',');
                foreach (var idGroup in cardList.GroupBy(x => x))
                {
                    var card = Hearthstone.Database.GetCardFromId(idGroup.Key);
                    card.Count = idGroup.Count();
                    deck.Cards.Add(card);
                    if (deck.Class == null && card.IsClassCard)
                    {
                        deck.Class = card.PlayerClass;
                    }
                }
                return(deck);
            }
            catch (Exception e)
            {
                Log.Error(e);
                return(null);
            }
        }
Пример #6
0
        public static async Task <Deck> Import(bool rethrow = false)
        {
            Exception error = null;

            try
            {
                var clipboard = Clipboard.GetText();
                var validUrl  = Uri.TryCreate(clipboard, UriKind.Absolute, out Uri uriResult) &&
                                (uriResult.Scheme == Uri.UriSchemeHttp || uriResult.Scheme == Uri.UriSchemeHttps);
                if (validUrl)
                {
                    return(await DeckImporter.Import(clipboard));
                }

                try
                {
                    var hearthDbDeck = DeckSerializer.Deserialize(clipboard);
                    var deck         = HearthDbConverter.FromHearthDbDeck(hearthDbDeck);
                    if (deck != null)
                    {
                        return(deck);
                    }
                }
                catch (Exception e)
                {
                    error = e;
                    Log.Error(e);
                    if (rethrow)
                    {
                        throw error;
                    }
                }

                if (StringImporter.IsValidImportString(clipboard))
                {
                    return(StringImporter.Import(clipboard));
                }
                return(JsonDeckImporter.Import(clipboard));
            }
            catch (Exception ex)
            {
                Log.Error(ex);
                if (rethrow)
                {
                    throw error ?? ex;
                }
                return(null);
            }
        }
Пример #7
0
 public Plugin()
 {
     MenuItem.Click += (sender, e) =>
     {
         try
         {
             var hdbDeck    = HearthDb.Deckstrings.DeckSerializer.Deserialize(Clipboard.GetText());
             var deck       = HearthDbConverter.FromHearthDbDeck(hdbDeck);
             var screenshot = DeckScreenshotHelper.Generate(deck, true);
             DeckScreenshotHelper.CopyToClipboard(screenshot);
         }
         catch (Exception exception)
         {
             Hearthstone_Deck_Tracker.Windows.MessageDialogs.ShowMessage(Core.MainWindow,
                                                                         "Could not create screenshot", exception.ToString()).Forget();
             Log.Error(exception);
         }
     };
 }