public static PwrPartList Load(ConfigNode node) { string prtName = "", prtTitle = "", prtModuleName = "", prtPower = ""; bool prtSubsystem = false, prtActive = false, prtSolarDependant = false; float prtPowerF = 0f; node.TryGetValue("PrtName", ref prtName); node.TryGetValue("PrtTitle", ref prtTitle); node.TryGetValue("PrtModuleName", ref prtModuleName); node.TryGetValue("PrtPower", ref prtPower); node.TryGetValue("PrtPowerF", ref prtPowerF); node.TryGetValue("PrtActive", ref prtActive); node.TryGetValue("PrtSolarDependant", ref prtSolarDependant); PwrPartList info = new PwrPartList(prtName, prtTitle, prtModuleName, prtSubsystem, prtPower, prtPowerF, prtActive, prtSolarDependant, null); node.TryGetValue("PrtEditorInclude", ref info._prtEditorInclude); node.TryGetValue("PrtUserEditorInclude", ref info._prtUserEditorInclude); node.TryGetValue("PrtValidprtEmergShutDn", ref info._validprtEmergShutDn); node.TryGetValue("PrtEmergShutDnInclude", ref info._prtEmergShutDnInclude); node.TryGetValue("PrtPreEmergShutDnStateActive", ref info._prtPreEmergShutDnStateActive); int tmpEspPriority = 1; node.TryGetValue("PrtEmergShutDnPriority", ref tmpEspPriority); info._prtEmergShutDnPriority = (ESPPriority)tmpEspPriority; return(info); }
public override void OnLoad(ConfigNode node) { base.OnLoad(node); if (Utilities.GameModeisFlight || Utilities.GameModeisEditor) { try { if (node.HasNode(VesselProdPartsListConfigNodeName)) { ConfigNode vslProdPartsListNode = node.GetNode(VesselProdPartsListConfigNodeName); var prodPartsNodes = vslProdPartsListNode.GetNodes(PwrPartList.ConfigNodeName); foreach (ConfigNode prodPartsNode in prodPartsNodes) { if (prodPartsNode.HasValue("ProdPartKey")) { string id = prodPartsNode.GetValue("ProdPartKey"); Utilities.Log_Debug("AYPart Loading ProdPartKey = " + id); PwrPartList prodPartInfo = PwrPartList.Load(prodPartsNode); if (AYVesselPartLists.VesselProdPartsList.ContainsKey(id)) { Utilities.Log_Debug("AYPart Loading - Ignoring Duplicate Keys :" + id); } else { if (prodPartInfo.PrtName == "AmpYear SubSystems" || prodPartInfo.PrtName == "AmpYear Manager" || prodPartInfo.PrtName == "AmpYear SubSystems-Max") { if (part.vessel != null && part.vessel.rootPart != null) { prodPartInfo.PrtReference = part.vessel.rootPart; } } else { prodPartInfo.PrtReference = part; } AYVesselPartLists.VesselProdPartsList.Add(id, prodPartInfo); } } } } if (node.HasNode(VesselConsPartsListConfigNodeName)) { ConfigNode vslConsPartsListNode = node.GetNode(VesselConsPartsListConfigNodeName); var consPartsNodes = vslConsPartsListNode.GetNodes(PwrPartList.ConfigNodeName); foreach (ConfigNode consPartsNode in consPartsNodes) { if (consPartsNode.HasValue("ConsPartKey")) { string id = consPartsNode.GetValue("ConsPartKey"); Utilities.Log_Debug("VesselInfo Loading ConsPartKey = " + id); PwrPartList consPartInfo = PwrPartList.Load(consPartsNode); if (AYVesselPartLists.VesselConsPartsList.ContainsKey(id)) { Utilities.Log_Debug("AYPart Loading - Ignoring Duplicate Keys :" + id); } else { if (consPartInfo.PrtName == "AmpYear SubSystems" || consPartInfo.PrtName == "AmpYear Manager" || consPartInfo.PrtName == "AmpYear SubSystems-Max") { if (part.vessel != null && part.vessel.rootPart != null) { consPartInfo.PrtReference = part.vessel.rootPart; } } else { consPartInfo.PrtReference = part; } AYVesselPartLists.VesselConsPartsList.Add(id, consPartInfo); } } } } } catch (Exception ex) { Utilities.Log("AYPart Exception occurred during part load"); Utilities.Log("Exception: {0}", ex); } } }
/// <summary> /// Add or Amend part in the VesselProdPartsList or VesselConsPartsList /// </summary> /// <param name="pkey">the CraftID</param> /// <param name="prtName">the part Name</param> /// <param name="prtModuleName">the partmodule Module Name</param> /// <param name="prtSubsystem">True if it is an AmpYear Subsystem, otherwise False</param> /// <param name="prtActive">True if part is Active, otherwise False</param> /// <param name="prtPowerF">The Amount of EC being drawn (float)</param> /// <param name="prodPrt">True if it is producing Power, otherwise False</param> /// <param name="partSolar">True if the part is Solar dependant, otherwise False</param> /// <param name="partref">Reference to the Part. May also be null for vessel wide things</param> internal static void AddPart(uint pkey, string prtName, string prtTitle, string prtModuleName, bool prtSubsystem, bool prtActive, double prtPowerF, bool prodPrt, bool partSolar, Part partref) { string keyValue = CreatePartKey(pkey, prtModuleName); if (prodPrt) // Producer part list { if (VesselProdPartsList.TryGetValue(keyValue, out partFnd)) //Try to get entry with index = 1 for key. If found, find the next available index { partFnd.PrtActive = prtActive; partFnd.PrtName = prtName; partFnd.PrtTitle = prtTitle; partFnd.PrtSubsystem = prtSubsystem; if (!AYController.Emergencypowerdownactivated && !AYController.Emergencypowerdownreset && !AYController.EmgcyShutOverrideStarted) { //VesselProdPartsList[keyValue].PrtPreEmergShutDnStateActive = prtActive; partFnd.PrtPreEmergShutDnStateActive = prtActive; } if (AYController.ShowDarkSideWindow && partSolar) { partFnd.PrtEditorInclude = false; } if (prtModuleName != "ModuleResourceConverter" || partFnd.PrtPowerF == 0.0) { if (partFnd.PrtEditorInclude && prtActive) { AYController.Instance.TotalPowerProduced += prtPowerF; } partFnd.PrtPowerF += (float)prtPowerF; partFnd.PrtPower = partFnd.PrtPowerF.ToString("####0.###"); } partFnd.PrtSolarDependant = partSolar; tmpESPDfltValue = AYController.Instance.AYsettings.PartModuleEmergShutDnDflt.FirstOrDefault(a => a.Key.Name == prtModuleName); if (tmpESPDfltValue.Key != null) { partFnd.ValidprtEmergShutDn = tmpESPDfltValue.Value.EmergShutDnDflt; } else { partFnd.ValidprtEmergShutDn = false; } } else { PwrPartList newProdPart = new PwrPartList(prtName, prtTitle, prtModuleName, prtSubsystem, "", (float)prtPowerF, prtActive, partSolar, partref); if (AYController.ShowDarkSideWindow && partSolar) { newProdPart.PrtEditorInclude = false; newProdPart.PrtUserEditorInclude = true; } else { newProdPart.PrtEditorInclude = true; newProdPart.PrtUserEditorInclude = true; } if (newProdPart.PrtEditorInclude && prtActive) { AYController.Instance.TotalPowerProduced += prtPowerF; } newProdPart.PrtPower = newProdPart.PrtPowerF.ToString("####0.###"); newProdPart.PrtSolarDependant = partSolar; tmpESPDfltValue = AYController.Instance.AYsettings.PartModuleEmergShutDnDflt.FirstOrDefault(a => a.Key.Name == prtModuleName); if (tmpESPDfltValue.Key != null) { newProdPart.ValidprtEmergShutDn = tmpESPDfltValue.Value.EmergShutDnDflt; newProdPart.PrtEmergShutDnPriority = tmpESPDfltValue.Value.EmergShutPriority; } else { newProdPart.ValidprtEmergShutDn = false; newProdPart.PrtEmergShutDnPriority = ESPPriority.MEDIUM; } VesselProdPartsList.Add(keyValue, newProdPart); } } else // consumer part list { if (VesselConsPartsList.TryGetValue(keyValue, out partFnd)) { partFnd.PrtActive = prtActive; partFnd.PrtName = prtName; partFnd.PrtTitle = prtTitle; partFnd.PrtSubsystem = prtSubsystem; if (!AYController.Emergencypowerdownactivated && !AYController.Emergencypowerdownreset && !AYController.EmgcyShutOverrideStarted) { partFnd.PrtPreEmergShutDnStateActive = prtActive; } if (prtModuleName != "ModuleResourceConverter" || partFnd.PrtPowerF == 0.0) { if (partFnd.PrtEditorInclude && prtActive) { AYController.Instance.TotalPowerDrain += prtPowerF; } partFnd.PrtPowerF += (float)prtPowerF; partFnd.PrtPower = partFnd.PrtPowerF.ToString("####0.###"); } partFnd.PrtSolarDependant = partSolar; tmpESPDfltValue = AYController.Instance.AYsettings.PartModuleEmergShutDnDflt.FirstOrDefault(a => a.Key.Name == prtModuleName); if (tmpESPDfltValue.Key != null) { partFnd.ValidprtEmergShutDn = tmpESPDfltValue.Value.EmergShutDnDflt; } else { partFnd.ValidprtEmergShutDn = false; } } else { PwrPartList newConsPart = new PwrPartList(prtName, prtTitle, prtModuleName, prtSubsystem, "", (float)prtPowerF, prtActive, partSolar, partref); if (prtActive) { AYController.Instance.TotalPowerDrain += prtPowerF; } newConsPart.PrtPowerF = (float)prtPowerF; newConsPart.PrtPower = newConsPart.PrtPowerF.ToString("####0.###"); newConsPart.PrtSolarDependant = partSolar; tmpESPDfltValue = AYController.Instance.AYsettings.PartModuleEmergShutDnDflt.FirstOrDefault(a => a.Key.Name == prtModuleName); if (tmpESPDfltValue.Key != null) { newConsPart.ValidprtEmergShutDn = tmpESPDfltValue.Value.EmergShutDnDflt; newConsPart.PrtEmergShutDnPriority = tmpESPDfltValue.Value.EmergShutPriority; } else { newConsPart.ValidprtEmergShutDn = false; newConsPart.PrtEmergShutDnPriority = ESPPriority.MEDIUM; } VesselConsPartsList.Add(keyValue, newConsPart); } } if (AYController.Instance.PartsToDelete.Contains(keyValue)) { AYController.Instance.PartsToDelete.Remove(keyValue); } }