Ejemplo n.º 1
0
        private void storeLiveTimingConfig()
        {
            RaceConfiguration cfg = _thisRace.RaceConfiguration;

            StoreLiveTiming(ref cfg);
            _thisRace.RaceConfiguration = cfg;
        }
Ejemplo n.º 2
0
        private void BtnLTLogin_Click(object sender, RoutedEventArgs e)
        {
            storeLiveTimingConfig();
            RaceConfiguration cfg = _thisRace.RaceConfiguration;

            try
            {
                _liveTimingRM      = new LiveTimingRM();
                _liveTimingRM.Race = _thisRace;

                _liveTimingRM.Login(txtLTBewerb.Text, txtLTLogin.Text, txtLTPassword.Password);

                var events = _liveTimingRM.GetEvents();
                cmbLTEvent.ItemsSource = events;

                try
                {
                    SelectLiveTimingEvent(cfg.LivetimingParams["RM_EventName"]);
                }
                catch (KeyNotFoundException)
                {
                    cmbLTEvent.SelectedIndex = 0;
                }
            }
            catch (Exception error)
            {
                MessageBox.Show(error.Message, "Fehler", MessageBoxButton.OK, MessageBoxImage.Error);
                _liveTimingRM = null;
            }

            UpdateLiveTimingUI();
        }
Ejemplo n.º 3
0
        public void GlobalRaceConfig_SaveAndLoad()
        {
            string dbFilename = TestUtilities.CreateWorkingFileFrom(testContextInstance.TestDeploymentDir, @"TestDB_Empty.mdb");

            RaceHorologyLib.Database db = new RaceHorologyLib.Database();
            db.Connect(dbFilename);
            AppDataModel model = new AppDataModel(db);

            // Default Config
            Assert.AreEqual("Vereinsrennen - BestOfTwo", model.GlobalRaceConfig.Name);

            var testConfig1 = new RaceConfiguration
            {
                Name            = "BaseName",
                Runs            = 2,
                DefaultGrouping = "DefaultG",
                ActiveFields    = new List <string> {
                    "eins", "zwei"
                },
                RaceResultView       = "RaceResultView",
                RaceResultViewParams = new Dictionary <string, object>(),

                Run1_StartistView         = "Run1_StartistView",
                Run1_StartistViewGrouping = "Run1_StartistViewGrouping",
                Run1_StartistViewParams   = new Dictionary <string, object>(),

                Run2_StartistView         = "Run2_StartistView",
                Run2_StartistViewGrouping = "Run2_StartistViewGrouping",
                Run2_StartistViewParams   = new Dictionary <string, object>(),

                LivetimingParams = new Dictionary <string, string> {
                    { "key", "value" }
                },

                ValueF         = 100,
                ValueA         = 200,
                MinimumPenalty = 300
            };

            // Check for PropertyChanged event
            string propertyChanged = null;

            model.PropertyChanged += delegate(object sender, System.ComponentModel.PropertyChangedEventArgs e)
            {
                propertyChanged = e.PropertyName;
            };

            model.GlobalRaceConfig = testConfig1;
            Assert.AreEqual("GlobalRaceConfig", propertyChanged);

            TestUtilities.AreEqualByJson(testConfig1, model.GlobalRaceConfig);
            model.Close();

            // Check saving and loading from in DB
            RaceHorologyLib.Database db2 = new RaceHorologyLib.Database();
            db2.Connect(dbFilename);
            AppDataModel model2 = new AppDataModel(db2);

            TestUtilities.AreEqualByJson(testConfig1, model2.GlobalRaceConfig);
        }
        private void startLiveTiming()
        {
            storeLiveTimingConfig();

            RaceConfiguration cfg = _thisRace.RaceConfiguration;

            if (_liveTimingFIS != null) // Might be a zombie from a failed connection
            {
                stopLiveTiming();
            }

            _stopRequested = false;
            _liveTimingFIS = new LiveTimingFIS.LiveTimingFIS();

            try
            {
                _liveTimingFIS.Race           = _thisRace;
                _liveTimingFIS.StatusChanged += liveTimingFIS_StatusChanged;
                _liveTimingFIS.Connect(int.Parse(cfg.LivetimingParams["FIS_Port"]));
                _liveTimingFIS.Login(cfg.LivetimingParams["FIS_RaceCode"], cfg.LivetimingParams["FIS_Category"], cfg.LivetimingParams["FIS_Pasword"]);
                _liveTimingFIS.Start();
            }
            catch (Exception error)
            {
                MessageBox.Show(error.Message, "Fehler", MessageBoxButton.OK, MessageBoxImage.Error);
                _liveTimingFIS = null;
            }
        }
Ejemplo n.º 5
0
        private void BtnLTStart_Click(object sender, RoutedEventArgs e)
        {
            if (_liveTimingRM == null)
            {
                return;
            }


            if (_liveTimingRM.Started)
            {
                _liveTimingRM.Stop();
            }
            else
            {
                // Start
                if (cmbLTEvent.SelectedIndex < 0)
                {
                    MessageBox.Show("Bitte Veranstalltung auswählen", "Live Timing", MessageBoxButton.OK, MessageBoxImage.Error);
                }
                else
                {
                    storeLiveTimingConfig();
                    RaceConfiguration cfg = _thisRace.RaceConfiguration;

                    _liveTimingRM.SetEvent(cmbLTEvent.SelectedIndex);
                    _liveTimingRM.Start();
                }
            }

            UpdateLiveTimingUI();
        }
        private void globalConfig_SaveChanges()
        {
            RaceConfiguration cfg = ucRaceConfig.GetConfig();

            _dm.GlobalRaceConfig = cfg;

            ucRaceConfig.Init(_dm.GlobalRaceConfig);
        }
        public RaceConfiguration GetConfig()
        {
            RaceConfiguration cfg = new RaceConfiguration();

            StoreConfigurationSelectionUI(ref cfg);

            return(cfg);
        }
        public bool ExistingChanges()
        {
            RaceConfiguration cfgTemp = new RaceConfiguration();

            StoreConfigurationSelectionUI(ref cfgTemp);

            return(!RaceConfigurationCompare.MainConfig(_raceConfiguration, cfgTemp));
        }
        private void StoreLiveTiming(ref RaceConfiguration cfg)
        {
            if (cfg.LivetimingParams == null)
            {
                cfg.LivetimingParams = new Dictionary <string, string>();
            }

            cfg.LivetimingParams["FIS_RaceCode"] = txtRaceCode.Text;
            cfg.LivetimingParams["FIS_Category"] = txtCategory.Text;
            cfg.LivetimingParams["FIS_Pasword"]  = txtPassword.Password;
            cfg.LivetimingParams["FIS_Port"]     = txtPort.Text;
        }
Ejemplo n.º 10
0
        private void StoreLiveTiming(ref RaceConfiguration cfg)
        {
            if (cfg.LivetimingParams == null)
            {
                cfg.LivetimingParams = new Dictionary <string, string>();
            }

            cfg.LivetimingParams["RM_Bewerb"]    = txtLTBewerb.Text;
            cfg.LivetimingParams["RM_Login"]     = txtLTLogin.Text;
            cfg.LivetimingParams["RM_Password"]  = txtLTPassword.Password;
            cfg.LivetimingParams["RM_EventName"] = cmbLTEvent.SelectedItem?.ToString();
        }
        private void CmbTemplate_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (cmbTemplate.SelectedValue is CBItem selected)
            {
                if (selected.Value is string configName)
                {
                    RaceConfiguration config      = _raceConfigurationPresets.GetConfiguration(configName);
                    RaceConfiguration configToSet = RaceConfigurationMerger.MainConfig(_raceConfiguration, config);

                    ResetConfigurationSelectionUI(configToSet);
                }
            }
        }
Ejemplo n.º 12
0
        private void ResetLiveTimningUI(RaceConfiguration cfg)
        {
            if (cfg.LivetimingParams == null)
            {
                return;
            }

            try
            {
                txtLTBewerb.Text       = cfg.LivetimingParams["RM_Bewerb"];
                txtLTLogin.Text        = cfg.LivetimingParams["RM_Login"];
                txtLTPassword.Password = cfg.LivetimingParams["RM_Password"];
            }
            catch (KeyNotFoundException) { }
        }
        private void ResetLiveTimningUI(RaceConfiguration cfg)
        {
            if (cfg.LivetimingParams == null)
            {
                return;
            }

            try
            {
                txtRaceCode.Text     = cfg.LivetimingParams["FIS_RaceCode"];
                txtCategory.Text     = cfg.LivetimingParams["FIS_Category"];
                txtPassword.Password = cfg.LivetimingParams["FIS_Pasword"];
                txtPort.Text         = cfg.LivetimingParams["FIS_Port"];
            }
            catch (KeyNotFoundException) { }
        }
        private void ResetConfigurationSelectionUI(RaceConfiguration cfg)
        {
            cmbRuns.SelectCBItem(cfg.Runs);
            cmbConfigErgebnisGrouping.SelectCBItem(cfg.DefaultGrouping);
            cmbConfigErgebnis.SelectCBItem(cfg.RaceResultView);
            cmbConfigStartlist1.SelectCBItem(cfg.Run1_StartistView);
            cmbConfigStartlist1Grouping.SelectCBItem(cfg.Run1_StartistViewGrouping);
            cmbConfigStartlist2.SelectCBItem(cfg.Run2_StartistView);
            cmbConfigStartlist2Grouping.SelectCBItem(cfg.Run2_StartistViewGrouping);
            txtValueF.Text      = cfg.ValueF.ToString();
            txtValueA.Text      = cfg.ValueA.ToString();
            txtMinPenalty.Text  = cfg.MinimumPenalty.ToString();
            txtValueCutOff.Text = cfg.ValueCutOff.ToString();

            chkConfigFieldsYear.IsChecked       = cfg.ActiveFields.Contains("Year");
            chkConfigFieldsClub.IsChecked       = cfg.ActiveFields.Contains("Club");
            chkConfigFieldsNation.IsChecked     = cfg.ActiveFields.Contains("Nation");
            chkConfigFieldsCode.IsChecked       = cfg.ActiveFields.Contains("Code");
            chkConfigFieldsPoints.IsChecked     = cfg.ActiveFields.Contains("Points");
            chkConfigFieldsPercentage.IsChecked = cfg.ActiveFields.Contains("Percentage");
        }
Ejemplo n.º 15
0
        public void GlobalRaceConfig_InheritToRace()
        {
            TestDataGenerator tg = new TestDataGenerator();
            var model            = tg.Model;

            var testConfig1 = new RaceConfiguration
            {
                Name            = "BaseName",
                Runs            = 2,
                DefaultGrouping = "DefaultG",
                ActiveFields    = new List <string> {
                    "eins", "zwei"
                },
                RaceResultView       = "RaceResultView",
                RaceResultViewParams = new Dictionary <string, object>(),

                Run1_StartistView         = "Run1_StartistView",
                Run1_StartistViewGrouping = "Run1_StartistViewGrouping",
                Run1_StartistViewParams   = new Dictionary <string, object>(),

                Run2_StartistView         = "Run2_StartistView",
                Run2_StartistViewGrouping = "Run2_StartistViewGrouping",
                Run2_StartistViewParams   = new Dictionary <string, object>(),

                LivetimingParams = new Dictionary <string, string> {
                    { "key", "value" }
                },

                ValueF         = 100,
                ValueA         = 200,
                MinimumPenalty = 300
            };

            model.GlobalRaceConfig = testConfig1;

            TestUtilities.AreEqualByJson(testConfig1, model.GlobalRaceConfig);
            TestUtilities.AreEqualByJson(testConfig1, model.GetRace(0).RaceConfiguration);
        }
