/// <summary>
        /// Fills a context collection with unit seat mappings and context objects.
        /// </summary>
        /// <param name="reader">The stream to read from.</param>
        /// <param name="cache">The cache file containing the scripting context.</param>
        /// <param name="buildinfo">The cache file's build information.</param>
        /// <param name="data">The meta data in which is the context is stored.</param>
        /// <param name="collection">The context collection.</param>
        private static void FillContextCollection(IReader reader, ICacheFile cache, EngineDescription buildinfo, StructureValueCollection data, ScriptingContextCollection collection)
        {
            var tagBlocks = data.GetTagBlocks();

            foreach (var block in tagBlocks)
            {
                if (block.Value.Length == 0)
                {
                    continue;
                }

                if (block.Key == "unit_seat_mapping")
                {
                    HandleUnitSeatMappings(reader, cache, buildinfo, block, collection);
                }
                else if (IsWrapperBlock(block))
                {
                    HandleParentWrapperBlock(block, collection);
                }
                else
                {
                    collection.AddObjectGroup(CreateContextBlock(block, false));
                }
            }
        }
        /// <summary>
        /// Creates a context object from meta data.
        /// </summary>
        /// <param name="index">The index of the object.</param>
        /// <param name="group">The object group of the object.</param>
        /// <param name="isChildObject">is true if thi sobject is the child of another object.</param>
        /// <param name="data">The meta data.</param>
        /// <returns>A context object.</returns>
        private static ScriptingContextObject CreateContextObject(int index, string group, bool isChildObject, StructureValueCollection data, int wrapperIndex = -1)
        {
            string name   = data.HasStringID("Name") ? data.GetStringID("Name") : data.GetString("Name");
            var    result = new ScriptingContextObject(name.ToLowerInvariant(), index, group, isChildObject, wrapperIndex);

            var childBlocks = data.GetTagBlocks();

            if (childBlocks.Length > 0)
            {
                foreach (var block in childBlocks.Where(b => b.Value.Length > 0))
                {
                    // Handle child blocks, which are wrapped up in another block without a name field.
                    if (IsWrapperBlock(block))
                    {
                        var wrappedBlocks = new Dictionary <string, List <ScriptingContextObject> >();

                        // Iterate through the wrapper elements and collect all wrapped blocks and their objects.
                        for (int i = 0; i < block.Value.Length; i++)
                        {
                            var innerChildrenBlocks = block.Value[i].GetTagBlocks();
                            foreach (var inner in innerChildrenBlocks)
                            {
                                var wrappedObjects = GetWrapperContextObjects(inner, i);
                                if (wrappedBlocks.ContainsKey(inner.Key))
                                {
                                    wrappedBlocks[inner.Key].AddRange(wrappedObjects);
                                }
                                else
                                {
                                    wrappedBlocks[inner.Key] = wrappedObjects.ToList();
                                }
                            }
                        }

                        // Add the grouped blocks and objects to the result.
                        foreach (var groupedBlock in wrappedBlocks)
                        {
                            result.AddChildBlock(new ScriptingContextBlock(groupedBlock.Key, groupedBlock.Value));
                        }
                    }
                    // Handle regular child blocks.
                    else
                    {
                        result.AddChildBlock(CreateContextBlock(block, true));
                    }
                }
            }

            return(result);
        }