Skip to content

Commit

Permalink
fixed card counts being wrong after creating/editing decks
Browse files Browse the repository at this point in the history
  • Loading branch information
epix37 committed Jun 26, 2014
1 parent 66e4acf commit a6438ef
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 24 deletions.
40 changes: 24 additions & 16 deletions Hearthstone Deck Tracker/Hearthstone.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,35 +77,43 @@ private void LoadCardDb(string languageTag)
var localizedCardNames = new Dictionary<string, string>();
if (languageTag != "enUS")
{
var localized = JObject.Parse(File.ReadAllText(string.Format("Files/cardsDB.{0}.json", languageTag)));
foreach (var cardType in localized)
var file = string.Format("Files/cardsDB.{0}.json", languageTag);
if(File.Exists(file))
{
if (cardType.Key != "Basic" && cardType.Key != "Expert" && cardType.Key != "Promotion" &&
cardType.Key != "Reward") continue;
foreach (var card in cardType.Value)
var localized = JObject.Parse(file);
foreach (var cardType in localized)
{
var tmp = JsonConvert.DeserializeObject<Card>(card.ToString());
localizedCardNames.Add(tmp.Id, tmp.Name);
if (cardType.Key != "Basic" && cardType.Key != "Expert" && cardType.Key != "Promotion" &&
cardType.Key != "Reward") continue;
foreach (var card in cardType.Value)
{
var tmp = JsonConvert.DeserializeObject<Card>(card.ToString());
localizedCardNames.Add(tmp.Id, tmp.Name);
}
}
}
}


//load engish db (needed for importing, etc)
var obj = JObject.Parse(File.ReadAllText("Files/cardsDB.enUS.json"));
var fileEng = "Files/cardsDB.enUS.json";
var tempDb = new Dictionary<string, Card>();
foreach (var cardType in obj)
if(File.Exists(fileEng))
{
if (cardType.Key != "Basic" && cardType.Key != "Expert" && cardType.Key != "Promotion" &&
cardType.Key != "Reward") continue;
foreach (var card in cardType.Value)
var obj = JObject.Parse(File.ReadAllText(fileEng));
foreach (var cardType in obj)
{
var tmp = JsonConvert.DeserializeObject<Card>(card.ToString());
if (languageTag != "enUS")
if (cardType.Key != "Basic" && cardType.Key != "Expert" && cardType.Key != "Promotion" &&
cardType.Key != "Reward") continue;
foreach (var card in cardType.Value)
{
tmp.LocalizedName = localizedCardNames[tmp.Id];
var tmp = JsonConvert.DeserializeObject<Card>(card.ToString());
if (languageTag != "enUS")
{
tmp.LocalizedName = localizedCardNames[tmp.Id];
}
tempDb.Add(tmp.Id, tmp);
}
tempDb.Add(tmp.Id, tmp);
}
}
_cardDb = new Dictionary<string, Card>(tempDb);
Expand Down
4 changes: 2 additions & 2 deletions Hearthstone Deck Tracker/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@
<RowDefinition Height="auto"></RowDefinition>
<RowDefinition Height="*"></RowDefinition>
</Grid.RowDefinitions>
<GroupBox Header="Additional Windows" Grid.Column="1" Grid.Row="0" HorizontalAlignment="Center" VerticalAlignment="Top" Height="417" Width="235" Margin="5,5,5,0" Grid.RowSpan="2">
<GroupBox Header="Additional Windows" Grid.Column="1" Grid.Row="0" HorizontalAlignment="Center" VerticalAlignment="Top" Height="478" Width="235" Margin="5,5,5,0" Grid.RowSpan="2">
<Grid>
<CheckBox x:Name="CheckboxWindowsTopmost" Content="Topmost" HorizontalAlignment="Left" Margin="10,33,0,0" VerticalAlignment="Top" Checked="CheckboxWindowsTopmost_Checked" Unchecked="CheckboxWindowsTopmost_Unchecked"/>
<CheckBox x:Name="CheckboxWindowsOpenAutomatically" Content="Show decks in additional windows" HorizontalAlignment="Left" Margin="10,10,0,0" VerticalAlignment="Top" Checked="CheckboxWindowsOpenAutomatically_Checked" Unchecked="CheckboxWindowsOpenAutomatically_Unchecked"/>
Expand Down Expand Up @@ -250,7 +250,7 @@
<CheckBox x:Name="CheckboxKeepDecksVisible" Content="Don't reset decks after game" HorizontalAlignment="Left" Margin="10,33,0,0" VerticalAlignment="Top" Width="200" Checked="CheckboxKeepDecksVisible_Checked" Unchecked="CheckboxKeepDecksVisible_Unchecked"/>
<CheckBox x:Name="CheckboxMinimizeTray" Content="Minimize to tray" HorizontalAlignment="Left" Margin="10,10,0,0" VerticalAlignment="Top" Checked="CheckboxMinimizeTray_Checked" Unchecked="CheckboxMinimizeTray_Unchecked" RenderTransformOrigin="1.518,2.778"/>
<CheckBox x:Name="CheckboxDeckDetection" Content="Automatic deck detection" HorizontalAlignment="Left" Margin="10,56,0,0" VerticalAlignment="Top" Checked="CheckboxDeckDetection_Checked" Unchecked="CheckboxDeckDetection_Unchecked"/>
<CheckBox x:Name="CheckboxAutoSelectDeck" Content="Autoselect if only 1 possible deck" HorizontalAlignment="Left" Margin="29,79,-11,0" VerticalAlignment="Top" Checked="CheckboxAutoSelectDeck_Checked" Unchecked="CheckboxAutoSelectDeck_Unchecked"/>
<CheckBox x:Name="CheckboxAutoSelectDeck" Content="Autoselect if 1 possible deck" HorizontalAlignment="Left" Margin="29,79,-11,0" VerticalAlignment="Top" Checked="CheckboxAutoSelectDeck_Checked" Unchecked="CheckboxAutoSelectDeck_Unchecked"/>
<ComboBox x:Name="ComboboxAccent" HorizontalAlignment="Left" Margin="64,146,0,0" VerticalAlignment="Top" Width="110" SelectionChanged="ComboboxAccent_SelectionChanged">
<ComboBox.ItemTemplate>
<DataTemplate>
Expand Down
14 changes: 9 additions & 5 deletions Hearthstone Deck Tracker/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,10 @@ public MainWindow()
Application.Current.Shutdown();
}
}
else
{
BtnExport.IsEnabled = false;
}


