public void ParsingTest() { var manager = new LogParserManager(); var parser1 = new MockParser("1"); var parser2 = new MockParser("2"); var line1 = new Line("1", "Line1"); var line2 = new Line("2", "Line2"); var line3 = new Line("1", "Line3"); manager.RegisterParser(parser1); manager.RegisterParser(parser2); manager.Parse(new [] { line1 }); Assert.AreEqual(line1, parser1.LastParsedLine); Assert.IsNull(parser2.LastParsedLine); manager.Parse(new [] { line2 }); Assert.AreEqual(line1, parser1.LastParsedLine); Assert.AreEqual(line2, parser2.LastParsedLine); manager.UnregisterParser(parser1); manager.Parse(new[] { line3 }); Assert.AreEqual(line1, parser1.LastParsedLine); manager.RegisterParser(parser1); manager.Parse(new[] { line3 }); Assert.AreEqual(line3, parser1.LastParsedLine); }
public GameEventManager(Game game, ILogInput logInput, IGameDataProvider gameData) { _game = game; _gameData = gameData; _arenaWatcher = new ArenaWatcher(gameData); _arenaWatcher.RunComplete += game.Arena.OnArenaRunComplete; _arenaWatcher.CardPicked += game.Arena.OnArenaDraftPick; _arenaWatcher.ChoicesChanged += game.Arena.OnArenaDraftChoices; _arenaWatcher.DeckComplete += game.Arena.OnArenaDraftComplete; _packWatcher = new PackWatcher(gameData); _packWatcher.PackOpened += game.OnPackOpened; _dungeonRunWatcher = new DungeonRunWatcher(new DungeonRunData(game, gameData)); _dungeonRunWatcher.DungeonRunMatchStarted += game.OnDungeonRunMatchStarted; _dungeonRunWatcher.DungeonRunDeckUpdated += game.OnDungeonRunDeckUpdated; _friendlyChallengeWatcher = new FriendlyChallengeWatcher(gameData); _friendlyChallengeWatcher.FriendlyChallenge += game.OnFriendlyChallenge; var logParserManager = new LogParserManager(); var powerParser = new PowerParser(new DefaultGameInfoProvider(game)); powerParser.CreateGame += () => game.OnCreateGame(null); powerParser.PowerTaskListLog += args => game.OnGameTimeChanged(args.Line.Time); powerParser.GameStateChange += mod => game.CurrentGame?.Apply(mod); powerParser.BlockStart += block => game.GameStateEvents.OnBlockStart(block, game.CurrentGame); powerParser.BlockEnd += block => game.GameStateEvents.OnBlockEnd(block, game.CurrentGame); powerParser.GameStateLog += args => game.CurrentGame?.AppendLog(args); powerParser.SetupComplete += game.OnSetupComplete; logParserManager.RegisterParser(powerParser); var decksParser = new DecksParser(); decksParser.FindingGame += game.OnQueuedForGame; decksParser.EditedDeck += game.Collection.OnDeckEdited; decksParser.FoundDecks += game.Collection.OnDecksLoaded; logParserManager.RegisterParser(decksParser); var loadingScreenParser = new LoadingScreenParser(); loadingScreenParser.ModeChanged += game.OnModeChanged; loadingScreenParser.ModeChanged += LoadingScreenParser_OnModeChanged; logParserManager.RegisterParser(loadingScreenParser); var arenaParser = new ArenaParser(); arenaParser.ArenaRunComplete += () => _arenaWatcher.Update(); logParserManager.RegisterParser(arenaParser); var rachelleParser = new RachelleParser(); rachelleParser.DeckDeleted += game.Collection.OnDeckDeleted; rachelleParser.GoldProgressWins += game.OnGoldProgressWins; logParserManager.RegisterParser(rachelleParser); logInput.NewLines += eventArgs => logParserManager.Parse(eventArgs.Lines); }