Exemple #1
0
        private IEnumerable <bool> ParseBlock()
        {
            var match = BlockStartRegex.Match(this.parsing_log);

            if (!match.Success)
            {
                yield break;
            }

            var indent     = match.Groups["indent"].Value;
            var entity_raw = match.Groups["entity"].Value.Trim();
            var block_type = match.Groups["block_type"].Value.Trim();
            var target_raw = match.Groups["target"].Value.Trim();

            var entity_id = ParserUtilities.GetEntityIdFromRawString(this.game_state, entity_raw);

            if (entity_id < 0)
            {
                logger_.Info(String.Format("[INFO] Cannot get entity id '{0}'.", entity_raw));
            }

            var target_id = ParserUtilities.GetEntityIdFromRawString(this.game_state, target_raw);

            if (target_id < 0)
            {
                logger_.Info(String.Format("[INFO] Cannot get target id '{0}'.", target_raw));
            }

            if (this.BlockStart != null)
            {
                this.BlockStart(this, new BlockStartEventArgs(entity_id, block_type));
            }

            yield return(true);

            while (true)
            {
                if (BlockEndRegex.IsMatch(this.parsing_log))
                {
                    break;
                }

                bool matched = false;
                foreach (var ret in ParserUtilities.TrySubParsers(new List <Func <IEnumerable <bool> > >
                {
                    () => this.ParseFullEntity(),
                    () => this.ParseShowEntities(),
                    () => this.ParseTagChange(),
                    () => this.ParseHideEntity(),
                    () => this.ParseBlock(),
                    () => this.ParseMetadata()
                }))
                {
                    matched = true;
                    yield return(ret);
                }

                if (!matched)
                {
                    yield break;
                }
            }

            if (this.BlockEnd != null)
            {
                this.BlockEnd(this, new BlockEndEventArgs(entity_id, block_type));
            }

            yield return(true);
        }
Exemple #2
0
        private IEnumerable <bool> ParseCreateGame()
        {
            if (!CreateGameRegex.IsMatch(this.parsing_log))
            {
                yield break;
            }

            if (this.CreateGameEvent != null)
            {
                this.CreateGameEvent(this, new CreateGameEventArgs());
            }

            yield return(true);

            {
                bool matched = false;
                foreach (var ret in this.ParseGameEntityCreation())
                {
                    matched = true;
                    yield return(ret);
                }
                if (!matched)
                {
                    yield break;
                }
            }

            for (int i = 0; i < 2; i++) // two players
            {
                bool matched = false;
                foreach (var ret in this.ParsePlayerEntityCreation())
                {
                    matched = true;
                    yield return(ret);
                }
                if (!matched)
                {
                    yield break;
                }
            }

            while (true)
            {
                bool matched = false;
                foreach (var ret in ParserUtilities.TrySubParsers(new List <Func <IEnumerable <bool> > > {
                    () => { return(this.ParseFullEntity()); },
                    () => { return(this.ParseShowEntities()); },
                    () => { return(this.ParseTagChange()); },
                    () => { return(this.ParseHideEntity()); },
                    () => { return(this.ParseBlock()); }
                }))
                {
                    matched = true;
                    yield return(ret);
                }

                if (!matched)
                {
                    yield break;
                }
            }
        }