Skip to content

Commit

Permalink
Created V2. Pulled some LogReader bulk into Handlers
Browse files Browse the repository at this point in the history
  • Loading branch information
Mattish committed Aug 20, 2015
1 parent db7c30d commit b51d81b
Show file tree
Hide file tree
Showing 16 changed files with 1,352 additions and 17 deletions.
1 change: 1 addition & 0 deletions Hearthstone Deck Tracker.sln.DotSettings
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@
<s:String x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/WRAP_CHAINED_METHOD_CALLS/@EntryValue">WRAP_IF_LONG</s:String>
<s:String x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/WRAP_FOR_STMT_HEADER_STYLE/@EntryValue">WRAP_IF_LONG</s:String>
<s:String x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/WRAP_TERNARY_EXPR_STYLE/@EntryValue">WRAP_IF_LONG</s:String>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ESettingsUpgrade_002EAddAccessorOwnerDeclarationBracesMigration/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ESettingsUpgrade_002EMigrateBlankLinesAroundFieldToBlankLinesAroundProperty/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ESettingsUpgrade_002EMigrateThisQualifierSettings/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

using System.Windows;
using Hearthstone_Deck_Tracker.Hearthstone;
using Hearthstone_Deck_Tracker.LogReader;

#endregion

Expand Down Expand Up @@ -113,7 +114,7 @@ private void CheckboxRemoveCards_Checked(object sender, RoutedEventArgs e)
Game.Reset();
if(DeckList.Instance.ActiveDeck != null)
Game.SetPremadeDeck((Deck)DeckList.Instance.ActiveDeck.Clone());
HsLogReader.Instance.Reset(true);
HsLogReaderV2.Instance.Reset(true);
Helper.MainWindow.Overlay.Update(true);
}

Expand All @@ -126,7 +127,7 @@ private void CheckboxRemoveCards_Unchecked(object sender, RoutedEventArgs e)
Game.Reset();
if(DeckList.Instance.ActiveDeck != null)
Game.SetPremadeDeck((Deck)DeckList.Instance.ActiveDeck.Clone());
HsLogReader.Instance.Reset(true);
HsLogReaderV2.Instance.Reset(true);
Helper.MainWindow.Overlay.Update(true);
}

Expand Down
9 changes: 5 additions & 4 deletions Hearthstone Deck Tracker/GameEventHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using Hearthstone_Deck_Tracker.Enums;
using Hearthstone_Deck_Tracker.Hearthstone;
using Hearthstone_Deck_Tracker.HearthStats.API;
using Hearthstone_Deck_Tracker.LogReader;
using Hearthstone_Deck_Tracker.Replay;
using Hearthstone_Deck_Tracker.Stats;
using Hearthstone_Deck_Tracker.Windows;
Expand Down Expand Up @@ -134,7 +135,7 @@ public void HandleInMenu()
}
if(!Game.IsUsingPremade)
Game.DrawnLastGame = new List<Card>(Game.PlayerDrawn);
HsLogReader.Instance.ClearLog();
HsLogReaderV2.Instance.ClearLog();
if(!Config.Instance.KeepDecksVisible)
Game.Reset(false);
if(Game.CurrentGameStats != null && Game.CurrentGameStats.Result != GameResult.None)
Expand Down Expand Up @@ -288,7 +289,7 @@ public static async void HandleGameEnd()
else
Game.CurrentGameStats.OpponentName = Game.CurrentGameStats.OpponentHero;

