RemoteTech.Settings.LoadPreset C# (CSharp) Méthode

LoadPreset() public static méthode

Load a preset configuration into the RemoteTech settings object.
public static LoadPreset ( Settings previousSettings, string presetCfgUrl ) : Settings
previousSettings Settings
presetCfgUrl string
Résultat Settings
        public static Settings LoadPreset(Settings previousSettings, string presetCfgUrl)
        {
            var newPreSetSettings = new Settings();
            var successLoadPreSet = false;

            // Exploit KSP's GameDatabase to find third-party mods' RemoteTechSetting node (from GameData/ExampleMod/RemoteTechSettings.cfg)
            var rtSettingCfGs = GameDatabase.Instance.GetConfigs("RemoteTechSettings");
            for(var i = 0; i < rtSettingCfGs.Length; i++)
            {
                var rtSettingCfg = rtSettingCfGs[i];

                if (!rtSettingCfg.url.Equals(presetCfgUrl))
                    continue;

                // Preserve important information of RT, such as the single ID
                var importantInfoNode = new ConfigNode();
                importantInfoNode.AddValue("MapFilter", previousSettings.MapFilter);
                importantInfoNode.AddValue("ActiveVesselGuid", previousSettings.ActiveVesselGuid);
                importantInfoNode.AddValue("NoTargetGuid", previousSettings.NoTargetGuid);

                successLoadPreSet = ConfigNode.LoadObjectFromConfig(newPreSetSettings, rtSettingCfg.config);
                RTLog.Notify("Load the preset cfg into object with {0}: LOADED {1}", newPreSetSettings, successLoadPreSet ? "OK" : "FAIL");

                // Restore backups
                ConfigNode.LoadObjectFromConfig(newPreSetSettings, importantInfoNode);
                break;
            }

            return successLoadPreSet?newPreSetSettings: previousSettings;
        }

Usage Example

Exemple #1
0
 /// <summary>
 /// Replace the given settings with a new Settings object of the given setting preset, and save it
 /// </summary>
 public static void ReloadSettings(Settings previousSettings, string presetCfgUrl)
 {
     _instance = Settings.LoadPreset(previousSettings, presetCfgUrl);
     _instance.Save();
 }
All Usage Examples Of RemoteTech.Settings::LoadPreset