public static void UpdateVesselProtoPartFairing(VesselFairingMsgData msgData) { if (AllPlayerVessels.TryGetValue(msgData.VesselId, out var vesselProtoUpd)) { if (vesselProtoUpd.ProtoVessel == null) { return; } var part = VesselCommon.FindProtoPartInProtovessel(vesselProtoUpd.ProtoVessel, msgData.PartFlightId); if (part != null) { var module = VesselCommon.FindProtoPartModuleInProtoPart(part, "ModuleProceduralFairing"); module?.moduleValues.SetValue("fsm", "st_flight_deployed"); module?.moduleValues.RemoveNodesStartWith("XSECTION"); } } }
/// <summary> /// Updates the proto vessel with the values we received about a fairing change of a vessel /// </summary> private static string UpdateProtoVesselFileWithNewFairingData(string vesselData, VesselFairingMsgData msgData) { var document = new XmlDocument(); document.LoadXml(vesselData); var module = $@"/{ConfigNodeXmlParser.StartElement}/{ConfigNodeXmlParser.ParentNode}[@name='PART']/{ConfigNodeXmlParser.ValueNode}[@name='uid' and text()=""{msgData.PartFlightId}""]/" + $"following-sibling::{ConfigNodeXmlParser.ParentNode}[@name='MODULE']/{ConfigNodeXmlParser.ValueNode}" + @"[@name='name' and text()=""ModuleProceduralFairing""]/parent::{ConfigNodeXmlParser.ParentNode}[@name='MODULE']/"; var xpath = $"{module}/{ConfigNodeXmlParser.ValueNode}[@name='fsm']"; var fieldNode = document.SelectSingleNode(xpath); if (fieldNode != null) { fieldNode.InnerText = "st_flight_deployed"; } var moduleNode = fieldNode.ParentNode; var fairingsSections = document.SelectNodes($"{module}/{ConfigNodeXmlParser.ParentNode}[@name='XSECTION']"); if (moduleNode != null && fairingsSections != null) { for (var i = 0; i < fairingsSections.Count; i++) { moduleNode.RemoveChild(fairingsSections[i]); } } return(document.ToIndentedString()); }