/// <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> /// Processes a parent wrapper block and adds its child blocks to a context collection. /// </summary> /// <param name="block">The parent wrapper block.</param> /// <param name="collection">The context collection.</param> /// <exception cref="ArgumentException">Thrown when a parent wrapper block has more than one element.</exception> private static void HandleParentWrapperBlock(KeyValuePair <string, StructureValueCollection[]> block, ScriptingContextCollection collection) { if (block.Value.Length != 1) { throw new ArgumentException($"The wrapper context block {block.Key} doesn't have exactly one element."); } var innerBlocks = block.Value[0].GetTagBlocks(); foreach (var inner in innerBlocks) { collection.AddObjectGroup(CreateContextBlock(inner, false)); } }