private void InitializeParts(Vessel vessel) { Log("TestFlightManager: Initializing parts for vessel " + vessel.GetName()); // Launch time is equal to current UT unless we have already chached this vessel's launch time double launchTime = Planetarium.GetUniversalTime(); if (knownVessels.ContainsKey(vessel.id)) { launchTime = knownVessels[vessel.id]; } foreach (Part part in vessel.parts) { ITestFlightCore core = TestFlightUtil.GetCore(part); if (core != null) { Log("TestFlightManager: Found core. Getting part data"); PartFlightData partData = tfScenario.GetFlightDataForPartName(TestFlightUtil.GetFullPartName(part)); if (partData == null) { Log("TestFlightManager: Unable to find part data. Starting fresh."); core.InitializeFlightData(null); } else { core.InitializeFlightData(partData.GetFlightData()); } } } }
internal void CalculateWindowBounds() { if (appLauncherButton == null) { return; } if (tfScenario == null) { return; } float windowWidth = 350f; float left = Screen.width - windowWidth - 75f; float windowHeight = 50f; float numItems = 0; ITestFlightCore core = GetCore(); if (core != null) { List <TestFlightData> flightData = null; PartFlightData partData = tfScenario.GetFlightDataForPartName(TestFlightUtil.GetFullPartName(SelectedPart)); if (partData == null) { numItems = 0; } else { flightData = partData.GetFlightData(); if (flightData != null) { numItems = flightData.Count; } } } windowHeight += numItems * 20f; float top = Screen.height - windowHeight - 60f; if (!tfScenario.userSettings.editorWindowLocked) { left = tfScenario.userSettings.editorWindowPosition.xMin; top = tfScenario.userSettings.editorWindowPosition.yMin; } WindowRect = new Rect(left, top, windowWidth, windowHeight); }
public void Update() { if (TestFlightManagerScenario.Instance == null) { return; } if (!TestFlightManagerScenario.Instance.SettingsEnabled) { return; } double currentTime = Planetarium.GetUniversalTime(); teamsToStop.Clear(); if (currentTime - lastUpdateTime >= updateFrequency) { float normalizedTime = (float)((currentTime - lastUpdateTime) / updateFrequency); Log("Doing research update, normalized time " + normalizedTime); lastUpdateTime = currentTime; if (activeTeams == null || activeTeams.Count <= 0) { return; } teamsEnumerator = activeTeams.GetEnumerator(); KeyValuePair <string, TestFlightRnDTeam> entry; while (teamsEnumerator.MoveNext()) { entry = teamsEnumerator.Current; if (entry.Value.PartInResearch != "" && entry.Value.ResearchActive) { float partCurrentData = tfScenario.GetFlightDataForPartName(entry.Value.PartInResearch); if (partCurrentData >= entry.Value.MaxData) { Log("Part " + entry.Value.PartInResearch + " has reached maximum RnD data. Removing research automatically"); teamsToStop.Add(entry.Key); } else { float partData = entry.Value.UpdateResearch(normalizedTime, partCurrentData); Log("Research tick for part " + entry.Value.PartInResearch + " yielded " + partData + "du"); if (partData > 0) { TestFlightManagerScenario.Instance.AddFlightDataForPartName(entry.Value.PartInResearch, partData); } } } } if (teamsToStop.Count > 0) { for (int i = 0; i < teamsToStop.Count; i++) { activeTeams.Remove(teamsToStop[i]); } } } }
public void Update() { double currentTime = Planetarium.GetUniversalTime(); List <string> teamsToStop = new List <string>(); if (currentTime - lastUpdateTime >= updateFrequency) { float normalizedTime = (float)((currentTime - lastUpdateTime) / updateFrequency); Log("Doing research update, normalized time " + normalizedTime); lastUpdateTime = currentTime; if (activeTeams == null || activeTeams.Count <= 0) { return; } foreach (KeyValuePair <string, TestFlightRnDTeam> entry in activeTeams) { if (entry.Value.PartInResearch != "" && entry.Value.ResearchActive) { float partCurrentData = tfScenario.GetFlightDataForPartName(entry.Value.PartInResearch); if (partCurrentData >= entry.Value.MaxData) { Log("Part " + entry.Value.PartInResearch + " has reached maximum RnD data. Removing research automatically"); teamsToStop.Add(entry.Key); } else { float partData = entry.Value.UpdateResearch(normalizedTime, partCurrentData); Log("Research tick for part " + entry.Value.PartInResearch + " yielded " + partData + "du"); if (partData > 0) { TestFlightManagerScenario.Instance.AddFlightDataForPartName(entry.Value.PartInResearch, partData); } } } } if (teamsToStop.Count > 0) { foreach (string team in teamsToStop) { activeTeams.Remove(team); } } } }