public static void load(ConfigNode node) { // get version (or use current one for new savegames) version = Lib.ConfigValue(node, "version", Lib.Version()); // get unique id (or generate one for new savegames) uid = Lib.ConfigValue(node, "uid", Lib.RandomInt(int.MaxValue)); // if this is an unsupported version, print warning if (string.CompareOrdinal(version, "1.1.5.0") < 0) { Lib.Log("loading save from unsupported version " + version); } // load kerbals data kerbals = new Dictionary <string, KerbalData>(); if (node.HasNode("kerbals")) { foreach (var kerbal_node in node.GetNode("kerbals").GetNodes()) { kerbals.Add(from_safe_key(kerbal_node.name), new KerbalData(kerbal_node)); } } // load vessels data vessels = new Dictionary <uint, VesselData>(); if (node.HasNode("vessels")) { foreach (var vessel_node in node.GetNode("vessels").GetNodes()) { vessels.Add(Lib.Parse.ToUInt(vessel_node.name), new VesselData(vessel_node)); } } // load bodies data bodies = new Dictionary <string, BodyData>(); if (node.HasNode("bodies")) { foreach (var body_node in node.GetNode("bodies").GetNodes()) { bodies.Add(from_safe_key(body_node.name), new BodyData(body_node)); } } // load landmark data if (node.HasNode("landmarks")) { landmarks = new LandmarkData(node.GetNode("landmarks")); } else { landmarks = new LandmarkData(); } // if an old savegame was imported, log some debug info if (version != Lib.Version()) { Lib.Log("savegame converted from version " + version); } }
public static void Load(ConfigNode node) { // get version (or use current one for new savegames) string versionStr = Lib.ConfigValue(node, "version", Lib.KerbalismVersion.ToString()); // sanitize old saves (pre 3.1) format (X.X.X.X) to new format (X.X) if (versionStr.Split('.').Length > 2) { versionStr = versionStr.Split('.')[0] + "." + versionStr.Split('.')[1]; } version = new Version(versionStr); // if this is an unsupported version, print warning if (version <= new Version(1, 2)) { Lib.Log("loading save from unsupported version " + version); } // get unique id (or generate one for new savegames) uid = Lib.ConfigValue(node, "uid", Lib.RandomInt(int.MaxValue)); // load kerbals data kerbals = new Dictionary <string, KerbalData>(); if (node.HasNode("kerbals")) { foreach (var kerbal_node in node.GetNode("kerbals").GetNodes()) { kerbals.Add(From_safe_key(kerbal_node.name), new KerbalData(kerbal_node)); } } // load the science database, has to be before vessels are loaded ScienceDB.Load(node); UnityEngine.Profiling.Profiler.BeginSample("Kerbalism.DB.Load.Vessels"); vessels.Clear(); // flightstate will be null when first creating the game if (HighLogic.CurrentGame.flightState != null) { ConfigNode vesselsNode = node.GetNode("vessels2"); if (vesselsNode == null) { vesselsNode = new ConfigNode(); } // HighLogic.CurrentGame.flightState.protoVessels is what is used by KSP to persist vessels // It is always available and synchronized in OnLoad, no matter the scene, excepted on the first OnLoad in a new game foreach (ProtoVessel pv in HighLogic.CurrentGame.flightState.protoVessels) { if (pv.vesselID == Guid.Empty) { // It seems flags are saved with an empty GUID. skip them. Lib.LogDebug("Skipping VesselData load for vessel with empty GUID :" + pv.vesselName); continue; } VesselData vd = new VesselData(pv, vesselsNode.GetNode(pv.vesselID.ToString())); vessels.Add(pv.vesselID, vd); Lib.LogDebug("VesselData loaded for vessel " + pv.vesselName); } } UnityEngine.Profiling.Profiler.EndSample(); // for compatibility with old saves, convert drives data (it's now saved in PartData) if (node.HasNode("drives")) { Dictionary <uint, PartData> allParts = new Dictionary <uint, PartData>(); foreach (VesselData vesselData in vessels.Values) { foreach (PartData partData in vesselData.PartDatas) { // we had a case of someone having a save with multiple parts having the same flightID // 5 duplicates, all were asteroids. if (!allParts.ContainsKey(partData.FlightId)) { allParts.Add(partData.FlightId, partData); } } } foreach (var drive_node in node.GetNode("drives").GetNodes()) { uint driveId = Lib.Parse.ToUInt(drive_node.name); if (allParts.ContainsKey(driveId)) { allParts[driveId].Drive = new Drive(drive_node); } } } // load bodies data storms = new Dictionary <string, StormData>(); if (node.HasNode("bodies")) { foreach (var body_node in node.GetNode("bodies").GetNodes()) { storms.Add(From_safe_key(body_node.name), new StormData(body_node)); } } // load landmark data if (node.HasNode("landmarks")) { landmarks = new LandmarkData(node.GetNode("landmarks")); } else { landmarks = new LandmarkData(); } // load ui data if (node.HasNode("ui")) { ui = new UIData(node.GetNode("ui")); } else { ui = new UIData(); } // if an old savegame was imported, log some debug info if (version != Lib.KerbalismVersion) { Lib.Log("savegame converted from version " + version + " to " + Lib.KerbalismVersion); } }