Skip to content

Commit

Permalink
Better logging
Browse files Browse the repository at this point in the history
  • Loading branch information
Lisias committed Jun 27, 2021
1 parent 70399c3 commit 7049ab2
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions Source/Refunding/PartModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public class Refunding : PartModule, IPartCostModifier

public override void OnAwake()
{
Log.dbg("OnAwake {0}:{1:X}", this.name, this.part.GetInstanceID());
Log.dbg("OnAwake {0}", this.PartInstanceId);
base.OnAwake();
// Here we have a problem. Some parts have the this.part.partInfo set, others don't.
// Don't know why, and this is worrying - TweakScale depends on this! Is this a race condition?
Expand All @@ -64,19 +64,19 @@ public override void OnAwake()

public override void OnStart(StartState state)
{
Log.dbg("OnStart {0}:{1:X} {2} {3}", this.name, this.part.GetInstanceID(), state, this.active);
Log.dbg("OnStart {0} {1} {2}", this.PartInstanceId, state, this.active);
base.OnStart(state);
}

public override void OnCopy(PartModule fromModule)
{
Log.dbg("OnCopy {0}:{1:X} from {2:X}", this.name, this.part.GetInstanceID(), fromModule.part.GetInstanceID());
Log.dbg("OnCopy {0} from {1:X}", this.PartInstanceId, fromModule.part.GetInstanceID());
base.OnCopy(fromModule);
}

public override void OnLoad(ConfigNode node)
{
Log.dbg("OnLoad {0}:{1:X} {2}", this.name, this.part.GetInstanceID(), null != node);
Log.dbg("OnLoad {0} {1}", this.PartInstanceId, null != node);
base.OnLoad(node);
if (null == this.part.partInfo)
this.prefab = this.part;
Expand Down Expand Up @@ -104,7 +104,7 @@ public override void OnLoad(ConfigNode node)

public override void OnSave(ConfigNode node)
{
Log.dbg("OnSave {0}:{1:X}", this.name, this.part.GetInstanceID());
Log.dbg("OnSave {0}", this.PartInstanceId);
base.OnSave(node);
}

Expand All @@ -116,7 +116,7 @@ private void FixedUpdate()
{
if (!this.active) return;
if (0 != --this.delayTicks) return;
Log.dbg("FixedUpdate {0}:{1:X}", this.name, this.part.GetInstanceID());
Log.dbg("FixedUpdate {0}", this.PartInstanceId);

switch(HighLogic.LoadedScene)
{
Expand All @@ -134,7 +134,7 @@ private void FixedUpdate()

private void OnDestroy()
{
Log.dbg("OnDestroy {0}:{1:X}", this.name, this.part.GetInstanceID());
Log.dbg("OnDestroy {0}", this.PartInstanceId);
}

#endregion
Expand Down Expand Up @@ -202,7 +202,7 @@ internal void SynchronousFullUpdate()

private void Recalculate()
{
Log.dbg("Recalculate {0}:{1:X}", this.name, this.part.GetInstanceID());
Log.dbg("Recalculate {0}", this.PartInstanceId);
if (!this.active)
{
this.costFix = 0;
Expand Down Expand Up @@ -317,7 +317,7 @@ private void UpdateResource()

private void RemoveResourceIfAvailable()
{
Log.dbg("Removing {0} from part {1}-{2}:{3:X}", RESOURCENAME, this.VesselName, this.part.name, this.part.GetInstanceID());
Log.dbg("Removing {0} from part {1}", RESOURCENAME, this.PartInstanceId);

if (null == this.part.Resources) return; // Oukey, this is a bug on KSP ou just an anti-feature? :-(
PartResource pr = this.part.Resources.Get(RESOURCENAME);
Expand Down Expand Up @@ -356,7 +356,7 @@ private bool IsStackable()
}
}

Log.dbg("{0}-{1}:{2:X} is {3}", this.VesselName, this.part.name, this.part.GetInstanceID(), r ? "stackable" : "not stackable");
Log.dbg("{0} is {1}", this.PartInstanceId, r ? "stackable" : "not stackable");
return r;
}

Expand All @@ -382,7 +382,7 @@ private PartResource RestoreResource()
#else
private void RestoreResource()
{
Log.dbg("RestoreResource {0}:{1:X}", this.name, this.part.GetInstanceID());
Log.dbg("RestoreResource {0}", this.PartInstanceId);
PartResource pr = this.part.Resources.Get(RESOURCENAME);
Log.dbg("Before {0} {1} {2} {3}", pr.ToString(), pr.amount, pr.maxAmount, pr.info.unitCost);
pr.SetInfo(PartResourceLibrary.Instance.GetDefinition(RESOURCENAME));
Expand All @@ -407,6 +407,7 @@ private void NotifyResourcesChanged()
// Place holder. Find a way to induce KSP to save the part again.
}

private string PartInstanceId => string.Format("{0}-{1}:{2:X}", this.VesselName, this.part.name, this.part.GetInstanceID());
private string VesselName => null == this.part.vessel ? "<NO VESSEL>" : this.part.vessel.vesselName ;

private static readonly KSPe.Util.Log.Logger Log = KSPe.Util.Log.Logger.CreateForType<Refunding>("KSP-Recall", "Refunding");
Expand Down

0 comments on commit 7049ab2

Please sign in to comment.