Skip to content

Commit

Permalink
Make all Persistent fields Public
Browse files Browse the repository at this point in the history
this should really fix persistence

closes #1678
closes #1580

Signed-off-by: Lamont Granquist <lamont@scriptkiddie.org>
  • Loading branch information
lamont-granquist committed Oct 31, 2023
1 parent c504550 commit a0b239b
Show file tree
Hide file tree
Showing 17 changed files with 113 additions and 64 deletions.
61 changes: 41 additions & 20 deletions MechJeb2/AttitudeControllers/BetterController.cs
@@ -1,4 +1,5 @@
using System;
using JetBrains.Annotations;
using KSP.Localization;
using MechJebLib.Control;
using UnityEngine;
Expand All @@ -11,65 +12,85 @@ internal class BetterController : BaseAttitudeController
private Vessel Vessel => ac.Vessel;

/* FIXME: when you do that look at ModuleGimbal gimbalResponseSpeed and model the time delay and use the XLR11 since it has slow gimbal */
[UsedImplicitly]
[Persistent(pass = (int)(Pass.TYPE | Pass.GLOBAL))]
private readonly EditableDouble PosKp = new EditableDouble(1.98);
public readonly EditableDouble PosKp = new EditableDouble(1.98);

[UsedImplicitly]
[Persistent(pass = (int)(Pass.TYPE | Pass.GLOBAL))]
private readonly EditableDouble PosDeadband = new EditableDouble(0.002);
public readonly EditableDouble PosDeadband = new EditableDouble(0.002);

[UsedImplicitly]
[Persistent(pass = (int)(Pass.TYPE | Pass.GLOBAL))]
private readonly EditableDouble VelKp = new EditableDouble(10);
public readonly EditableDouble VelKp = new EditableDouble(10);

[UsedImplicitly]
[Persistent(pass = (int)(Pass.TYPE | Pass.GLOBAL))]
private readonly EditableDouble VelKi = new EditableDouble(20);
public readonly EditableDouble VelKi = new EditableDouble(20);

[UsedImplicitly]
[Persistent(pass = (int)(Pass.TYPE | Pass.GLOBAL))]
private readonly EditableDouble VelKd = new EditableDouble(0.425);
public readonly EditableDouble VelKd = new EditableDouble(0.425);

[UsedImplicitly]
[Persistent(pass = (int)(Pass.TYPE | Pass.GLOBAL))]
private readonly EditableDouble VelN = new EditableDouble(84.1994541201249);
public readonly EditableDouble VelN = new EditableDouble(84.1994541201249);

[UsedImplicitly]
[Persistent(pass = (int)(Pass.TYPE | Pass.GLOBAL))]
private readonly EditableDouble VelB = new EditableDouble(0.994);
public readonly EditableDouble VelB = new EditableDouble(0.994);

[UsedImplicitly]
[Persistent(pass = (int)(Pass.TYPE | Pass.GLOBAL))]
private readonly EditableDouble VelC = new EditableDouble(0.0185);
public readonly EditableDouble VelC = new EditableDouble(0.0185);

[UsedImplicitly]
[Persistent(pass = (int)(Pass.TYPE | Pass.GLOBAL))]
private readonly EditableDouble VelDeadband = new EditableDouble(0.0001);
public readonly EditableDouble VelDeadband = new EditableDouble(0.0001);

[UsedImplicitly]
[Persistent(pass = (int)(Pass.TYPE | Pass.GLOBAL))]
private bool VelClegg;
public bool VelClegg;

[UsedImplicitly]
[Persistent(pass = (int)(Pass.TYPE | Pass.GLOBAL))]
private readonly EditableDouble VelSmoothIn = new EditableDouble(1);
public readonly EditableDouble VelSmoothIn = new EditableDouble(1);

[UsedImplicitly]
[Persistent(pass = (int)(Pass.TYPE | Pass.GLOBAL))]
private readonly EditableDouble VelSmoothOut = new EditableDouble(1);
public readonly EditableDouble VelSmoothOut = new EditableDouble(1);

