public void Parse()
{
ThreadPool.SetMaxThreads(2, 2);
Loading = true;
// First load prefabs
PrefabsLookup = PrefabFiles.Select(x => new Ets2Prefab(this, x)).ToList();
// Load all LUTs
LoadLUT();
ItemSearchRequests = new List<Ets2ItemSearchRequest>();
Sectors = SectorFiles.Select(x => new Ets2Sector(this, x)).ToList();
// 2-stage process so we can validate node UID's at item stage
ThreadPool.SetMaxThreads(1, 1);
Parallel.ForEach(Sectors, (sec) => sec.ParseNodes());
Parallel.ForEach(Sectors, (sec) => sec.ParseItems());
Loading = false;
// Now find all that were not ofund
ItemSearchRequests.Clear();
Console.WriteLine(ItemSearchRequests.Count +
" were not found; attempting to search them through all sectors");
foreach (var req in ItemSearchRequests)
{
Ets2Item item = Sectors.Select(sec => sec.FindItem(req.ItemUID)).FirstOrDefault(tmp => tmp != null);
if (item == null)
{
Console.WriteLine("Still couldn't find node " + req.ItemUID.ToString("X16"));
}
else
{
if (req.IsBackward)
{
item.Apply(req.Node);
req.Node.BackwardItem = item;
}
if (req.IsForward)
{
item.Apply(req.Node);
req.Node.ForwardItem = item;
}
if (item.StartNode == null && item.StartNodeUID != null)
{
Ets2Node startNode;
if (Nodes.TryGetValue(item.StartNodeUID, out startNode))
item.Apply(startNode);
}
if (item.EndNode == null && item.EndNodeUID != null)
{
Ets2Node endNode;
if (Nodes.TryGetValue(item.EndNodeUID, out endNode))
item.Apply(endNode);
}
Console.Write(".");
}
}
// Navigation cache
BuildNavigationCache();
// Lookup all cities
Cities = Items.Values.Where(x => x.Type == Ets2ItemType.City).GroupBy(x=>x.City).Select(x=>x.FirstOrDefault()).ToDictionary(x => x.City, x => x);
Console.WriteLine(Items.Values.Count(x => x.Type == Ets2ItemType.Building) + " buildings were found");
Console.WriteLine(Items.Values.Count(x => x.Type == Ets2ItemType.Road) + " roads were found");
Console.WriteLine(Items.Values.Count(x => x.Type == Ets2ItemType.Prefab) + " prefabs were found");
Console.WriteLine(Items.Values.Count(x => x.Type == Ets2ItemType.Prefab && x.Prefab != null && x.Prefab.Curves.Any()) + " road prefabs were found");
Console.WriteLine(Items.Values.Count(x => x.Type == Ets2ItemType.Service) + " service points were found");
Console.WriteLine(Items.Values.Count(x => x.Type == Ets2ItemType.Company) + " companies were found");
Console.WriteLine(Items.Values.Count(x => x.Type == Ets2ItemType.City) + " cities were found");
}