Game.CurrentGameStats.Turns = HsLogReader.Instance.GetTurnNumber();
Game.CurrentGameStats.Turns = HsLogReaderV2.Instance.GetTurnNumber();
if(Config.Instance.DiscardZeroTurnGame && Game.CurrentGameStats.Turns < 1)
{
Logger.WriteLine("Game has 0 turns, discarded. (DiscardZeroTurnGame)", "GameEventHandler");
Expand Down Expand Up @@ -379,7 +380,7 @@ public static async void HandleGameEnd()
if(Game.CurrentGameMode == GameMode.None)
await GameModeDetection(300); //give the user 5 minutes to get out of the victory/defeat screen
if(Game.CurrentGameMode == GameMode.Casual)
await HsLogReader.Instance.RankedDetection();
await HsLogReaderV2.Instance.RankedDetection();
if(Game.CurrentGameMode == GameMode.Ranked && !_lastGame.HasRank)
await RankDetection(5);
await GameModeSaved(15);
Expand Down Expand Up @@ -483,7 +484,7 @@ private static void SaveAndUpdateStats()

if(Game.CurrentGameStats != null)
{
Game.CurrentGameStats.Turns = HsLogReader.Instance.GetTurnNumber();
Game.CurrentGameStats.Turns = HsLogReaderV2.Instance.GetTurnNumber();
if(Config.Instance.DiscardZeroTurnGame && Game.CurrentGameStats.Turns < 1)
{
Logger.WriteLine("Game has 0 turns, discarded. (DiscardZeroTurnGame)", "GameEventHandler");
Expand Down
9 changes: 9 additions & 0 deletions Hearthstone Deck Tracker/Hearthstone Deck Tracker.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,15 @@
<DependentUpon>OverlayPlayer.xaml</DependentUpon>
</Compile>
<Compile Include="Hearthstone\Mechanic.cs" />
<Compile Include="LogReader\AssetHandler.cs" />
<Compile Include="LogReader\Handlers\BobHandler.cs" />
<Compile Include="LogReader\Handlers\ZoneHandler.cs" />
<Compile Include="LogReader\HsGameState.cs" />
<Compile Include="LogReader\HsLogReaderConstants.cs" />
<Compile Include="LogReader\HsLogReaderV2.cs" />
<Compile Include="LogReader\Handlers\PowerHandler.cs" />
<Compile Include="LogReader\Handlers\RachelleHandler.cs" />
<Compile Include="LogReader\Handlers\TagChangeHandler.cs" />
<Compile Include="Plugins\IPlugin.cs" />
<Compile Include="Hearthstone\CardDb.cs" />
<Compile Include="Plugins\PluginManager.cs" />
Expand Down
27 changes: 24 additions & 3 deletions Hearthstone Deck Tracker/HsLogReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,29 @@

namespace Hearthstone_Deck_Tracker
{
public class HsLogReader
{
public interface IHsLogReader
{
/// <summary>
/// Start tracking gamelogs with default impelementaion of GameEventHandler
/// </summary>
void Start();

/// <summary>
/// Start tracking gamelogs with custom impelementaion of GameEventHandler
/// </summary>
/// <param name="gh"> Custom Game handler implementation </param>
void Start(IGameHandler gh);

void Stop();
void ClearLog();
Task<bool> RankedDetection(int timeoutInSeconds = 3);
void GetCurrentRegion();
void Reset(bool full);
}

[Obsolete("Use HsLogReaderV2")]
public class HsLogReader : IHsLogReader
{
//should be about 180,000 lines
private const int MaxFileLength = 6000000;
private readonly Regex _actionStartRegex = new Regex(@".*ACTION_START.*id=(?<id>\d*).*(cardId=(?<Id>(\w*))).*BlockType=POWER.*Target=(?<target>(.+))");
Expand Down Expand Up @@ -1172,7 +1193,7 @@ public void ClearLog()
_gameLoaded = false;
}

internal void Reset(bool full)
public void Reset(bool full)
{
if(full)
{
Expand Down
46 changes: 46 additions & 0 deletions Hearthstone Deck Tracker/LogReader/AssetHandler.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
using System;
using System.Text.RegularExpressions;
using Hearthstone_Deck_Tracker.Enums;
using Hearthstone_Deck_Tracker.Hearthstone;

namespace Hearthstone_Deck_Tracker.LogReader
{
public class AssetHandler
{
public void Handle(string logLine, HsGameState gameState)
{
if (gameState.AwaitingRankedDetection)
{
gameState.LastAssetUnload = DateTime.Now;
gameState.WaitingForFirstAssetUnload = false;
}
if (logLine.Contains("Medal_Ranked_"))
{
var match = Regex.Match(logLine, "Medal_Ranked_(?<rank>(\\d+))");
if (match.Success)
{
int rank;
if (int.TryParse(match.Groups["rank"].Value, out rank))
gameState.GameHandler.SetRank(rank);
}
}
else if (logLine.Contains("rank_window"))
{
gameState.FoundRanked = true;
gameState.GameHandler.SetGameMode(GameMode.Ranked);
}
else if (HsLogReaderConstants.UnloadCardRegex.IsMatch(logLine))
{
var id = HsLogReaderConstants.UnloadCardRegex.Match(logLine).Groups["id"].Value;
if (Game.CurrentGameMode == GameMode.Arena)
gameState.GameHandler.HandlePossibleArenaCard(id);
else
gameState.GameHandler.HandlePossibleConstructedCard(id, true);
}
else if (HsLogReaderConstants.UnloadBrawlAsset.IsMatch(logLine))
{
gameState.GameHandler.SetGameMode(GameMode.Brawl);
}
}
}
}
35 changes: 35 additions & 0 deletions Hearthstone Deck Tracker/LogReader/Handlers/BobHandler.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using Hearthstone_Deck_Tracker.Enums;
using Hearthstone_Deck_Tracker.Hearthstone;

namespace Hearthstone_Deck_Tracker.LogReader.Handlers
{
public class BobHandler
{
public void Handle(string logLine, HsGameState gameState)
{
if (logLine.StartsWith("[Bob] ---RegisterScreenPractice---"))
gameState.GameHandler.SetGameMode(GameMode.Practice);
else if (logLine.StartsWith("[Bob] ---RegisterScreenTourneys---"))
gameState.GameHandler.SetGameMode(GameMode.Casual);
else if (logLine.StartsWith("[Bob] ---RegisterScreenForge---"))
{
gameState.GameHandler.SetGameMode(GameMode.Arena);
Game.ResetArenaCards();
}
else if (logLine.StartsWith("[Bob] ---RegisterScreenFriendly---"))
gameState.GameHandler.SetGameMode(GameMode.Friendly);
else if (logLine.StartsWith("[Bob] ---RegisterScreenBox---"))
{
//game ended - back in menu
if (Game.CurrentGameMode == GameMode.Spectator)
gameState.GameEnd();
}
else if (logLine.StartsWith("[Bob] ---RegisterFriendChallenge---"))
gameState.GameHandler.HandleInMenu();
else if (logLine.StartsWith("[Bob] ---RegisterScreenCollectionManager---"))
gameState.GameHandler.ResetConstructedImporting();
else if (logLine.StartsWith("[Bob] ---RegisterProfileNotices---"))
gameState.GameLoaded = true;
}
}
}
Loading

0 comments on commit b51d81b

Please sign in to comment.