Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
move PackOpeningWatcher to HearthWatcher project
- Loading branch information
Showing
11 changed files
with
115 additions
and
85 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,17 @@ | |||
using System.Collections.Generic; | |||
using HearthMirror.Objects; | |||
|
|||
namespace HearthWatcher.EventArgs | |||
{ | |||
public class PackEventArgs : System.EventArgs | |||
{ | |||
public PackEventArgs(List<Card> cards, int packId) | |||
{ | |||
Cards = cards; | |||
PackId = packId; | |||
} | |||
|
|||
public List<Card> Cards { get; } | |||
public int PackId { get; set; } | |||
} | |||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,60 @@ | |||
using System; | |||
using System.Collections.Generic; | |||
using System.Linq; | |||
using System.Threading.Tasks; | |||
using HearthMirror.Objects; | |||
using HearthWatcher.EventArgs; | |||
using HearthWatcher.Providers; | |||
|
|||
namespace HearthWatcher | |||
{ | |||
public class PackOpeningWatcher | |||
{ | |||
public delegate void PackEventHandler(object sender, PackEventArgs args); | |||
|
|||
private readonly List<Card> _previousPack = new List<Card>(); | |||
private readonly int _delay; | |||
private bool _running; | |||
private bool _watch; | |||
private readonly IPackProvider _packProvider; | |||
|
|||
public PackOpeningWatcher(IPackProvider packProvider, int delay = 1000) | |||
{ | |||
if(packProvider == null) | |||
throw new ArgumentNullException(nameof(packProvider)); | |||
_packProvider = packProvider; | |||
_delay = delay; | |||
} | |||
public event PackEventHandler NewPackEventHandler; | |||
|
|||
public void Run() | |||
{ | |||
_watch = true; | |||
if(!_running) | |||
CheckForPacks(); | |||
} | |||
|
|||
public void Stop() => _watch = false; | |||
|
|||
private async void CheckForPacks() | |||
{ | |||
_running = true; | |||
while(_watch) | |||
{ | |||
await Task.Delay(_delay); | |||
if(!_watch) | |||
break; | |||
var cards = _packProvider.GetCards(); | |||
if(cards?.Any() ?? false) | |||
{ | |||
if(cards.All(x => _previousPack.Any(c => c.Id == x.Id & c.Premium == x.Premium))) | |||
continue; | |||
_previousPack.Clear(); | |||
_previousPack.AddRange(cards); | |||
NewPackEventHandler?.Invoke(this, new PackEventArgs(cards, _packProvider.GetPackId())); | |||
} | |||
} | |||
_running = false; | |||
} | |||
} | |||
} |
2 changes: 1 addition & 1 deletion
2
HearthWatcher/IArenaProvider.cs → HearthWatcher/Providers/IArenaProvider.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,11 @@ | |||
using System.Collections.Generic; | |||
using HearthMirror.Objects; | |||
|
|||
namespace HearthWatcher.Providers | |||
{ | |||
public interface IPackProvider | |||
{ | |||
List<Card> GetCards(); | |||
int GetPackId(); | |||
} | |||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 0 additions & 66 deletions
66
Hearthstone Deck Tracker/Hearthstone/PackOpeningWatcher.cs
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters