Beispiel #1
0
        public TrainerPokemonTeamRun(IDataModel model, int start, SortedSpan <int> sources) : base(start, sources)
        {
            this.model = model;

            // trainer format (abbreviated):
            //     0           1       2         3        4-15     16     18      20     22       24          28       32         36          40 total
            // [structType. class. introMusic. sprite. name\"\"12 item1: item2: item3: item4: doubleBattle:: ai:: pokemonCount:: pokemon<>]
            StructType   = 0;
            ElementCount = 1;
            foreach (var source in sources)
            {
                if (!(model.GetNextRun(source) is ITableRun))
                {
                    continue;
                }
                StructType   = model[source - TrainerFormat_PointerOffset];
                ElementCount = model.ReadMultiByteValue(source - TrainerFormat_PointerOffset + TrainerFormat_PokemonCountOffset, 4);
                break;
            }

            var segments = Initialize();

            ElementContent = segments;
            ElementLength  = ElementContent.Sum(segment => segment.Length);
        }
Beispiel #2
0
        private TrainerPokemonTeamRun(IDataModel model, int start, SortedSpan <int> sources, int primarySource) : base(start, sources)
        {
            this.model   = model;
            StructType   = model[primarySource - TrainerFormat_PointerOffset];
            ElementCount = model[primarySource - TrainerFormat_PointerOffset + TrainerFormat_PokemonCountOffset];
            var segments = Initialize();

            ElementContent = segments;
            ElementLength  = ElementContent.Sum(segment => segment.Length);
        }
        private ArrayRun(IDataModel data, string format, int start, IReadOnlyList <int> pointerSources) : base(start, pointerSources)
        {
            owner        = data;
            FormatString = format;
            SupportsPointersToElements = format.StartsWith(AnchorStart.ToString());
            if (SupportsPointersToElements)
            {
                format = format.Substring(1);
            }
            var closeArray = format.LastIndexOf(ArrayEnd.ToString());

            if (!format.StartsWith(ArrayStart.ToString()) || closeArray == -1)
            {
                throw new ArrayRunParseException($"Array Content must be wrapped in {ArrayStart}{ArrayEnd}.");
            }
            var segments = format.Substring(1, closeArray - 1);
            var length   = format.Substring(closeArray + 1);

            ElementContent = ParseSegments(segments, data);
            if (ElementContent.Count == 0)
            {
                throw new ArrayRunParseException("Array Content must not be empty.");
            }
            ElementLength = ElementContent.Sum(e => e.Length);

            FormatMatchFlags flags = default;

            if (ElementContent.Count == 1)
            {
                flags |= FormatMatchFlags.IsSingleSegment;
            }

            if (length.Length == 0)
            {
                var nextRun = owner.GetNextRun(Start);
                while (nextRun is NoInfoRun && nextRun.Start < owner.Count)
                {
                    nextRun = owner.GetNextRun(nextRun.Start + 1);
                }
                var byteLength   = 0;
                var elementCount = 0;
                while (Start + byteLength + ElementLength <= nextRun.Start && DataMatchesElementFormat(owner, Start + byteLength, ElementContent, flags, nextRun))
                {
                    byteLength += ElementLength;
                    elementCount++;
                }
                LengthFromAnchor = string.Empty;
                ElementCount     = Math.Max(1, elementCount); // if the user said there's a format here, then there is, even if the format it wrong.
            }
            else if (int.TryParse(length, out int result))
            {
                // fixed length is easy
                LengthFromAnchor = string.Empty;
                ElementCount     = Math.Max(1, result);
            }
            else
            {
                LengthFromAnchor = length;
                ElementCount     = Math.Max(1, ParseLengthFromAnchor());
            }

            Length = ElementLength * ElementCount;
        }