public override void OnLoad(ConfigNode node) { if (node.HasValue("towerRot")) { string rot = node.GetValue("towerRot"); towerRot = KSPUtil.ParseQuaternion(rot); } if (node.HasValue("ForceHeightCheck")) { bool fhc; if (bool.TryParse(node.GetValue("ForceHeightCheck"), out fhc)) { enableExtension |= fhc; } } }
public override void OnLoad(ConfigNode node) { if (!HighLogic.LoadedSceneIsGame) { towerPivot = part.FindModelTransform(trf_towerPivot_name); towerYoke = part.FindModelTransform(trf_towerYoke_name); towerAnchor = part.FindModelTransform(trf_anchor_name); towerGirder = part.FindModelTransform(trf_towerGirder_name); towerStretch = part.FindModelTransform(trf_towerStretch_name); girderMeshFilter = towerGirder.GetComponent <MeshFilter>(); girderMesh = girderMeshFilter.mesh; if (!SystemInfo.supportsInstancing) { this.LogWarning("You are using a computer which does not support instancing, " + "falling back to a slower launch clamp implementation in the editor"); instancingEnabled = false; } if (girderFactory == null) { //Debug.Log("Making new girder factory..."); girderSegmentHeight = Vector3.Distance(towerAnchor.position, towerStretch.position); if (float.IsInfinity(girderSegmentHeight)) { girderSegmentHeight = -1f; } girderFactory = ScriptableObject.CreateInstance <LaunchClampGirderFactory>(); girderFactory.Initialize(girderMesh, girderSegmentHeight, maxSegments); } } if (node.HasValue("towerRot")) { string rot = node.GetValue("towerRot"); towerRot = KSPUtil.ParseQuaternion(rot); } _girderSegments = 1; base.OnLoad(node); }
public void Load() { Debug.Log("[PR] Loading Data."); //This is called when all persistent rotation data is being loaded from the cfg file. #region ### Quicksave selection ### ConfigNode temp = null; float temp_delta = 0f; ConfigNode load = null; float load_delta = 0f; float oldest_time = 0f; List <String> allPaths = GetAllPaths(); if (allPaths.Count() == 0) { Debug.Log("[PR] No save files found."); return; } foreach (String path in allPaths) { temp = ConfigNode.Load(path); if (temp == null) { Debug.Log("[PR] Couldn't load data: File not found."); continue; } float time = float.Parse(temp.GetValue("TIME")); temp_delta = Mathf.Abs(time - (float)Planetarium.GetUniversalTime()); if (time > oldest_time) { oldest_time = time; } if (load == null) { load = temp; load_delta = temp_delta; } else { if (temp_delta < load_delta) { load = temp; load_delta = temp_delta; } } } #endregion //Load global variables defaultReferenceMode = (DefaultReferenceMode)(int.Parse(load.GetValue("DEFAULT_REFERENCE_MODE"))); //Pregenerate data for all vessels that currently exist foreach (Vessel vessel in FlightGlobals.Vessels) { FindPRVessel(vessel); } //All vessels should now have data. //Load PRVessel data foreach (PRVessel v in PRVessels) { ConfigNode cn_vessel = load.GetNode(v.vessel.id.ToString()); if (cn_vessel != null) //If node exists at all { Debug.Log("[PR] Found node for vessel " + v.vessel.vesselName); v.momentum = KSPUtil.ParseVector3(cn_vessel.GetValue("MOMENTUM")); v.planetariumRight = KSPUtil.ParseVector3(cn_vessel.GetValue("PLANETARIUM_RIGHT")); v.mjMode = MechJebWrapper.saTargetMap[int.Parse(cn_vessel.GetValue("MJMODE"))]; v.rtMode = RemoteTechWrapper.acFlightModeMap[int.Parse(cn_vessel.GetValue("RTMODE"))]; v.rotationModeActive = Boolean.Parse(cn_vessel.GetValue("ROTATION_MODE_ACTIVE")); v.dynamicReference = Boolean.Parse(cn_vessel.GetValue("DYNAMIC_REFERENCE")); v.rotation = KSPUtil.ParseQuaternion(cn_vessel.GetValue("ROTATION")); v.direction = KSPUtil.ParseVector3(cn_vessel.GetValue("DIRECTION")); string reference = cn_vessel.GetValue("REFERENCE"); v.reference = null; if (reference != "NONE") { foreach (CelestialBody body in FlightGlobals.Bodies) { if (body.name == reference) { v.reference = body; } } foreach (Vessel vessel in FlightGlobals.Vessels) { if (vessel.id.ToString() == reference) { v.reference = vessel; } } } v.momentumModeActive = Boolean.Parse(cn_vessel.GetValue("MOMENTUM_MODE_ACTIVE")); v.desiredRPM = float.Parse(cn_vessel.GetValue("DESIRED_RPM")); } } //If old save state is loaded, delete all save files! if (float.Parse(load.GetValue("TIME")) < oldest_time) { Debug.Log("[PR] Reloading old save, flushing data."); foreach (String path in GetAllPaths()) { File.Delete(path); } //Save current loaded one. Save(); } //TODO: Delete all files on Launch / Keep all files that correspond to a quicksave Debug.Log("[PR] Oldest time: " + oldest_time.ToString()); Debug.Log("[PR] Loaded time: " + load.GetValue("TIME")); Interface.instance.desiredRPMstr = FindPRVessel(FlightGlobals.ActiveVessel).desiredRPM.ToString(); //Set desired rpm of active vessel }