Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using TagTool.Cache;
- using TagTool.Commands.Common;
- namespace TagTool.Commands.Tags
- {
- class ListUnnamedTagsCommand : Command
- {
- public HaloOnlineCacheContext CacheContext { get; }
- public ListUnnamedTagsCommand(HaloOnlineCacheContext cacheContext)
- : base(false,
- "ListUnnamedTags",
- "Lists all unnamed tags in the current tag cache",
- "ListUnnamedTags",
- "Lists all unnamed tags in the current tag cache")
- {
- CacheContext = cacheContext;
- }
- public override object Execute(List<string> args)
- {
- if (args.Count != 0)
- return false;
- var unnamedTags = new List<CachedTagInstance>();
- foreach (var tag in CacheContext.TagCache.Index)
- {
- if (tag != null && (tag.Name == null || tag.Name == ""))
- {
- //Console.WriteLine($"0x{tag.Index:X4}.{tag.Group.Tag.ToString()}");
- unnamedTags.Add(tag);
- }
- }
- Console.WriteLine($"Total unnamed tag count: {unnamedTags.Count}");
- var topmostTags = new List<CachedTagInstance>();
- foreach (var tag in unnamedTags)
- {
- var topmost = FindTopmost(tag);
- foreach (var topmostTag in topmost)
- {
- var topmostInstance = CacheContext.GetTag(topmostTag);
- if (!topmostTags.Contains(topmostInstance))
- topmostTags.Add(topmostInstance);
- }
- }
- Console.WriteLine("Topmost tags:");
- foreach (var tag in topmostTags)
- {
- var tagName = (tag.Name == null || tag.Name == "") ?
- $"0x{tag.Index:X4}" :
- tag.Name;
- Console.WriteLine($"{tagName}.{tag.Group.Tag}");
- }
- Console.WriteLine($"Total topmost tag count: {topmostTags.Count}");
- return true;
- }
- private List<int> FindTopmost(CachedTagInstance instance)
- {
- var result = new List<int>();
- if (instance == null)
- return result;
- var indexQueue = new List<int> { instance.Index };
- while (indexQueue.Count != 0)
- {
- var nextIndexQueue = new List<int>();
- foreach (var index in indexQueue)
- {
- if (result.Contains(index))
- continue;
- foreach (var currentInstance in CacheContext.TagCache.Index)
- {
- if (currentInstance == null || currentInstance.Index == index)
- continue;
- foreach (var dependentIndex in currentInstance.Dependencies)
- {
- var dependency = CacheContext.GetTag(dependentIndex);
- if (dependency == null || dependency.Index != index)
- continue;
- if (!nextIndexQueue.Contains(currentInstance.Index))
- nextIndexQueue.Add(currentInstance.Index);
- }
- }
- }
- if (nextIndexQueue.Count == 0)
- {
- foreach (var entry in indexQueue)
- {
- if (!result.Contains(entry))
- result.Add(entry);
- }
- break;
- }
- else if (nextIndexQueue.Count == 1)
- {
- var dependentInstance = CacheContext.GetTag(nextIndexQueue[0]);
- if (dependentInstance.IsInGroup("cfgt") ||
- dependentInstance.IsInGroup("matg") ||
- dependentInstance.IsInGroup("scnr"))
- {
- result.AddRange(indexQueue);
- break;
- }
- }
- else if (indexQueue.Count == nextIndexQueue.Count)
- {
- var equal = true;
- foreach (var entry in nextIndexQueue)
- {
- if (!indexQueue.Contains(entry))
- {
- equal = false;
- break;
- }
- }
- if (equal)
- break;
- }
- indexQueue = nextIndexQueue;
- }
- return result;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement