SimShift.MapTool.Ets2Mapper.Parse C# (CSharp) 메소드

Parse() 공개 메소드

public Parse ( ) : void
리턴 void
        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");
        }

Usage Example

예제 #1
0
파일: FrmMain.cs 프로젝트: nlhans/SimShift
        public FrmMain()
        {
            var map = "europe.ets2";
            var universalFolder = Directory.Exists(@"E:\map\" + map + "\\")
                ? @"E:\map\" + map + "\\"
                : Directory.Exists(@"E:\Games\Steam\steamapps\common\Euro Truck Simulator 2\base\map")
                    ? @"E:\Games\Steam\steamapps\common\Euro Truck Simulator 2\base\map\" + map + "\\"
                    : @"./europe/";

            var prefabs = @"E:\Mods\ETS2\data 1.19\base\prefab\";

            Ets2Map = new Ets2Mapper(universalFolder, prefabs, @"C:\Projects\Software\SimShift\Resources\LUT1.19");
            Ets2Map.Parse();
            Main.SetMap(Ets2Map);

            //SimulationEnvironment sim = new SimulationEnvironment();
            InitializeComponent();

            this.StartPosition = FormStartPosition.Manual;
            this.Location = new Point(0,0);

            btServiceStartStop_Click(null, null);

            gbCarSelect.Enabled = false;

            updateModules = new Timer();
            updateModules.Interval = 25;
            updateModules.Tick += updateModules_Tick;
            updateModules.Start();
        }