-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(Choices): start parsing SendChoices
- Loading branch information
Showing
7 changed files
with
114 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
using System.Collections.Generic; | ||
using Hearthstone_Deck_Tracker.Hearthstone.Entities; | ||
using HearthDb.Enums; | ||
using System; | ||
|
||
namespace Hearthstone_Deck_Tracker.Hearthstone | ||
{ | ||
[Serializable] | ||
public class Choice | ||
{ | ||
public readonly int Id; | ||
public readonly ChoiceType ChoiceType; | ||
public readonly List<Entity> ChosenEntities = new List<Entity>(); | ||
|
||
public Choice(int id, ChoiceType choiceType) | ||
{ | ||
Id = id; | ||
ChoiceType = choiceType; | ||
} | ||
|
||
public void AttachChosenEntity(int index, Entity entity) | ||
{ | ||
ChosenEntities.Add(entity); | ||
} | ||
} | ||
} |
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
37 changes: 37 additions & 0 deletions
37
Hearthstone Deck Tracker/LogReader/Handlers/ChoicesHandler.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
using Hearthstone_Deck_Tracker.Hearthstone; | ||
using Hearthstone_Deck_Tracker.LogReader.Interfaces; | ||
using System; | ||
using HearthDb.Enums; | ||
using static Hearthstone_Deck_Tracker.LogReader.LogConstants.Choices; | ||
|
||
namespace Hearthstone_Deck_Tracker.LogReader.Handlers | ||
{ | ||
internal class ChoicesHandler | ||
{ | ||
SendChoicesHandler _sendChoicesHandler = new SendChoicesHandler(); | ||
|
||
public void Handle(string logLine, IHsGameState gameState, IGame game) | ||
{ | ||
if(SendChoicesHeaderRegex.IsMatch(logLine)) | ||
{ | ||
var match = SendChoicesHeaderRegex.Match(logLine); | ||
var choiceId = int.Parse(match.Groups["id"].Value); | ||
if(!Enum.TryParse(match.Groups["choiceType"].Value, out ChoiceType choiceType)) | ||
choiceType = ChoiceType.INVALID; | ||
_sendChoicesHandler.SendChoices(choiceId, choiceType, gameState, game); | ||
} | ||
else if(SendChoicesBodyRegex.IsMatch(logLine)) | ||
{ | ||
var match = SendChoicesBodyRegex.Match(logLine); | ||
var index = int.Parse(match.Groups["index"].Value); | ||
var entityId = int.Parse(match.Groups["id"].Value); | ||
_sendChoicesHandler.SendChoice(index, entityId, gameState, game); | ||
} | ||
else | ||
{ | ||
// Terminate the current Choice. | ||
_sendChoicesHandler.Flush(gameState, game); | ||
} | ||
} | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
Hearthstone Deck Tracker/LogReader/Handlers/SendChoicesHandler.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
using Hearthstone_Deck_Tracker.Hearthstone; | ||
using Hearthstone_Deck_Tracker.LogReader.Interfaces; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using HearthDb.Enums; | ||
|
||
namespace Hearthstone_Deck_Tracker.LogReader.Handlers | ||
{ | ||
internal class SendChoicesHandler | ||
{ | ||
private Choice? Choice; | ||
|
||
public void SendChoices(int id, ChoiceType choiceType, IHsGameState gameState, IGame game) | ||
{ | ||
Choice = new Choice(id, choiceType); | ||
} | ||
|
||
public void SendChoice(int index, int entityId, IHsGameState gameState, IGame game) | ||
{ | ||
if(Choice is null) return; | ||
|
||
if(game.Entities.TryGetValue(entityId, out var entity)) | ||
Choice.AttachChosenEntity(index, entity); | ||
} | ||
|
||
public void Flush(IHsGameState gameState, IGame game) | ||
{ | ||
if(Choice is null) return; | ||
|
||
gameState.GameHandler?.HandlePlayerSendChoices(Choice); | ||
Choice = null; | ||
} | ||
} | ||
} |
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