Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
siimav committed Sep 8, 2023
2 parents 42dcf3d + 75434f0 commit 1e5181a
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 65 deletions.
54 changes: 0 additions & 54 deletions TestFlightCore/TestFlightCore/Framework/PartModuleExtended.cs
Original file line number Diff line number Diff line change
Expand Up @@ -352,60 +352,6 @@ public virtual void OnDestroy()

#endregion

#region OnGuiStuff
//flag to mark when OnceOnly has been done
private Boolean _OnGUIOnceOnlyHasRun = false;

/// <summary>
/// Unity: OnGUI is called for rendering and handling GUI events.
///
/// Trigger: This is called multiple times per frame to lay stuff out etc.
/// Code here ignores the F2 key that disables user interface. So if you are making something to be user hidable then use the RenderingManager.PostDrawQueue functions in here
/// Alternatively you could use the MonoBehaviourWindow Type and its DrawWindow Function
/// </summary>
public void OnGUI()
{
if (!_OnGUIOnceOnlyHasRun)
{
//set theflag so this only runs once
_OnGUIOnceOnlyHasRun = true;
//set up the skins library
if (!SkinsLibrary._Initialized)
SkinsLibrary.InitSkinList();

//then pass it on to the downstream derivatives
OnGUIOnceOnly();
}

OnGUIEvery();
}

/// <summary>
/// Extension Function - OnGUIEvery is wrapped in OnGUI with some stuff to facilitate the OnGUIOnceOnly functionality, basically this is the OnGUI function
///
/// Unity: OnGUI is called for rendering and handling GUI events.
///
/// Trigger: This is called multiple times per frame to lay stuff out etc.
/// Code here ignores the F2 key that disables user interface. So if you are making something to be user hidable then use the RenderingManager.PostDrawQueue functions in here
/// Alternatively you could use the MonoBehaviourWindow Type and its DrawWindow Function
/// </summary>
internal virtual void OnGUIEvery()
{

}

/// <summary>
/// Extension Function - this will run only once each time the monobehaviour is awakened
///
/// Added this so you can put your GUI initialisation code in here. Running GUI initialisation stuff in Awake/Start will throw an error
/// </summary>
internal virtual void OnGUIOnceOnly()
{
LogFormatted_DebugOnly("Running OnGUI OnceOnly Code");

}
#endregion

#region Assembly/Class Information
/// <summary>
/// Name of the Assembly that is running this MonoBehaviour
Expand Down
2 changes: 1 addition & 1 deletion TestFlightCore/TestFlightCore/TestFlight.cs
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ internal void Log(string message)

internal void LogCareerFailure(Vessel vessel, string part, string failureType)
{
if (!rp1Available || !careerLogging)
if (!rp1Available || !careerLogging || HighLogic.CurrentGame?.Mode != Game.Modes.CAREER)
{
Log("Unable to log career failure. RP1 or Career Logging is unavailable");
return;
Expand Down
32 changes: 23 additions & 9 deletions TestFlightCore/TestFlightCore/TestFlightCore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ public class TestFlightCore : PartModuleExtended, ITestFlightCore

public List<ConfigNode> configs = new List<ConfigNode>(8);
public ConfigNode currentConfig;
public string configNodeData;

bool initialized = false;
float transferData;
Expand Down Expand Up @@ -216,14 +215,13 @@ public override void OnLoad(ConfigNode node)
{
configs.Clear();

foreach (ConfigNode subNode in cNodes) {
foreach (ConfigNode subNode in cNodes)
{
var newNode = new ConfigNode("CONFIG");
subNode.CopyTo(newNode);
configs.Add(newNode);
}
}

configNodeData = node.ToString();
}

internal void Log(string message)
Expand Down Expand Up @@ -833,13 +831,13 @@ public override void OnDestroy()
public override void OnAwake()
{
initialized = false;

if (!string.IsNullOrEmpty(configNodeData))

TestFlightCore pm = GetCoreFromPrefab();
if (pm != null)
{
var node = ConfigNode.Parse(configNodeData);
OnLoad(node);
configs = pm.configs;
}

// poll failure modules for any existing failures
foreach (ITestFlightFailure failure in TestFlightUtil.GetFailureModules(this.part, Alias))
{
Expand All @@ -851,6 +849,22 @@ public override void OnAwake()
}
}

private TestFlightCore GetCoreFromPrefab()
{
Part prefab = part?.partInfo?.partPrefab;
if (prefab != null)
{
int index = part.Modules.IndexOf(this);
if (index < 0)
index = part.Modules.Count;

var pm = prefab.Modules.Count > index ? prefab.Modules[index] as TestFlightCore : null;
return pm ?? prefab.FindModuleImplementing<TestFlightCore>();
}

return null;
}

public void OnCrewChange(GameEvents.HostedFromToAction<ProtoCrewMember, Part> e) => _OnCrewChange();
private void _OnCrewChange()
{
Expand Down
2 changes: 1 addition & 1 deletion TestFlightFailure_IgnitionFail.cs
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ public override void DoFailure()
if (!TestFlightEnabled)
return;
Failed = true;
float multiplier = 0;
float multiplier = 1f;
ITestFlightCore core = TestFlightUtil.GetCore(this.part, Configuration);
if (core != null)
{
Expand Down

0 comments on commit 1e5181a

Please sign in to comment.