/// <summary> /// Extracts all unique unit seat mappings from the script expressions of a scnr based script file. /// </summary> /// <param name="scnr">The scnr based script file.</param> /// <param name="reader">The stream to read from.</param> /// <param name="op">A lookup containing script type information.</param> /// <returns>All unique unit seat mappings contained in the script expressions.</returns> public static IEnumerable <UnitSeatMapping> ExtractScnrSeatMappings(ScnrScriptFile scnr, IReader reader, OpcodeLookup op) { ScriptTable scripts = scnr.LoadScripts(reader); ScriptValueType typeInfo = op.GetTypeInfo("unit_seat_mapping"); // find all unique mappings SortedDictionary <uint, UnitSeatMapping> uniqueMappings = new SortedDictionary <uint, UnitSeatMapping>(); foreach (var exp in scripts.Expressions) { if (exp.Opcode == typeInfo.Opcode && exp.ReturnType == typeInfo.Opcode && !exp.Value.IsNull) { // Calculate the index and only add it if it doesn't exist yet. uint index = exp.Value.UintValue & 0xFFFF; if (!uniqueMappings.ContainsKey(index)) { uint count = (exp.Value.UintValue & 0xFFFF0000) >> 16; string name = exp.StringValue; UnitSeatMapping mapping = new UnitSeatMapping((short)index, (short)count, name); uniqueMappings.Add(index, mapping); } } } return(uniqueMappings.Values); }
public ObjectCompletion(UnitSeatMapping mapping) { Text = mapping.Name; Description = "[UNIT_SEAT_MAPPING]"; Priority = 0.8; var image = new BitmapImage(new Uri("pack://application:,,,/Metro/Images/Object_16x.png")); image.Freeze(); Image = image; }
public void AddUnitSeatMapping(UnitSeatMapping mapping) { if (_unitSeatMappings.ContainsKey(mapping.Name)) { throw new InvalidOperationException($"The context collection has multiple definitions for the unit seat mapping {mapping.Name}."); } else { _unitSeatMappings.Add(mapping.Name, mapping); } }
public bool TryGetUnitSeatMapping(string name, out UnitSeatMapping mapping) { return(_unitSeatMappings.TryGetValue(name, out mapping)); }
/// <summary> /// Creates unit seat mappings from mapping information. Also identifies and handles mapping groups. /// </summary> /// <param name="information">The information</param> /// <returns>A <see cref="IEnumerable"/> containing the finalized seat mappings.</returns> private static IEnumerable <UnitSeatMapping> CreateUnitSeatMappings(MappingInformation[] information, PostProcessing postProcessing) { var queue = new Queue <MappingInformation>(information); var result = new List <UnitSeatMapping>(); while (queue.Count > 0) { MappingInformation info = queue.Dequeue(); var members = new List <MappingInformation>(); var processedTags = new List <string>(); members.Add(info); processedTags.Add(info.TagName); // Retrieve other group members. while (queue.Count > 0) { MappingInformation next = queue.Peek(); // The border of a group is reached, when any of these conditions is true. if (next.TagName == info.TagName || next.SplitName[0] != info.SplitName[0] || next.SplitName[1] != info.SplitName[1] || members.Contains(next) || processedTags.Contains(next.TagName)) { break; } else { processedTags.Add(next.TagName); members.Add(queue.Dequeue()); } } // Handle mapping groups. if (members.Count > 1) { if (postProcessing == PostProcessing.HaloReach) { // Some groups are not being detected correctly and need to be postprocessed. // If subsequent group member share the same name, they belong to a separate group. In this case the original group needs to be split. List <MappingInformation> currentGroup = new List <MappingInformation> { members.First() }; foreach (var i in members.Skip(1)) { if (currentGroup.Count > 1 && currentGroup.Last().Name != i.Name && currentGroup.All(i => i.Name == currentGroup[0].Name)) { var group = new UnitSeatMapping(currentGroup.First().Index, (short)currentGroup.Count, currentGroup.First().Name); result.Add(group); currentGroup.Clear(); } currentGroup.Add(i); } // Add the last group. var mapping = new UnitSeatMapping(currentGroup.First().Index, (short)currentGroup.Count, GetMappingGroupName(currentGroup)); result.Add(mapping); currentGroup.Clear(); } else if (postProcessing == PostProcessing.Halo3) { // Halo 3 doesn't require any postprocessing. result.Add(new UnitSeatMapping(members[0].Index, (short)members.Count, GetMappingGroupName(members))); } } // Handle single mappings. else { result.Add(new UnitSeatMapping(members[0].Index, 1, members[0].Name)); } } return(result); }