/* Important Note about how modules are loaded and saved and why this kludge exists. * Each part.cfg file contains a list of modules defined by MODULE config nodes. * When a part is first loaded upon startup, KSP looks through each MODULE config node and * uses it to instantiate the corresponding PartModule-derived object. * For instance, if your part file has an MKSModule, then KSP will instantiate an MKSModule object for you. * * When a part is saved into a craft file or a savegame file, KSP searches through a part's * list of modules and tells them to save their data into the provided ConfigNode object. * If we add new modules at runtime, they too will be saved into the craft file/savegame file. * * When a craft file/savegame file is loaded, KSP goes through all the modules listed in the part * and tries to instantiate them. Therein lies the problem. If we added modules at runtime, and * they are not part of the original part's part.cfg file, then KSP skips the module data. This is * bad because you lose all of your persistent data. Adding KolonyConverter modules at runtime is * no exception. Fortunately, we have a workaround. * * When MKSModuleSwitcher is loaded and saved, we have access to its ConfigNode object. By calling * SaveToNode for each KolonyConverter that we created at runtime, we can pass in that ConfigNode object * and save the KolonyConverter's persistent data into MKSModuleSwitcher's node. That way, * persistent data such as the enabled/disabled status and last updated time are all preserved. * */ public void SaveToNode(KolonyConverter converter, ConfigNode node) { //We'll get the private fields saved this way converter.Save(node); node.AddValue("converterName", converter.converterName); node.AddValue("conversionRate", converter.conversionRate); node.AddValue("inputResources", converter.inputResources); node.AddValue("outputResources", converter.outputResources); node.AddValue("requiredResources", converter.requiredResources); node.AddValue("SurfaceOnly", converter.SurfaceOnly); node.AddValue("converterEnabled", converter.converterEnabled); node.AddValue("alwaysOn", converter.alwaysOn); node.AddValue("requiresOxygenAtmo", converter.requiresOxygenAtmo); node.AddValue("shutdownIfAllOutputFull", converter.shutdownIfAllOutputFull); node.AddValue("showRemainingTime", converter.showRemainingTime); }
public PartModule AddFromTemplate(ConfigNode node) { Log("AddFromTemplate called"); KolonyConverter converter = (KolonyConverter)this.part.AddModule(node); //Remove the converter's GUI converter.ShowGUI(_showGUI); //Add it to the list this.converters.Add(converter); return(converter); }
public void LoadFromNode(KolonyConverter converter, ConfigNode node) { string value; try { //This will load our private fields converter.Load(node); //Set its parameters value = node.GetValue("converterName"); if (!string.IsNullOrEmpty(value)) { converter.converterName = value; } value = node.GetValue("conversionRate"); if (!string.IsNullOrEmpty(value)) { converter.conversionRate = float.Parse(value); } value = node.GetValue("inputResources"); if (!string.IsNullOrEmpty(value)) { converter.inputResources = value; } value = node.GetValue("outputResources"); if (!string.IsNullOrEmpty(value)) { converter.outputResources = value; } value = node.GetValue("requiredResources"); if (!string.IsNullOrEmpty(value)) { converter.requiredResources = value; } value = node.GetValue("SurfaceOnly"); if (!string.IsNullOrEmpty(value)) { converter.SurfaceOnly = bool.Parse(value); } value = node.GetValue("converterEnabled"); if (!string.IsNullOrEmpty(value)) { converter.converterEnabled = bool.Parse(value); } value = node.GetValue("alwaysOn"); if (!string.IsNullOrEmpty(value)) { converter.alwaysOn = bool.Parse(value); } value = node.GetValue("requiresOxygenAtmo"); if (!string.IsNullOrEmpty(value)) { converter.requiresOxygenAtmo = bool.Parse(value); } value = node.GetValue("shutdownIfAllOutputFull"); if (!string.IsNullOrEmpty(value)) { converter.shutdownIfAllOutputFull = bool.Parse(value); } value = node.GetValue("showRemainingTime"); if (!string.IsNullOrEmpty(value)) { converter.showRemainingTime = bool.Parse(value); } } catch (Exception ex) { Log("Error during load: " + ex.Message); } }
public void LoadFromNode(KolonyConverter converter, ConfigNode node) { string value; try { //This will load our private fields converter.Load(node); //Set its parameters value = node.GetValue("converterName"); if (!string.IsNullOrEmpty(value)) converter.converterName = value; value = node.GetValue("conversionRate"); if (!string.IsNullOrEmpty(value)) converter.conversionRate = float.Parse(value); value = node.GetValue("inputResources"); if (!string.IsNullOrEmpty(value)) converter.inputResources = value; value = node.GetValue("outputResources"); if (!string.IsNullOrEmpty(value)) converter.outputResources = value; value = node.GetValue("requiredResources"); if (!string.IsNullOrEmpty(value)) converter.requiredResources = value; value = node.GetValue("SurfaceOnly"); if (!string.IsNullOrEmpty(value)) converter.SurfaceOnly = bool.Parse(value); value = node.GetValue("converterEnabled"); if (!string.IsNullOrEmpty(value)) converter.converterEnabled = bool.Parse(value); value = node.GetValue("alwaysOn"); if (!string.IsNullOrEmpty(value)) converter.alwaysOn = bool.Parse(value); value = node.GetValue("requiresOxygenAtmo"); if (!string.IsNullOrEmpty(value)) converter.requiresOxygenAtmo = bool.Parse(value); value = node.GetValue("shutdownIfAllOutputFull"); if (!string.IsNullOrEmpty(value)) converter.shutdownIfAllOutputFull = bool.Parse(value); value = node.GetValue("showRemainingTime"); if (!string.IsNullOrEmpty(value)) converter.showRemainingTime = bool.Parse(value); } catch (Exception ex) { Log("Error during load: " + ex.Message); } }