[UsedImplicitly]
[Persistent(pass = (int)(Pass.TYPE | Pass.GLOBAL))]
private readonly EditableDouble PosSmoothIn = new EditableDouble(1);
public readonly EditableDouble PosSmoothIn = new EditableDouble(1);

[UsedImplicitly]
[Persistent(pass = (int)(Pass.TYPE | Pass.GLOBAL))]
private readonly EditableDouble maxStoppingTime = new EditableDouble(2.0);
public readonly EditableDouble maxStoppingTime = new EditableDouble(2.0);

[UsedImplicitly]
[Persistent(pass = (int)(Pass.TYPE | Pass.GLOBAL))]
private readonly EditableDouble minFlipTime = new EditableDouble(120);
public readonly EditableDouble minFlipTime = new EditableDouble(120);

[UsedImplicitly]
[Persistent(pass = (int)(Pass.TYPE | Pass.GLOBAL))]
private readonly EditableDouble rollControlRange = new EditableDouble(5);
public readonly EditableDouble rollControlRange = new EditableDouble(5);

[UsedImplicitly]
[Persistent(pass = (int)(Pass.TYPE | Pass.GLOBAL))]
private bool useControlRange = true;
public bool useControlRange = true;

[UsedImplicitly]
[Persistent(pass = (int)(Pass.TYPE | Pass.GLOBAL))]
private bool useFlipTime = true;
public bool useFlipTime = true;

[UsedImplicitly]
[Persistent(pass = (int)(Pass.TYPE | Pass.GLOBAL))]
private bool useStoppingTime = true;
public bool useStoppingTime = true;

[UsedImplicitly]
[Persistent(pass = (int)(Pass.TYPE | Pass.GLOBAL))]
private int _version = -1;
public int _version = -1;

private const int SETTINGS_VERSION = 5;

Expand Down
10 changes: 7 additions & 3 deletions MechJeb2/AttitudeControllers/HybridController.cs
@@ -1,19 +1,23 @@
using System;
using JetBrains.Annotations;
using KSP.Localization;
using UnityEngine;