Ejemplo n.º 16
0
        public void RaceConfigurationPresets_Test()
        {
            RaceConfigurationPresets cfgPresets = new RaceConfigurationPresets(".");

            var configs = cfgPresets.GetConfigurations();

            Assert.AreEqual(2, configs.Count);
            Assert.IsTrue(configs.ContainsKey("DSV Erwachsene"));
            Assert.IsTrue(configs.ContainsKey("FIS Rennen Men"));

            // Create new Config
            var newConfig = new RaceConfiguration(configs["FIS Rennen Men"]);

            newConfig.Runs = 3;
            cfgPresets.SaveConfiguration("FIS Rennen - neu", newConfig);
            Assert.AreEqual(3, configs.Count);
            Assert.IsTrue(configs.ContainsKey("DSV Erwachsene"));
            Assert.IsTrue(configs.ContainsKey("FIS Rennen Men"));
            Assert.IsTrue(configs.ContainsKey("FIS Rennen - neu"));

            // Delete a config
            cfgPresets.DeleteConfiguration("FIS Rennen Men");
            Assert.AreEqual(2, configs.Count);
            Assert.IsTrue(configs.ContainsKey("DSV Erwachsene"));
            Assert.IsTrue(configs.ContainsKey("FIS Rennen - neu"));
            Assert.AreEqual(3, cfgPresets.GetConfigurations()["FIS Rennen - neu"].Runs);

            // Create new Config with unsafe name
            var newConfig2 = new RaceConfiguration(configs["DSV Erwachsene"]);

            newConfig.Runs = 3;
            cfgPresets.SaveConfiguration(@"abc\*:;? 123", newConfig);
            Assert.AreEqual(3, configs.Count);
            Assert.IsTrue(configs.ContainsKey("DSV Erwachsene"));
            Assert.IsTrue(configs.ContainsKey(@"abc; 123"));
            Assert.IsTrue(configs.ContainsKey("FIS Rennen - neu"));
        }
        private void btnTemplateSave_Click(object sender, RoutedEventArgs e)
        {
            RaceConfiguration newConfig = new RaceConfiguration();

            StoreConfigurationSelectionUI(ref newConfig);

            // Ask for the name to store
            string configName = string.Empty;

            if (cmbTemplate.SelectedValue is CBItem selected && selected.Value is string selConfigName)
            {
                configName = selConfigName;
            }

            RaceConfigurationSaveDlg dlg = new RaceConfigurationSaveDlg(configName);

            dlg.ShowDialog();
            if (dlg.TemplateName == null)
            {
                return;
            }

            configName = dlg.TemplateName;

            if (_raceConfigurationPresets.GetConfigurations().ContainsKey(configName))
            {
                var res = MessageBox.Show(string.Format("Die Konfiguration \"{0}\" existiert schon. Wollen Sie die Konfiguration überschreiben?", configName), "Konfiguration speichern", MessageBoxButton.YesNo, MessageBoxImage.Question);
                if (res == MessageBoxResult.No)
                {
                    return;
                }
            }

            _raceConfigurationPresets.SaveConfiguration(configName, newConfig);
            refreshConfigPresetsUI();
        }
Ejemplo n.º 18
0
        public void RaceConfigurationCompare_MainConfig()
        {
            RaceConfiguration config1 = new RaceConfiguration
            {
                Name            = "BaseName",
                Runs            = 2,
                DefaultGrouping = "DefaultG",
                ActiveFields    = new List <string> {
                    "eins", "zwei"
                },
                RaceResultView       = "RaceResultView",
                RaceResultViewParams = new Dictionary <string, object>(),

                Run1_StartistView         = "Run1_StartistView",
                Run1_StartistViewGrouping = "Run1_StartistViewGrouping",
                Run1_StartistViewParams   = new Dictionary <string, object>(),

                Run2_StartistView         = "Run2_StartistView",
                Run2_StartistViewGrouping = "Run2_StartistViewGrouping",
                Run2_StartistViewParams   = new Dictionary <string, object>(),

                LivetimingParams = new Dictionary <string, string> {
                    { "key", "value" }
                },

                ValueF         = 100,
                ValueA         = 200,
                MinimumPenalty = 300
            };

            RaceConfiguration config2 = new RaceConfiguration(config1);

            Assert.IsTrue(RaceConfigurationCompare.MainConfig(config1, config2));
            config1.Runs = 3;
            Assert.IsFalse(RaceConfigurationCompare.MainConfig(config1, config2));
            config1.Runs = 2;
            Assert.IsTrue(RaceConfigurationCompare.MainConfig(config1, config2));
            config2.DefaultGrouping = "DefaultC";
            Assert.IsFalse(RaceConfigurationCompare.MainConfig(config1, config2));
            config2.DefaultGrouping = "DefaultG";
            Assert.IsTrue(RaceConfigurationCompare.MainConfig(config1, config2));

            config2.ActiveFields = new List <string> {
                "eins"
            };
            Assert.IsFalse(RaceConfigurationCompare.MainConfig(config1, config2));
            config2.ActiveFields = new List <string> {
                "eins", "zwei"
            };
            Assert.IsTrue(RaceConfigurationCompare.MainConfig(config1, config2));
            config1.ActiveFields = new List <string> {
                "eins"
            };
            Assert.IsFalse(RaceConfigurationCompare.MainConfig(config1, config2));
            config1.ActiveFields = new List <string> {
                "eins", "zwei"
            };
            Assert.IsTrue(RaceConfigurationCompare.MainConfig(config1, config2));

            config1.RaceResultView = "RaceResultView1";
            Assert.IsFalse(RaceConfigurationCompare.MainConfig(config1, config2));
            config1.RaceResultView = "RaceResultView";
            Assert.IsTrue(RaceConfigurationCompare.MainConfig(config1, config2));
        }
Ejemplo n.º 19
0
        private void configuration_SaveChanges()
        {
            RaceConfiguration cfg = new RaceConfiguration();

            _thisRace.RaceConfiguration = ucRaceConfig.GetConfig();
        }
        public void Init(RaceConfiguration raceConfig)
        {
            // ApplicationFolder + raceconfigpresets
            _raceConfigurationPresets = new RaceConfigurationPresets(System.IO.Path.Combine(System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location), @"raceconfigpresets"));
            _raceConfiguration        = raceConfig.Copy();

            refreshConfigPresetsUI();

            // Configuration Screen
            cmbRuns.Items.Clear();
            cmbRuns.Items.Add(new CBItem {
                Text = "1", Value = 1
            });
            cmbRuns.Items.Add(new CBItem {
                Text = "2", Value = 2
            });
            cmbRuns.Items.Add(new CBItem {
                Text = "3", Value = 3
            });
            cmbRuns.Items.Add(new CBItem {
                Text = "4", Value = 4
            });
            cmbRuns.Items.Add(new CBItem {
                Text = "5", Value = 5
            });
            cmbRuns.Items.Add(new CBItem {
                Text = "6", Value = 6
            });

            // Result
            UiUtilities.FillGrouping(cmbConfigErgebnisGrouping);

            cmbConfigErgebnis.Items.Clear();
            cmbConfigErgebnis.Items.Add(new CBItem {
                Text = "Bester Durchgang", Value = "RaceResult_BestOfTwo"
            });
            cmbConfigErgebnis.Items.Add(new CBItem {
                Text = "Summe der besten 2 Durchgänge", Value = "RaceResult_SumBest2"
            });
            cmbConfigErgebnis.Items.Add(new CBItem {
                Text = "Summe", Value = "RaceResult_Sum"
            });
            cmbConfigErgebnis.Items.Add(new CBItem {
                Text = "Summe + Punkte nach DSV Schülerreglement", Value = "RaceResult_SumDSVPointsSchool"
            });

            // Run 1
            UiUtilities.FillGrouping(cmbConfigStartlist1Grouping);
            cmbConfigStartlist1.Items.Clear();
            cmbConfigStartlist1.Items.Add(new CBItem {
                Text = "Startnummer (aufsteigend)", Value = "Startlist_1stRun_StartnumberAscending"
            });
            cmbConfigStartlist1.Items.Add(new CBItem {
                Text = "Punkte (nicht gelost)", Value = "Startlist_1stRun_Points_0"
            });
            cmbConfigStartlist1.Items.Add(new CBItem {
                Text = "Punkte (ersten 15 gelost)", Value = "Startlist_1stRun_Points_15"
            });
            cmbConfigStartlist1.Items.Add(new CBItem {
                Text = "Punkte (ersten 30 gelost)", Value = "Startlist_1stRun_Points_30"
            });

            // Run 2
            UiUtilities.FillGrouping(cmbConfigStartlist2Grouping);
            cmbConfigStartlist2.Items.Clear();
            cmbConfigStartlist2.Items.Add(new CBItem {
                Text = "Startnummer (aufsteigend)", Value = "Startlist_2nd_StartnumberAscending"
            });
            //cmbConfigStartlist2.Items.Add(new GroupingCBItem { Text = "Startnummer (aufsteigend, inkl. ohne Ergebnis)", Value = "Startlist_2nd_StartnumberAscending" });
            cmbConfigStartlist2.Items.Add(new CBItem {
                Text = "Startnummer (absteigend)", Value = "Startlist_2nd_StartnumberDescending"
            });
            //cmbConfigStartlist2.Items.Add(new GroupingCBItem { Text = "Startnummer (absteigend, inkl. ohne Ergebnis)", Value = "Startlist_2nd_StartnumberDescending" });
            cmbConfigStartlist2.Items.Add(new CBItem {
                Text = "Vorheriger Lauf nach Zeit (nicht gedreht)", Value = "Startlist_2nd_PreviousRun_0_OnlyWithResults"
            });
            cmbConfigStartlist2.Items.Add(new CBItem {
                Text = "Vorheriger Lauf nach Zeit (nicht gedreht, inkl. ohne Ergebnis)", Value = "Startlist_2nd_PreviousRun_0_AlsoWithoutResults"
            });
            cmbConfigStartlist2.Items.Add(new CBItem {
                Text = "Vorheriger Lauf nach Zeit (ersten 15 gedreht)", Value = "Startlist_2nd_PreviousRun_15_OnlyWithResults"
            });
            cmbConfigStartlist2.Items.Add(new CBItem {
                Text = "Vorheriger Lauf nach Zeit (ersten 15 gedreht, inkl. ohne Ergebnis)", Value = "Startlist_2nd_PreviousRun_15_AlsoWithoutResults"
            });
            cmbConfigStartlist2.Items.Add(new CBItem {
                Text = "Vorheriger Lauf nach Zeit (ersten 30 gedreht)", Value = "Startlist_2nd_PreviousRun_30_OnlyWithResults"
            });
            cmbConfigStartlist2.Items.Add(new CBItem {
                Text = "Vorheriger Lauf nach Zeit (ersten 30 gedreht, inkl. ohne Ergebnis)", Value = "Startlist_2nd_PreviousRun_30_AlsoWithoutResults"
            });
            cmbConfigStartlist2.Items.Add(new CBItem {
                Text = "Vorheriger Lauf nach Zeit (alle gedreht)", Value = "Startlist_2nd_PreviousRun_all_OnlyWithResults"
            });
            cmbConfigStartlist2.Items.Add(new CBItem {
                Text = "Vorheriger Lauf nach Zeit (alle gedreht, inkl. ohne Ergebnis)", Value = "Startlist_2nd_PreviousRun_all_AlsoWithoutResults"
            });

            ResetConfigurationSelectionUI(_raceConfiguration);
        }
        private bool StoreConfigurationSelectionUI(ref RaceConfiguration cfg)
        {
            // Store the template name
            string configName = null;

            if (cmbTemplate.SelectedValue is CBItem selected && selected.Value is string selConfigName)
            {
                configName = selConfigName;
            }
            cfg.Name = configName;

            var presetConfig = _raceConfigurationPresets.GetConfiguration(configName);

            if (presetConfig != null)
            {
                cfg.InternalDSVAlpinCompetitionTypeWrite = presetConfig.InternalDSVAlpinCompetitionTypeWrite;
            }

            if (cmbRuns.SelectedIndex >= 0)
            {
                cfg.Runs = (int)((CBItem)cmbRuns.SelectedValue).Value;
            }

            if (cmbConfigErgebnisGrouping.SelectedIndex >= 0)
            {
                cfg.DefaultGrouping = (string)((CBItem)cmbConfigErgebnisGrouping.SelectedValue).Value;
            }

            if (cmbConfigErgebnis.SelectedIndex >= 0)
            {
                cfg.RaceResultView = (string)((CBItem)cmbConfigErgebnis.SelectedValue).Value;
            }

            if (cmbConfigStartlist1.SelectedIndex >= 0)
            {
                cfg.Run1_StartistView = (string)((CBItem)cmbConfigStartlist1.SelectedValue).Value;
            }

            if (cmbConfigStartlist1Grouping.SelectedIndex >= 0)
            {
                cfg.Run1_StartistViewGrouping = (string)((CBItem)cmbConfigStartlist1Grouping.SelectedValue).Value;
            }

            if (cmbConfigStartlist2.SelectedIndex >= 0)
            {
                cfg.Run2_StartistView = (string)((CBItem)cmbConfigStartlist2.SelectedValue).Value;
            }

            if (cmbConfigStartlist2Grouping.SelectedIndex >= 0)
            {
                cfg.Run2_StartistViewGrouping = (string)((CBItem)cmbConfigStartlist2Grouping.SelectedValue).Value;
            }

            try { cfg.ValueF = double.Parse(txtValueF.Text); } catch (Exception) { }
            try { cfg.ValueA = double.Parse(txtValueA.Text); } catch (Exception) { }
            try { cfg.MinimumPenalty = double.Parse(txtMinPenalty.Text); } catch (Exception) { }
            try { cfg.ValueCutOff = double.Parse(txtValueCutOff.Text); } catch (Exception) { }

            void enableField(List <string> fieldList, string field, bool?enabled)
            {
                if (enabled != null && (bool)enabled)
                {
                    if (!fieldList.Contains(field))
                    {
                        fieldList.Add(field);
                    }
                }
                else
                {
                    if (fieldList.Contains(field))
                    {
                        fieldList.Remove(field);
                    }
                }
            }

            enableField(cfg.ActiveFields, "Year", chkConfigFieldsYear.IsChecked);
            enableField(cfg.ActiveFields, "Club", chkConfigFieldsClub.IsChecked);
            enableField(cfg.ActiveFields, "Nation", chkConfigFieldsNation.IsChecked);
            enableField(cfg.ActiveFields, "Code", chkConfigFieldsCode.IsChecked);
            enableField(cfg.ActiveFields, "Points", chkConfigFieldsPoints.IsChecked);
            enableField(cfg.ActiveFields, "Percentage", chkConfigFieldsPercentage.IsChecked);

            return(true);
        }
Ejemplo n.º 22
0
 public void ConfigureRace(RaceConfiguration config)
 {
     StartCoroutine(ConfigureRaceWorker(config));
 }
Ejemplo n.º 23
0
    private IEnumerator ConfigureRaceWorker(RaceConfiguration config)
    {
        stage = RaceStage.Preparation;

        var operation = SceneManager.LoadSceneAsync(config.circuit.sceneName, LoadSceneMode.Additive);

        while (!operation.isDone)
        {
            yield return(null);
        }

        SceneManager.SetActiveScene(SceneManager.GetSceneByName(config.circuit.sceneName));

        var scene    = SceneManager.GetSceneByName(config.circuit.sceneName);
        var track    = scene.GetRootGameObjects().Select(g => g.GetComponentInChildren <Track>()).Where(o => o != null).First();
        var geometry = track.GetComponent <TrackGeometry>();

        var cars = config.cars;

        competitors = new List <Competitor>();
        laps        = config.laps;

        int i = 0;

        for (; i < cars.Count; i++)
        {
            var item = cars[i];
            var car  = GameObject.Instantiate(item.Agent, geometry.transform);
            ResetController.PlacePrefab(car.transform, geometry, GridStartDistance(i), GridStartOffset(i));
            competitors.Add(new Competitor(car));
        }

        if (config.player != null)
        {
            var player = GameObject.Instantiate(config.player.Player, geometry.transform);
            ResetController.PlacePrefab(player.transform, geometry, GridStartDistance(i), GridStartOffset(i));
            this.player = new Competitor(player);
            competitors.Add(this.player);
        }

        foreach (var item in competitors)
        {
            item.navigator.Lap = 0;
        }

        config.leaderboard.Clear();
        foreach (var item in competitors)
        {
            var entry = new LeaderboardEntry();
            entry.car     = item.vehicle.name;
            entry.bestLap = float.PositiveInfinity;
            entry.place   = competitors.IndexOf(item) + 1;

            if (item.vehicle.GetComponent <Agent>())
            {
                entry.driver = item.vehicle.GetComponent <Agent>().DriverName;
            }
            else
            {
                entry.driver = "Player 1";
            }

            config.leaderboard.Add(entry);
            item.entry = entry;
        }

        raceCamera.cameraRigs = competitors.Select(c => c.vehicle.GetComponentInChildren <CamRig>()).ToArray();
        raceCamera.Target     = competitors.Last().vehicle.GetComponent <CamRig>();

        SendMessage("OnRacePrepared", this, SendMessageOptions.DontRequireReceiver);

        StartCoroutine(CountdownWorker());
    }
