private ConfigNode FromInFlightVessel(Vessel VesselToSave, ListType listType) { //This code is taken from InflightShipSave by Claw, using the CC-BY-NC-SA license. //This code thus is licensed under the same license, despite the GPLv3 license covering original KCT code //See https://github.com/ClawKSP/InflightShipSave string ShipName = VesselToSave.vesselName; ShipConstruct ConstructToSave = new ShipConstruct(ShipName, "", VesselToSave.parts[0]); Quaternion OriginalRotation = VesselToSave.vesselTransform.rotation; Vector3 OriginalPosition = VesselToSave.vesselTransform.position; if (listType == ListType.SPH) { VesselToSave.SetRotation(new Quaternion((float)Math.Sqrt(0.5), 0, 0, (float)Math.Sqrt(0.5))); } else { VesselToSave.SetRotation(new Quaternion(0, 0, 0, 1)); } Vector3 ShipSize = ShipConstruction.CalculateCraftSize(ConstructToSave); VesselToSave.SetPosition(new Vector3(0, Math.Min(ShipSize.y + 2, 15), 0)); //Try to limit the max height we put the ship at ConfigNode cn = ConstructToSave.SaveShip(); SanitizeShipNode(cn); // override KSP sizing of the ship construct cn.SetValue("size", KSPUtil.WriteVector(Utilities.GetShipSize(ConstructToSave, true))); // These are actually needed, do not comment them out VesselToSave.SetRotation(OriginalRotation); VesselToSave.SetPosition(OriginalPosition); //End of Claw's code. Thanks Claw! return(cn); }
// Save RDNode and parents. public void Save(ConfigNode node) { if (node == null) { HETTNSettings.Log("test11"); } node.AddValue("id", this.techID); node.AddValue("tier", this.tier); // KTT compatibility. node.AddValue("title", this.title); node.AddValue("description", this.description); node.AddValue("cost", this.scienceCost); node.AddValue("hideEmpty", this.hideIfNoParts); node.AddValue("nodeName", this.nodeName); node.AddValue("anyToUnlock", this.AnyParentToUnlock); node.AddValue("icon", this.iconRef); node.AddValue("pos", KSPUtil.WriteVector(this.pos)); node.AddValue("scale", this.scale); int count = this.parents.Length; for (int i = 0; i < count; i++) { this.parents[i].Save(node.AddNode("Parent")); } // ETT fix 4 of 5. if (this.unlocks != null) { this.unlocks.Save(node.AddNode("Unlocks")); } }
virtual public void Save(ConfigNode node) { try { ConfigNode.CreateConfigFromObject(this, node); } catch (Exception e) { Utils.Log("Exception while saving {}\n{}\n{}\n{}", GetType().Name, e.Message, e.StackTrace, node); } foreach (var fi in get_fields()) { if (not_persistant(fi)) { continue; } //save all IConfigNode if (fi.FieldType.GetInterface(cnode_name) != null) { var f = fi.GetValue(this) as IConfigNode; if (f != null) { f.Save(get_field_node(fi, node)); } } //save ConfigNode else if (typeof(ConfigNode).IsAssignableFrom(fi.FieldType)) { var f = fi.GetValue(this) as ConfigNode; if (f != null) { get_field_node(fi, node).AddData(f); } } //save some often used types else if (fi.FieldType == typeof(Guid)) { node.AddValue(fi.Name, ((Guid)fi.GetValue(this)).ToString("N")); } else if (fi.FieldType == typeof(Vector3d)) { node.AddValue(fi.Name, KSPUtil.WriteVector((Vector3d)fi.GetValue(this))); } else if (fi.FieldType == typeof(Orbit)) { var f = fi.GetValue(this) as Orbit; if (f != null) { var obt = new OrbitSnapshot(f); obt.Save(get_field_node(fi, node)); } } } }
public override void OnSave(ConfigNode node) { base.OnSave(node); foreach (KeyValuePair <int, SectionInfo> section in sections) { ConfigNode sectionNode = node.AddNode("SECTIONPOS"); sectionNode.AddValue("index", section.Key); sectionNode.AddValue("localPos", KSPUtil.WriteVector(KAS_Shared.GetLocalPosFrom(section.Value.transform, this.part.transform))); sectionNode.AddValue("localRot", KSPUtil.WriteQuaternion(KAS_Shared.GetLocalRotFrom(section.Value.transform, this.part.transform))); } }
public override void OnSave(ConfigNode node) { node.AddValue("cameraPosition", KSPUtil.WriteVector(cameraPosition)); node.AddValue("cameraForward", KSPUtil.WriteVector(cameraForward)); node.AddValue("cameraUp", KSPUtil.WriteVector(cameraUp)); node.AddValue("camEnabled", camEnabled.ToString()); node.AddValue("cameraFoV", cameraFoV.ToString()); node.AddValue("cameraClip", cameraClip.ToString()); base.OnSave(node); }
/* PRVESSEL STORAGE METHODS */ public void Save() { Debug.Log("[PR] Saving Data."); try { ConfigNode save = new ConfigNode(); save.AddValue("TIME", Planetarium.GetUniversalTime().ToString()); save.AddValue("DEFAULT_REFERENCE_MODE", ((int)defaultReferenceMode).ToString()); ConfigNode.CreateConfigFromObject(this, 0, save); //Save values per vessel foreach (PRVessel v in PRVessels) { ConfigNode cn_vessel = save.AddNode(v.vessel.id.ToString()); cn_vessel.AddValue("MOMENTUM", KSPUtil.WriteVector(v.momentum)); cn_vessel.AddValue("PLANETARIUM_RIGHT", KSPUtil.WriteVector(v.planetariumRight)); cn_vessel.AddValue("MJMODE", ((int)(v.mjMode)).ToString()); cn_vessel.AddValue("RTMODE", ((int)(v.rtMode)).ToString()); cn_vessel.AddValue("ROTATION_MODE_ACTIVE", v.rotationModeActive.ToString()); cn_vessel.AddValue("DYNAMIC_REFERENCE", v.dynamicReference.ToString()); cn_vessel.AddValue("ROTATION", KSPUtil.WriteQuaternion(v.rotation)); cn_vessel.AddValue("DIRECTION", KSPUtil.WriteVector(v.direction)); //Get Reference Type and save accordingly if (v.reference != null) { if (v.reference.GetType() == typeof(CelestialBody)) { cn_vessel.AddValue("REFERENCE", v.reference.GetName()); } else if (v.reference.GetType() == typeof(Vessel)) { cn_vessel.AddValue("REFERENCE", v.reference.GetVessel().id.ToString()); } } else { cn_vessel.AddValue("REFERENCE", "NONE"); } cn_vessel.AddValue("MOMENTUM_MODE_ACTIVE", v.momentumModeActive.ToString()); cn_vessel.AddValue("DESIRED_RPM", v.desiredRPM.ToString()); } save.Save(GetUnusedPath()); } catch (Exception e) { Debug.Log("[PR] Saving not sucessfull: " + e.Message); } }
public void Save(ConfigNode node) { if (!string.IsNullOrEmpty(md5sum)) { node.AddValue("CraftHullSum", md5sum); } node.AddValue("position", KSPUtil.WriteVector(position)); node.AddValue("rotation", KSPUtil.WriteQuaternion(rotation)); node.AddValue("hullError", hullError); if (bounds != null) { bounds.Save(node.AddNode("bounds")); node.AddValue("boundsOrigin", boundsOrigin); } }
public override void OnSave(ConfigNode node) { base.OnSave(node); node.AddValue("dockUId", this.dockedPartUId); if (this_vessel != null) { this_vessel.Save(node.AddNode("DOCKEDVESSEL")); } if (docked_vessel != null) { docked_vessel.Save(node.AddNode("DOCKEDVESSEL_Other")); } if (this.grappleNode != null) { node.AddValue("grapplePos", KSPUtil.WriteVector(this.grappleNode.position)); node.AddValue("grappleOrt", KSPUtil.WriteVector(this.grappleNode.orientation)); node.AddValue("grappleOrt2", KSPUtil.WriteVector(this.grappleNode.secondaryAxis)); } }
public void moveNode(string choice) { p_0pos = p_0.attachJoint.Joint.anchor; p_1pos = p_1.attachJoint.Joint.anchor; if (choice == "plus") { p_0.SetCollisionIgnores(); p_1.SetCollisionIgnores(); Vector3 temp_0 = p_0pos + v; Vector3 temp_1 = p_1pos + v; p_0.attachJoint.Joint.anchor = temp_0; p_1.attachJoint.Joint.anchor = temp_1; part.FindAttachNode(node_0).position = part.FindAttachNode(node_0).position + v; part.FindAttachNode(node_1).position = part.FindAttachNode(node_1).position - v; Debug.Log(KSPUtil.WriteVector(p_0.FindAttachNodeByPart(part).position)); p_0.ResetCollisionIgnores(); p_1.ResetCollisionIgnores(); } if (choice == "minus") { p_0.SetCollisionIgnores(); p_1.SetCollisionIgnores(); Vector3 temp_0 = p_0pos - v; Vector3 temp_1 = p_1pos - v; p_0.attachJoint.Joint.anchor = temp_0; p_1.attachJoint.Joint.anchor = temp_1; part.FindAttachNode(node_0).position = part.FindAttachNode(node_0).position - v; part.FindAttachNode(node_1).position = part.FindAttachNode(node_1).position + v; p_0.ResetCollisionIgnores(); p_1.ResetCollisionIgnores(); } }
public override void OnSave(ConfigNode node) { base.OnSave(node); Debug.Log("OnSave called"); ConfigNode partNode = PartLoader.getPartInfoByName("testHub").partConfig; Debug.Log("Adding values to partNode"); string setValue_0 = KSPUtil.WriteVector(part.FindAttachNode(node_0).position) + ", " + KSPUtil.WriteVector(part.FindAttachNode(node_0).orientation) + ", 1"; string setValue_1 = KSPUtil.WriteVector(part.FindAttachNode(node_1).position) + ", " + KSPUtil.WriteVector(part.FindAttachNode(node_1).orientation) + ", 1"; if (partNode.HasValue("node_stack_" + node_0)) { partNode.SetValue("node_stack_" + node_0, setValue_0); } if (partNode.HasValue("node_stack_" + node_1)) { partNode.SetValue("node_stack_" + node_1, setValue_1); } ShipConstruction.GetSavePath(vessel.name); Debug.Log("OnSave end"); }
public BuildListVessel(ShipConstruct s, string ls, double effCost, double bP, string flagURL) { _ship = s; ShipNode = s.SaveShip(); // Override KSP sizing of the ship construct ShipSize = Utilities.GetShipSize(s, true); ShipNode.SetValue("size", KSPUtil.WriteVector(ShipSize)); ShipName = s.shipName; Cost = Utilities.GetTotalVesselCost(ShipNode, true); EmptyCost = Utilities.GetTotalVesselCost(ShipNode, false); TotalMass = Utilities.GetShipMass(s, true, out EmptyMass, out _); HashSet <int> stages = new HashSet <int>(); NumStageParts = 0; StagePartCost = 0d; foreach (Part p in s.Parts) { if (p.stagingOn) { stages.Add(p.inverseStage); ++NumStageParts; StagePartCost += p.GetModuleCosts(p.partInfo.cost, ModifierStagingSituation.CURRENT) + p.partInfo.cost; } } NumStages = stages.Count; LaunchSite = ls; EffectiveCost = effCost; BuildPoints = bP; Progress = 0; Flag = flagURL; if (s.shipFacility == EditorFacility.VAB) { Type = ListType.VAB; FacilityBuiltIn = EditorFacility.VAB; } else if (s.shipFacility == EditorFacility.SPH) { Type = ListType.SPH; FacilityBuiltIn = EditorFacility.SPH; } else { Type = ListType.None; } Id = Guid.NewGuid(); KCTPersistentID = Guid.NewGuid().ToString(); CannotEarnScience = false; //get the crew from the editorlogic DesiredManifest = new List <string>(); if (CrewAssignmentDialog.Instance?.GetManifest()?.CrewCount > 0) { foreach (ProtoCrewMember crew in CrewAssignmentDialog.Instance.GetManifest().GetAllCrew(true) ?? new List <ProtoCrewMember>()) { DesiredManifest.Add(crew?.name ?? string.Empty); } } if (EffectiveCost == default) { // Can only happen in older saves that didn't have Effective cost persisted as a separate field // This code should be safe to remove after a while. EffectiveCost = Utilities.GetEffectiveCost(ShipNode.GetNodes("PART").ToList()); } IntegrationPoints = MathParser.ParseIntegrationTimeFormula(this); IntegrationCost = (float)MathParser.ParseIntegrationCostFormula(this); }
public void Save(ConfigNode node) { node.SetValue("positive", KSPUtil.WriteVector(positive)); node.SetValue("negative", KSPUtil.WriteVector(negative)); }
public string Serialize(object obj) { return(KSPUtil.WriteVector((Vector2)obj)); }
public string Serialize(object obj) { Log.Debug("Vector2Formatter.Serialize: got " + obj.ToString()); return(KSPUtil.WriteVector((Vector2)obj)); }