namespace MuMech.AttitudeControllers
{
internal class HybridController : BaseAttitudeController
{
[UsedImplicitly]
[Persistent(pass = (int)Pass.GLOBAL)]
private readonly EditableDouble maxStoppingTime = new EditableDouble(2);
public readonly EditableDouble maxStoppingTime = new EditableDouble(2);

[UsedImplicitly]
[Persistent(pass = (int)Pass.GLOBAL)]
private readonly EditableDoubleMult rollControlRange = new EditableDoubleMult(5 * Mathf.Deg2Rad, Mathf.Deg2Rad);
public readonly EditableDoubleMult rollControlRange = new EditableDoubleMult(5 * Mathf.Deg2Rad, Mathf.Deg2Rad);

[UsedImplicitly]
[Persistent(pass = (int)Pass.GLOBAL)]
private bool useControlRange = true;
public bool useControlRange = true;

public TorquePI pitchPI = new TorquePI();
public TorquePI yawPI = new TorquePI();
Expand Down
7 changes: 5 additions & 2 deletions MechJeb2/AttitudeControllers/KosAttitudeController.cs
@@ -1,15 +1,18 @@
using System;
using JetBrains.Annotations;
using UnityEngine;

namespace MuMech.AttitudeControllers
{
internal class KosAttitudeController : BaseAttitudeController
{
[UsedImplicitly]
[Persistent(pass = (int)Pass.GLOBAL)]
private readonly EditableDouble maxStoppingTime = new EditableDouble(2);
public readonly EditableDouble maxStoppingTime = new EditableDouble(2);

[UsedImplicitly]
[Persistent(pass = (int)Pass.GLOBAL)]
private readonly EditableDoubleMult rollControlRange = new EditableDoubleMult(5 * Mathf.Deg2Rad, Mathf.Deg2Rad);
public readonly EditableDoubleMult rollControlRange = new EditableDoubleMult(5 * Mathf.Deg2Rad, Mathf.Deg2Rad);
//public double RollControlRange {
// get { return this.rollControlRange; }
// set { this.rollControlRange.val = Math.Max(EPSILON, Math.Min(Math.PI, value)); }
Expand Down
4 changes: 3 additions & 1 deletion MechJeb2/AttitudeControllers/MJAttitudeController.cs
@@ -1,4 +1,5 @@
using System;
using JetBrains.Annotations;
using KSP.Localization;
using UnityEngine;

Expand All @@ -17,8 +18,9 @@ internal class MJAttitudeController : BaseAttitudeController

public Vector3d TfV = new Vector3d(0.3, 0.3, 0.3);

[UsedImplicitly]
[Persistent(pass = (int)Pass.GLOBAL)]
private Vector3 TfVec = new Vector3(0.3f, 0.3f, 0.3f); // use the serialize since Vector3d does not
public Vector3 TfVec = new Vector3(0.3f, 0.3f, 0.3f); // use the serialize since Vector3d does not

[Persistent(pass = (int)Pass.GLOBAL)]
public double TfMin = 0.1;
Expand Down
18 changes: 6 additions & 12 deletions MechJeb2/DisplayModule.cs
Expand Up @@ -43,18 +43,15 @@ protected set
}
}

[SerializeField]
[Persistent(pass = (int)Pass.GLOBAL)]
private Vector4 _windowVector = new Vector4(10, 40, 0, 0); //Persistence is via a Vector4 since ConfigNode doesn't know how to serialize Rects
public Vector4 _windowVector = new Vector4(10, 40, 0, 0); //Persistence is via a Vector4 since ConfigNode doesn't know how to serialize Rects

[SerializeField]
[Persistent(pass = (int)Pass.GLOBAL)]
private Vector4
public Vector4
_windowVectorEditor = new Vector4(10, 40, 0, 0); //Persistence is via a Vector4 since ConfigNode doesn't know how to serialize Rects

[SerializeField]
[Persistent(pass = (int)Pass.GLOBAL)]
private bool _showInFlight = true;
public bool _showInFlight = true;

public bool ShowInFlight
{
Expand All @@ -69,9 +66,8 @@ public bool ShowInFlight
}
}

[SerializeField]
[Persistent(pass = (int)Pass.GLOBAL)]
private bool _showInEditor;
public bool _showInEditor;

public bool ShowInEditor
{
Expand All @@ -84,9 +80,8 @@ public bool ShowInEditor
}
}

[SerializeField]
[Persistent(pass = (int)Pass.GLOBAL)]
private bool _isOverlay;
public bool _isOverlay;

public bool IsOverlay
{
Expand All @@ -99,9 +94,8 @@ public bool IsOverlay
}
}

[SerializeField]
[Persistent(pass = (int)Pass.GLOBAL)]
private bool _locked;
public bool _locked;