Ejemplo n.º 24
0
        public void RaceConfigurationMerger_MainConfig()
        {
            RaceConfiguration baseConfig = new RaceConfiguration
            {
                Name            = "BaseName",
                Runs            = 2,
                DefaultGrouping = "DefaultG",
                ActiveFields    = new List <string> {
                    "eins", "zwei"
                },
                RaceResultView       = "RaceResultView",
                RaceResultViewParams = new Dictionary <string, object>(),

                Run1_StartistView         = "Run1_StartistView",
                Run1_StartistViewGrouping = "Run1_StartistViewGrouping",
                Run1_StartistViewParams   = new Dictionary <string, object>(),

                Run2_StartistView         = "Run2_StartistView",
                Run2_StartistViewGrouping = "Run2_StartistViewGrouping",
                Run2_StartistViewParams   = new Dictionary <string, object>(),

                LivetimingParams = new Dictionary <string, string> {
                    { "key", "value" }
                },

                ValueF         = 100,
                ValueA         = 200,
                MinimumPenalty = 300
            };

            RaceConfiguration newConfig = new RaceConfiguration
            {
                Name            = "NewName",
                Runs            = 3,
                DefaultGrouping = "DefaultH",
                ActiveFields    = new List <string> {
                    "drei", "view"
                },
                RaceResultView       = "RaceResultView2",
                RaceResultViewParams = new Dictionary <string, object>(),

                Run1_StartistView         = "Run1_StartistView2",
                Run1_StartistViewGrouping = "Run1_StartistViewGrouping2",
                Run1_StartistViewParams   = new Dictionary <string, object>(),

                Run2_StartistView         = "Run2_StartistView2",
                Run2_StartistViewGrouping = "Run2_StartistViewGrouping2",
                Run2_StartistViewParams   = new Dictionary <string, object>(),

                LivetimingParams = new Dictionary <string, string> {
                    { "key2", "value2" }
                },

                ValueF         = 200,
                ValueA         = 300,
                MinimumPenalty = 400
            };


            RaceConfiguration mergedConfig = RaceConfigurationMerger.MainConfig(baseConfig, newConfig);

            Assert.AreEqual("NewName", mergedConfig.Name);

            Assert.AreEqual("DefaultH", mergedConfig.DefaultGrouping);
            Assert.AreEqual("drei", mergedConfig.ActiveFields[0]);
            Assert.AreEqual("view", mergedConfig.ActiveFields[1]);
            Assert.AreEqual("RaceResultView2", mergedConfig.RaceResultView);
            Assert.AreEqual(0, mergedConfig.RaceResultViewParams.Count);

            Assert.AreEqual("Run1_StartistView2", mergedConfig.Run1_StartistView);
            Assert.AreEqual("Run1_StartistViewGrouping2", mergedConfig.Run1_StartistViewGrouping);
            Assert.AreEqual(0, mergedConfig.Run1_StartistViewParams.Count);
            Assert.AreEqual("Run2_StartistView2", mergedConfig.Run2_StartistView);
            Assert.AreEqual("Run2_StartistViewGrouping2", mergedConfig.Run2_StartistViewGrouping);
            Assert.AreEqual(0, mergedConfig.Run2_StartistViewParams.Count);

            // After this line, there must be the old values
            Assert.AreEqual(1, mergedConfig.LivetimingParams.Count);
            Assert.AreEqual("value", mergedConfig.LivetimingParams["key"]);
            Assert.AreEqual(100, mergedConfig.ValueF);
            Assert.AreEqual(200, mergedConfig.ValueA);
            Assert.AreEqual(300, mergedConfig.MinimumPenalty);
        }