Skip to content

Commit

Permalink
fixes recording stats for selected version, retroactively moves match…
Browse files Browse the repository at this point in the history
…es to correct deck / default stats if not possible (HearthSim#722)
  • Loading branch information
epix37 committed Mar 6, 2015
1 parent 722de63 commit 25104b8
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 1 deletion.
3 changes: 3 additions & 0 deletions Hearthstone Deck Tracker/Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,9 @@ public class Config
[DefaultValue(false)]
public bool ResolvedDeckStatsIds = false;

[DefaultValue(false)]
public bool ResolvedDeckStatsIssue = false;

//updating from <= 0.5.1:
//SaveConfigInAppData and SaveDataInAppData are set to SaveInAppData AFTER the config isloaded
//=> Need to be null to avoid creating new config in appdata if config is stored locally.
Expand Down
2 changes: 1 addition & 1 deletion Hearthstone Deck Tracker/GameEventHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ public static async void HandleGameEnd()
return;
}
Game.CurrentGameStats.GameEnd();
var selectedDeck = DeckList.Instance.ActiveDeckVersion;
var selectedDeck = DeckList.Instance.ActiveDeck;
if(selectedDeck != null)
{
if(Config.Instance.DiscardGameIfIncorrectDeck
Expand Down
42 changes: 42 additions & 0 deletions Hearthstone Deck Tracker/MainWindow/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,8 @@ public MainWindow()

if(!Config.Instance.RemovedNoteUrls)
RemoveNoteUrls();
if(!Config.Instance.ResolvedDeckStatsIssue)
ResolveDeckStatsIssue();

//this has to happen before reader starts
//var lastDeck = DeckList.Instance.Decks.FirstOrDefault(d => d.DeckId == Config.Instance.LastDeckId);
Expand Down Expand Up @@ -334,11 +336,51 @@ public MainWindow()
_initialized = true;
}


public Thickness TitleBarMargin
{
get { return new Thickness(0, TitlebarHeight, 0, 0); }
}

private void ResolveDeckStatsIssue()
{
foreach(var deck in DeckList.Instance.Decks)
{
foreach(var deckVersion in deck.Versions)
{
if(deckVersion.DeckStats.Games.Any())
{
var games = deckVersion.DeckStats.Games.ToList();
foreach(var game in games)
{
deck.DeckStats.AddGameResult(game);
deckVersion.DeckStats.Games.Remove(game);
}
}
}
}
foreach(var deckStats in DeckStatsList.Instance.DeckStats)
{
if(deckStats.Games.Any() && !DeckList.Instance.Decks.Any(d => deckStats.BelongsToDeck(d)))
{
var games = deckStats.Games.ToList();
foreach(var game in games)
{
var defaultStats = DefaultDeckStats.Instance.GetDeckStats(game.PlayerHero);
if(defaultStats != null)
{
defaultStats.AddGameResult(game);
deckStats.Games.Remove(game);
}
}
}
}

DeckStatsList.Save();
Config.Instance.ResolvedDeckStatsIssue = true;
Config.Save();
}

private async void UpdateAsync()
{
const string url = "https://raw.githubusercontent.com/Epix37/HDT-Data/master/news";
Expand Down

0 comments on commit 25104b8

Please sign in to comment.