Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: mockingbirdnest/Principia
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 343571bb91d0
Choose a base ref
...
head repository: mockingbirdnest/Principia
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 065dd43b1251
Choose a head ref
  • 2 commits
  • 1 file changed
  • 1 contributor

Commits on Jun 28, 2019

  1. Copy the full SHA
    8ba2042 View commit details
  2. Merge pull request #2223 from pleroy/2222

    Fix persistent error message and problems with short flight plans
    pleroy authored Jun 28, 2019
    Copy the full SHA
    065dd43 View commit details
Showing with 28 additions and 12 deletions.
  1. +28 −12 ksp_plugin_adapter/flight_planner.cs
40 changes: 28 additions & 12 deletions ksp_plugin_adapter/flight_planner.cs
Original file line number Diff line number Diff line change
@@ -230,6 +230,7 @@ private void RenderFlightPlan(string vessel_guid) {
if (burn_editors_.Count == 0 &&
UnityEngine.GUILayout.Button("Delete flight plan")) {
plugin.FlightPlanDelete(vessel_guid);
ResetStatus();
Shrink();
// The state change will happen the next time we go through OnGUI.
} else {
@@ -291,10 +292,20 @@ private void RenderFlightPlan(string vessel_guid) {
previous_burn : burn_editors_.LastOrDefault());
Burn candidate_burn = editor.Burn();
var status = plugin.FlightPlanAppend(vessel_guid, candidate_burn);
editor.Reset(plugin.FlightPlanGetManoeuvre(
vessel_guid, burn_editors_.Count));
burn_editors_.Add(editor);
UpdateStatus(status, burn_editors_.Count - 1);

// The previous call did not necessarily create a manœuvre. Check if
// we need to add an editor.
int number_of_manœuvres =
plugin.FlightPlanNumberOfManoeuvres(vessel_guid);
if (number_of_manœuvres > burn_editors_.Count) {
editor.Reset(plugin.FlightPlanGetManoeuvre(
vessel_guid, number_of_manœuvres - 1));
burn_editors_.Add(editor);
UpdateStatus(status, number_of_manœuvres - 1);
} else {
UpdateStatus(status, number_of_manœuvres);
}

Shrink();
}
}
@@ -415,11 +426,15 @@ internal bool TryParsePlanLength(string str, out double value) {
return true;
}

private void ResetStatus() {
status_ = Status.OK;
first_error_manœuvre_ = null;
message_was_displayed_ = false;
}

private void UpdateStatus(Status status, int? error_manœuvre) {
if (message_was_displayed_) {
status_ = Status.OK;
first_error_manœuvre_ = null;
message_was_displayed_ = false;
ResetStatus();
}
if (status_.ok() && !status.ok()) {
status_ = status;
@@ -469,19 +484,20 @@ private string GetStatusMessage() {
? "the start of the flight plan"
: "manœuvre #" +
first_error_manœuvre_.Value) + " or " +
((first_error_manœuvre_.Value == manœuvres - 1)
((manœuvres == 0 ||
first_error_manœuvre_.Value == manœuvres - 1)
? "the end of the flight plan"
: "manœuvre #" +
(first_error_manœuvre_.Value + 2));
remedy_message = ((first_error_manœuvre_.Value == manœuvres - 1)
remedy_message = ((manœuvres == 0 ||
first_error_manœuvre_.Value == manœuvres - 1)
? "extending the flight plan or "
: "") +
"adjusting the initial time or reducing the " +
"duration of manœuvre #" +
(first_error_manœuvre_.Value + 1);
} else {
status_message = "flight plan final time overlaps the last " +
"manœuvre";
status_message = "flight plan is too short";
remedy_message = "increasing the flight plan duration";
}
}
@@ -511,7 +527,7 @@ private string GetStatusMessage() {
private float warning_height_ = 1;

private Status status_ = Status.OK;
private int? first_error_manœuvre_;
private int? first_error_manœuvre_; // May exceed the number of manœuvres.
private bool message_was_displayed_ = false;

private const double log10_time_lower_rate = 0.0;