Permalink
Browse files

Created V2. Pulled some LogReader bulk into Handlers

  • Loading branch information...
1 parent db7c30d commit b51d81bad1e997c2d4c4d8142e6f8118be7ce28f @Mattish Mattish committed Aug 20, 2015
@@ -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>
@@ -2,6 +2,7 @@
using System.Windows;
using Hearthstone_Deck_Tracker.Hearthstone;
+using Hearthstone_Deck_Tracker.LogReader;
#endregion
@@ -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);
}
@@ -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);
}
@@ -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;
@@ -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)
@@ -288,7 +289,7 @@ public static void HandleGameStart()
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");
@@ -379,7 +380,7 @@ public static void HandleGameStart()
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);
@@ -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");
@@ -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" />
@@ -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>(.+))");
@@ -1172,7 +1193,7 @@ public void ClearLog()
_gameLoaded = false;
}
- internal void Reset(bool full)
+ public void Reset(bool full)
{
if(full)
{
@@ -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);
+ }
+ }
+ }
+}
@@ -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;
+ }
+ }
+}
Oops, something went wrong.

0 comments on commit b51d81b

Please sign in to comment.