string languageTag = _config.SelectedLanguage;
Expand Down Expand Up @@ -454,7 +458,7 @@ private void HandleGameStart()
//select deck based on hero
if (!string.IsNullOrEmpty(_hearthstone.PlayingAs))
{
if (!_hearthstone.IsUsingPremade) return;
if (!_hearthstone.IsUsingPremade || !_config.AutoDeckDetection) return;

if (selectedDeck == null || selectedDeck.Class != _hearthstone.PlayingAs)
{
Expand Down Expand Up @@ -1175,7 +1179,7 @@ private void TextBoxDBFilter_KeyDown(object sender, KeyEventArgs e)
if (ListViewDB.Items.Count == 1)
{
var card = (Card) ListViewDB.Items[0];
AddCardToDeck(card);
AddCardToDeck((Card)card.Clone());
}
}
}
Expand Down Expand Up @@ -1237,7 +1241,7 @@ private void ListViewDB_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
if (originalSource != null)
{
var card = (Card)ListViewDB.SelectedItem;
AddCardToDeck(card);
AddCardToDeck((Card)card.Clone());
_newContainsDeck = true;
}
}
Expand Down Expand Up @@ -1270,7 +1274,7 @@ private void ListViewNewDeck_MouseRightButtonUp(object sender, MouseButtonEventA
if (originalSource != null)
{
var card = (Card)ListViewNewDeck.SelectedItem;
AddCardToDeck(card);
AddCardToDeck((Card)card.Clone());
}
}

Expand All @@ -1280,7 +1284,7 @@ private void ListViewDB_KeyDown(object sender, KeyEventArgs e)
{
var card = (Card) ListViewDB.SelectedItem;
if (string.IsNullOrEmpty(card.Name)) return;
AddCardToDeck(card);
AddCardToDeck((Card)card.Clone());
}
}

Expand Down
2 changes: 1 addition & 1 deletion Hearthstone Deck Tracker/Version.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
<Version>
<Major>0</Major>
<Minor>3</Minor>
<Revision>0</Revision>
<Revision>1</Revision>
<Build>0</Build>
</Version>

0 comments on commit a6438ef

Please sign in to comment.