public void DecksEdited_NewDeck() { List <Hearthstone.Deck> decks = null; List <Hearthstone.Deck> added = null; List <Hearthstone.Deck> removed = null; List <Hearthstone.Deck> edited = null; LoadDecks(); Assert.AreEqual(2, _collection.Decks.Count()); _collection.DecksChanged += args => { decks = args.Items.ToList(); added = args.Added.ToList(); removed = args.Removed.ToList(); edited = args.Edited.ToList(); }; var deck = DeckSerializer.Deserialize("AAECAZ8FBvQF2a4CucECg8cCteYCt+cCDKcF9QXZB7EIu68C/68CuMcC2ccC48sC+NIC1uUCieYCAA=="); deck.DeckId = 3; deck.Name = "new deck"; _collection.OnDeckEdited(new DeckEditedEventArgs(deck)); Assert.IsNotNull(decks); Assert.AreEqual(3, decks.Count); Assert.AreEqual(deck.Name, decks.Single(x => x.DeckId == 3).Name); Assert.IsNotNull(added); Assert.AreEqual(1, added.Count); Assert.AreEqual(deck.Name, added.Single().Name); Assert.IsNotNull(removed); Assert.AreEqual(0, removed.Count); Assert.IsNotNull(edited); Assert.AreEqual(0, edited.Count); }
public static void LoadPlayerCreatedDecksFromFile() { string path = Path.Combine(Config.SavedDataFolder(), Config.SavedDecksFile()); List <string> lines = File.ReadAllLines(path).ToList(); List <string> decksToLoad = new List <string>(); string input = ""; for (int i = 0; i < lines.Count; i++) { input = input + lines[i] + "\n"; if (lines.Count == i + 1) { decksToLoad.Add(input); input = ""; } else { if (lines[i + 1].StartsWith("###")) { decksToLoad.Add(input); input = ""; } } } decksToLoad.ForEach(x => CurrentDecks.Add(DeckSerializer.Deserialize(x))); Log.Info("Successfully loaded player created decks from file."); }
public void TestReserialize() { var deck = DeckSerializer.Deserialize(DeckString); var reserialized = DeckSerializer.Serialize(deck, false); Assert.AreEqual(DeckString, reserialized); }
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"); }
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"); }
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"); }
public void BasicMageDeck_ValidShortId() { var hearthDbDeck = DeckSerializer.Deserialize("AAECAf0EAA9NWtgBtAK7AosDqwS0BOAE+wSWBYoH7AeeCZYNAA=="); var deck = HearthDbConverter.FromHearthDbDeck(hearthDbDeck); var shortid = ShortIdHelper.GetShortId(deck); Assert.AreEqual(shortid, "KtYDbAkM8IjSSyLMWQn5zb"); }
public void GetDeckstring() { const string deckstring = "AAEBAYDTAgSyAq8EkbwCnOICDbQB7QKoBdQF3QiStgKBwgLrwgKbywLKywKmzgL70wLb4wIA"; var hdbDeck = DeckSerializer.Deserialize(deckstring); var deck = new Hearthstone.Deck(DeckType.Constructed, hdbDeck); Assert.AreEqual(deckstring, deck.GetDeckstring()); }
public void Parse(Line line) { const string findingGameWithHero = "Finding Game With Hero: "; if (line.Text == "Deck Contents Received:") { _state = State.ReceivingDecks; InvokeFoundDecksAsync(); } else if (line.Text == "Finished Editing Deck:") { UpdateState(State.FinishedEditingDeck); } else if (_findingGame.Contains(line.Text)) { UpdateState(State.FindingGameWithDeck); } else if (line.Text.StartsWith(findingGameWithHero)) { UpdateState(State.FindingGameWithHero); if (int.TryParse(line.Text.Substring(findingGameWithHero.Length), out var dbfId)) { FindingGame?.Invoke(new QueuedForGameEventArgs(dbfId)); } } else { if (_currentDeck.Count > 0 || line.Text.StartsWith("#")) { _currentDeck.Add(line.Text); } if (_currentDeck.Count == 3) { try { var deck = DeckSerializer.Deserialize(string.Join("\n", _currentDeck)); if (_state == State.FindingGameWithDeck) { FindingGame?.Invoke(new QueuedForGameEventArgs(deck)); } else if (_state == State.FinishedEditingDeck) { EditedDeck?.Invoke(new DeckEditedEventArgs(deck)); } else { _current.Add(deck); } } catch (Exception e) { Log.Error(e); } _currentDeck.Clear(); } } }
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); } }
public void DeserializeWithComments() { var deck = DeckSerializer.Deserialize(FullDeckString); Assert.AreEqual("Warrior123", deck.Name); Assert.AreEqual(30, deck.GetCards().Values.Sum()); var serialized = DeckSerializer.Serialize(deck, false); Assert.AreEqual(DeckString, serialized); }
public void TestSerializerCommentsDefaults() { var deck = DeckSerializer.Deserialize(DeckString); var commented = DeckSerializer.Serialize(deck, true); var lines = commented.Split(new[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries); Assert.AreEqual("### Warrior Deck", lines[0]); Assert.AreEqual("# Class: Warrior", lines[1]); Assert.AreEqual("# Format: Standard", lines[2]); }
public void TestDeckStrings() { var deck = DeckSerializer.Deserialize(DeckString); Assert.AreEqual(CardIds.Collectible.Warrior.GarroshHellscreamHeroHeroSkins, deck.GetHero().Id); var cards = deck.GetCards(); Assert.AreEqual(30, cards.Values.Sum()); var heroicStroke = cards.FirstOrDefault(c => c.Key.Id == CardIds.Collectible.Warrior.HeroicStrike); Assert.IsNotNull(heroicStroke); Assert.AreEqual(2, heroicStroke.Value); }
private void LoadDecks() { var deck1 = DeckSerializer.Deserialize("AAECAZ8FBvQFucECg8cC1uUCteYCt+cCDKcF9QXZB7EI2a4Cu68C/68CuMcC2ccC48sC+NICieYCAA=="); deck1.DeckId = 1; var deck2 = DeckSerializer.Deserialize("AAECAf0GBOCsApfTAp3iAtvpAg2KAZME9wS2B+EH3sQC58sC8tAC+NACiNICi+EC/OUC6OcCAA=="); deck2.DeckId = 2; _collection.OnDecksLoaded(new ConstructedDeckFoundEventArgs(new List <Deck> { deck1, deck2 })); }
public void TestDeckStringsClassic() { var deck = DeckSerializer.Deserialize(ClassicDeckstring); Assert.AreEqual(CardIds.Collectible.Druid.MalfurionStormrage_EliseStarseekerHeroHeroSkins, deck.GetHero().Id); var cards = deck.GetCards(); Assert.AreEqual(30, cards.Values.Sum()); var claw = cards.FirstOrDefault(c => c.Key.Id == CardIds.Collectible.Druid.ClawVanilla); Assert.IsNotNull(claw); Assert.AreEqual(1, claw.Value); Assert.AreEqual(FormatType.FT_CLASSIC, deck.Format); }
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); } }
public void TestSerializerComments() { var deck = DeckSerializer.Deserialize(DeckString); deck.Name = "Warrior123"; deck.ZodiacYear = ZodiacYear.MAMMOTH; var commented = DeckSerializer.Serialize(deck, true); var lines = commented.Split(new[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries); Assert.AreEqual("### Warrior123", lines[0]); Assert.AreEqual("# Class: Warrior", lines[1]); Assert.AreEqual("# Format: Standard", lines[2]); Assert.AreEqual("# Year of the Mammoth", lines[3]); }