public bool Locked
{
Expand Down
16 changes: 11 additions & 5 deletions MechJeb2/GuiUtils.cs
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using JetBrains.Annotations;
using UnityEngine;
using UnityEngine.Profiling;
using Object = UnityEngine.Object;
Expand All @@ -20,8 +21,9 @@ public interface IEditable
//double so that if you are not doing text input you can treat an EditableDouble like a double.
public class EditableDoubleMult : IEditable
{
[UsedImplicitly]
[Persistent]
protected double _val;
public double _val;

public virtual double val
{
Expand All @@ -37,8 +39,9 @@ public virtual double val

public bool parsed;

[UsedImplicitly]
[Persistent]
protected string _text;
public string _text;

public virtual string text
{
Expand Down Expand Up @@ -168,8 +171,9 @@ public void DrawEditGUI(Direction direction)

public class EditableInt : IEditable
{
[UsedImplicitly]
[Persistent]
private int _val;
public int _val;

public int val
{
Expand All @@ -183,8 +187,9 @@ public int val

private bool _parsed;

[UsedImplicitly]
[Persistent]
private string _text;
public string _text;

public virtual string text
{
Expand Down Expand Up @@ -214,8 +219,9 @@ public class EditableIntList : IEditable
[Persistent]
public readonly List<int> val = new List<int>();

[UsedImplicitly]
[Persistent]
private string _text = "";
public string _text = "";

public string text
{
Expand Down
3 changes: 2 additions & 1 deletion MechJeb2/Maneuver/TimeSelector.cs
Expand Up @@ -20,8 +20,9 @@ public class TimeSelector

private readonly TimeReference[] _allowedTimeRef;

[UsedImplicitly]
[Persistent(pass = (int)Pass.GLOBAL)]
private int _currentTimeRef;
public int _currentTimeRef;

public TimeReference TimeReference => _allowedTimeRef[_currentTimeRef];

Expand Down
6 changes: 4 additions & 2 deletions MechJeb2/MechJebModuleAirplaneGuidance.cs
Expand Up @@ -17,11 +17,13 @@ public MechJebModuleAirplaneGuidance(MechJebCore core) : base(core)
{
}

[UsedImplicitly]
[Persistent(pass = (int)Pass.LOCAL)]
private bool showpid;
public bool showpid;

[UsedImplicitly]
[Persistent(pass = (int)Pass.GLOBAL)]
private EditableDouble AltitudeTargettmp = 0,
public EditableDouble AltitudeTargettmp = 0,
HeadingTargettmp = 90,
RollTargettmp = 0,
SpeedTargettmp = 0,
Expand Down
9 changes: 6 additions & 3 deletions MechJeb2/MechJebModuleAscentMenu.cs
Expand Up @@ -62,11 +62,13 @@ public override void OnStart(PartModule.StartState state)
_classicPathMenu = Core.GetComputerModule<MechJebModuleAscentClassicPathMenu>();
}

[UsedImplicitly]
[Persistent(pass = (int)Pass.GLOBAL)]
private bool _lastPVGSettingsEnabled;
public bool _lastPVGSettingsEnabled;

[UsedImplicitly]
[Persistent(pass = (int)Pass.GLOBAL)]
private bool _lastSettingsMenuEnabled;
public bool _lastSettingsMenuEnabled;

protected override void OnModuleEnabled()
{
Expand Down Expand Up @@ -354,8 +356,9 @@ private void ShowAutoWarpGUIElements()
private string vgo, heading, tgo, pitch, label26, label27, label28, n, label29, znorm, label30, launchTimer, autopilotStatus;
private TimeSpan _refreshInterval = TimeSpan.FromSeconds(0.1);

[UsedImplicitly]
[Persistent(pass = (int)Pass.GLOBAL)]
private EditableInt _refreshRate = 10;
public EditableInt _refreshRate = 10;

private void UpdateStrings()
{
Expand Down
6 changes: 4 additions & 2 deletions MechJeb2/MechJebModuleAscentSettings.cs
Expand Up @@ -59,8 +59,9 @@ public MechJebModuleAscentSettings(MechJebCore core) : base(core)
[Persistent(pass = (int)(Pass.TYPE | Pass.GLOBAL))]
public readonly EditableDoubleMult HoldAPTime = new EditableDoubleMult(1);

[UsedImplicitly]
[Persistent(pass = (int)(Pass.TYPE | Pass.GLOBAL))]
private int _ascentTypeInteger;
public int _ascentTypeInteger;

public AscentType AscentType
{
Expand Down Expand Up @@ -110,8 +111,9 @@ public AscentType AscentType
[Persistent(pass = (int)(Pass.TYPE | Pass.GLOBAL))]
public readonly EditableDouble RollAltitude = new EditableDouble(50);

[UsedImplicitly]
[Persistent(pass = (int)(Pass.TYPE | Pass.GLOBAL))]
private bool _autostage = true;
public bool _autostage = true;

public bool Autostage
{
Expand Down

0 comments on commit a0b239b

Please sign in to comment.