Exemplo n.º 1
0
            private void LoadRaceGrid()
            {
                try {
                    if (SelectedObject.SerializedRaceGridData != null)
                    {
                        RaceGridViewModel.ImportFromPresetData(SelectedObject.SerializedRaceGridData);
                    }
                    else
                    {
                        RaceGridViewModel.LoadingFromOutside = true;

                        var list = SelectedObject.Drivers;
                        RaceGridViewModel.NonfilteredList.Clear();
                        RaceGridViewModel.Mode = BuiltInGridMode.Custom;
                        RaceGridViewModel.ShuffleCandidates = false;

                        RaceGridViewModel.AiLevelArrangeRandom     = 0;
                        RaceGridViewModel.AiLevelArrangeReverse    = false;
                        RaceGridViewModel.AiLevelArrangePowerRatio = false;
                        RaceGridViewModel.AiLevel    = 100;
                        RaceGridViewModel.AiLevelMin = 100;

                        foreach (var driver in list)
                        {
                            if (driver.CarId == null)
                            {
                                continue;
                            }

                            var car = CarsManager.Instance.GetById(driver.CarId);
                            if (car == null)
                            {
                                SelectedObject.AddError(AcErrorType.Data_UserChampionshipCarIsMissing, driver.CarId);
                                continue;
                            }

                            var skin = driver.SkinId == null ? null : car.GetSkinById(driver.SkinId);
                            if (skin == null)
                            {
                                SelectedObject.AddError(AcErrorType.Data_UserChampionshipCarSkinIsMissing, driver.CarId, driver.SkinId);
                            }

                            if (!driver.IsPlayer)
                            {
                                RaceGridViewModel.NonfilteredList.Add(new RaceGridEntry(car)
                                {
                                    CarSkin = skin,
                                    Name    = driver.Name
                                });
                            }
                        }

                        RaceGridViewModel.OpponentsNumber  = RaceGridViewModel.NonfilteredList.Count;
                        RaceGridViewModel.StartingPosition = 0;
                        RaceGridViewModel.FinishLoading();
                    }

                    // TODO: Several cars
                    RaceGridViewModel.PlayerCar       = SelectedObject.MainPlayerCarEntry?.Car;
                    RaceGridViewModel.TrackPitsNumber = SelectedObject.MaxCars;
                } finally {
                    RaceGridViewModel.LoadingFromOutside = false;
                }
            }