Skip to content

Commit

Permalink
[adds]
Browse files Browse the repository at this point in the history
+ Some developer build logging to various classes
+ CCL_Log capture stack for nested calls

[fixes]
+ Initial state of defs being changed due to AdvancedResearchDefs

[changes]
+ Injectors are now called directly during the saved game load sequence and new game sequence instead of implicitly by monitoring Scribe.mode
+ The controller for AdvancedResearchDefs now generate dictionaries of original XML data for things that are changed directly (sowTags, etc) which is now used to restore the defs states on new/load game
+ AdvancedResearchDef ResearchConsolidator is now HelpConsodilidator as it is more accurate in it's usage
+ Updated MainMenu buttons to match A15
+ WIP of updating all examples
  • Loading branch information
ForsakenShell committed Dec 2, 2016
1 parent 64db8e0 commit bd2d238
Show file tree
Hide file tree
Showing 94 changed files with 1,323 additions and 573 deletions.
23 changes: 14 additions & 9 deletions DLL_Project/Buildings/Building_AutomatedFactory.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
using System;
// Enable this define to do a whole bunch of debug logging
#if DEVELOPER
//#define _I_AM_A_POTATO_
#endif

using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
Expand Down Expand Up @@ -559,7 +564,7 @@ private void RescanTick()

public void ResetAndReprogramHoppers()
{
#if DEVELOPER
#if _I_AM_A_POTATO_
CCL_Log.Message(
string.Format( "{0}\n{1}", this.ThingID, Environment.StackTrace ),
"Building_AutomatedFactory.ResetAndReprogramHoppers()"
Expand Down Expand Up @@ -1238,7 +1243,7 @@ public bool ConsiderFor( ThingDef product, Pawn pawn )
{
if( consideration.ConsideredBy != pawn )
{
#if DEVELOPER
#if _I_AM_A_POTATO_
CCL_Log.Message(
string.Format(
"{0} could not consider {1} for {2} because it is already reserved by {3} for {4}\n{5}",
Expand All @@ -1256,7 +1261,7 @@ public bool ConsiderFor( ThingDef product, Pawn pawn )
}
}
consideration = new Consideration( pawn, product );
#if DEVELOPER
#if _I_AM_A_POTATO_
CCL_Log.Message(
string.Format( "{0} is now considering {1} for {2}\n{3}", pawn.LabelShort, this.ThingID, product.defName, Environment.StackTrace ),
"Building_AutomatedFactory.ConsiderFor"
Expand Down Expand Up @@ -1335,7 +1340,7 @@ public bool ReserveForUseBy( Pawn pawn, ThingDef product
{
if( consideration.ConsideredBy != pawn )
{
#if DEVELOPER
#if _I_AM_A_POTATO_
CCL_Log.Message(
string.Format(
"{0} could not reserve {1} for {2} because it is already reserved by {3} for {4}\n{5}",
Expand All @@ -1353,7 +1358,7 @@ public bool ReserveForUseBy( Pawn pawn, ThingDef product
}
}
consideration = new Consideration( pawn, product, true );
#if DEVELOPER
#if _I_AM_A_POTATO_
CCL_Log.Message(
string.Format( "{0} has now reserved {1} for {2}\n{3}", pawn.LabelShort, this.ThingID, product.defName, Environment.StackTrace ),
"Building_AutomatedFactory.ReserveForUseBy"
Expand All @@ -1367,7 +1372,7 @@ public bool ReserveForUseBy( Pawn pawn, ThingDef product

private void ReleaseFromUseByInt( Pawn pawn, bool releaseFromManager = false )
{
#if DEVELOPER
#if _I_AM_A_POTATO_
CCL_Log.Message(
string.Format(
"{0} is no longer reserving {1} for {2}\n{3}",
Expand All @@ -1393,7 +1398,7 @@ public void ReleaseFromUseBy( Pawn pawn, bool releaseFro
{
if( !IsReservedBy( pawn ) )
{
#if DEVELOPER
#if _I_AM_A_POTATO_
CCL_Log.Message(
string.Format(
"{0} could not release {1} because it is reserved by {2}\n{3}",
Expand All @@ -1415,7 +1420,7 @@ public Thing TryProduceAndReleaseFor( Pawn pawn, bool rel
//Log.Message( string.Format( "{0}.TryProduceAndReleaseBy( {1} )", this.ThingID, pawn == null ? "null" : pawn.NameStringShort ) );
if( !IsReservedBy( pawn ) )
{
#if DEVELOPER
#if _I_AM_A_POTATO_
CCL_Log.Message(
string.Format(
"{0} could not take from and release {1} because it is reserved by {2}\n{3}",
Expand Down
103 changes: 83 additions & 20 deletions DLL_Project/Classes/Static/CCL_Log.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.IO;
using System.Collections.Generic;

using System.Text;
using Verse;
Expand All @@ -19,6 +20,13 @@ public class LogStream
public int indent;
}

private enum MessageClass
{
Message,
Warning,
Error
}

public const string cclLogFileName = "ccl_log.txt";
private static LogStream cclStream;

Expand Down Expand Up @@ -105,19 +113,19 @@ public static void Write( string s, LogStream stream = null )
}
#endif

public static bool AppendSection( ref StringBuilder s, string str, bool addSectionDivider = true )
public static bool AppendSection( ref StringBuilder s, string str, bool prependSectionDivider = true )
{
if( addSectionDivider )
if( prependSectionDivider )
{
s.Append( " :: " );
}
s.Append( str );
return true;
}

public static bool AppendSectionNewLine( ref StringBuilder s, string str, bool addSectionDivider = true )
public static bool AppendSectionNewLine( ref StringBuilder s, string str, bool prependSectionDivider = true )
{
if( addSectionDivider )
if( prependSectionDivider )
{
s.Append( " :: " );
}
Expand Down Expand Up @@ -165,16 +173,33 @@ private static void AppendTrace( ref StringBuilder s, ModContent
}
*/

public static StringBuilder BaseMessage( string content = null, string category = null )
private static StringBuilder BaseMessage( string content = null, string category = null, MessageClass messageClass = MessageClass.Message )
{
var s = new StringBuilder();
s.Append( Controller.Data.UnityObjectName );

if(
( Current.Game != null )&&
( Find.TickManager != null )
)
{
AppendSection( ref s, string.Format( "TicksGame = {0}", Find.TickManager.TicksGame ) );
}

if( category != null )
{
AppendSection( ref s, category );
}

if( messageClass == MessageClass.Error )
{
AppendSection( ref s, "(Error)" );
}
if( messageClass == MessageClass.Warning )
{
AppendSection( ref s, "(Warning)" );
}

if( content != null )
{
AppendSection( ref s, content );
Expand All @@ -183,41 +208,53 @@ public static StringBuilder BaseMessage( string content = null, string c
return s;
}

private static List<StringBuilder> captureStack = new List<StringBuilder>();
private static StringBuilder captureTarget = null;
private static Verbosity captureVerbosity = Verbosity.Default;

public static bool CaptureBegin( StringBuilder target )
{
if( captureTarget == null )
if( target == null )
{
captureTarget = target;
captureVerbosity = Verbosity.Default;
return true;
CCL_Log.Error( "Cannot set CaptureBegin( target ) to null", "Log Capture" );
return false;
}
if( captureTarget == target )
if( captureStack.Contains( target ) )
{
CCL_Log.Error( "Already capturing log", "Log Capture" );
captureTarget = target;
return true;
}
return false;
captureStack.Insert( 0, target );
captureTarget = captureStack[ 0 ];
return true;
}

public static bool CaptureEnd( StringBuilder target, string status = "" )
{
if( captureTarget == null )
if( captureStack.NullOrEmpty() )
{
CCL_Log.Error( "Log isn't being captured, no need to end capture", "Log Capture" );
return true;
return false;
}
if( captureTarget != target )
if(
( captureStack[ 0 ] != target )&&
( captureTarget != target )
)
{
CCL_Log.Error( "Cannot end a capture on a different object", "Log Capture" );
return false;
}
var captureStatus = status + "\n";
captureTarget.Insert( 0, captureStatus );
captureVerbosity = Verbosity.Default;
captureTarget = null;
if( captureStack[ 0 ] == target )
{
captureStack.RemoveAt( 0 );
}
if( captureTarget == target )
{
captureTarget = captureStack.Count > 0 ? captureStack[ 0 ] : null;
}
return true;
}

Expand All @@ -241,7 +278,7 @@ public static void Message( string content, string category = n
bool prefixNext = false;
if( category != null )
{
prefixNext = AppendSection( ref s, category, false );
prefixNext = AppendSection( ref s, category, prefixNext );
}
AppendSectionNewLine( ref s, content, prefixNext );
}
Expand All @@ -255,7 +292,7 @@ public static void Error( string content, string category = nul
var s = captureTarget;
if( s == null )
{
s = BaseMessage( content, category );
s = BaseMessage( content, category, MessageClass.Error );
Verse.Log.Error( s.ToString() );
#if DEBUG
Write( s.ToString() );
Expand All @@ -264,10 +301,36 @@ public static void Error( string content, string category = nul
else
{
s.Append( "\t" );
bool prefixNext = false;
bool prefixNext = AppendSection( ref s, "(Error)", false );
if( category != null )
{
prefixNext = AppendSection( ref s, category, prefixNext );
}
AppendSectionNewLine( ref s, content, prefixNext );
}
}

/// <summary>
/// Write a warning => Community Core Library :: category(nullable) :: content
/// </summary>
public static void Warning( string content, string category = null )
{
var s = captureTarget;
if( s == null )
{
s = BaseMessage( content, category, MessageClass.Warning );
Verse.Log.Warning( s.ToString() );
#if DEBUG
Write( s.ToString() );
#endif
}
else
{
s.Append( "\t" );
bool prefixNext = AppendSection( ref s, "(Warning)", false );
if( category != null )
{
prefixNext = AppendSection( ref s, category, false );
prefixNext = AppendSection( ref s, category, prefixNext );
}
AppendSectionNewLine( ref s, content, prefixNext );
}
Expand Down
2 changes: 1 addition & 1 deletion DLL_Project/Classes/Static/HelpBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,7 @@ static void ResolveAdvancedResearch()
// Get advanced research database
var advancedResearchDefs =
Controller.Data.AdvancedResearchDefs.Where( a => (
( a.ResearchConsolidator == a )&&
( a.HelpConsolidator == a )&&
( a.HasHelp )
) ).ToList();

Expand Down
9 changes: 8 additions & 1 deletion DLL_Project/CommunityCoreLibrary.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@
<Compile Include="Detours\ThingListGroupHelper.cs" />
<Compile Include="Detours\GenConstruct.cs" />
<Compile Include="Detours\WorkGiver_Warden_DeliverFood.cs" />
<Compile Include="Detours\PreLoadUtility.cs" />
<Compile Include="Detours\RootMap.cs" />
<Compile Include="Detours\PageUtility.cs" />
<Compile Include="SpecialInjectors\PostLoadInjectorTest.cs" />
<Compile Include="Detours\ModLister.cs" />
Expand Down Expand Up @@ -337,6 +337,10 @@
<Compile Include="Extensions\JoyGiver_TakeDrug_Extensions.cs" />
<Compile Include="Detours\DrugAIUtility.cs" />
<Compile Include="Detours\JoyGiver.cs" />
<Compile Include="Detours\Debug\MapPawns.cs" />
<Compile Include="Detours\Debug\ListerThings.cs" />
<Compile Include="Extensions\ThingRequestGroup_Extensions.cs" />
<Compile Include="Detours\Game.cs" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Expand All @@ -355,4 +359,7 @@
</ItemGroup>
<ItemGroup />
<ItemGroup />
<ItemGroup>
<Folder Include="Detours\Debug\" />
</ItemGroup>
</Project>
37 changes: 0 additions & 37 deletions DLL_Project/Controller/Library.cs
Original file line number Diff line number Diff line change
Expand Up @@ -166,43 +166,6 @@ internal static bool IsInGoodState
}
}

internal static void Restart()
{
if( !IsInGoodState )
{
CCL_Log.Error( "Library is not in a valid state but 'Library.Restart' was called!" );
return;
}

// Call controller Initialize() on game load
var subControllers = Controller.Data.SubControllers.ToList();
subControllers.Sort( (x,y) => ( x.InitializationPriority > y.InitializationPriority ) ? -1 : 1 );

foreach( var subsys in subControllers )
{
if( subsys.InitializationPriority != SubController.DontProcessThisPhase )
{
if(
( subsys.State >= SubControllerState._BaseOk )&&
( subsys.ReinitializeOnGameLoad )
)
{
if( !subsys.Initialize() )
{
CCL_Log.Error( subsys.strReturn, subsys.Name + " :: Reinitialization" );
Controller.Data.LibraryOk = false;
return;
}
if( subsys.strReturn != string.Empty )
{
CCL_Log.Message( subsys.strReturn, subsys.Name + " :: Reinitialization" );
}
}
}
}
Controller.Data.LibraryTicks = 0;
}

}

}
4 changes: 0 additions & 4 deletions DLL_Project/Controller/MainMonoBehaviour.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,6 @@ public void FixedUpdate()
return;
}

if( Scribe.mode == LoadSaveMode.LoadingVars )
{
LongEventHandler.QueueLongEvent( Controller.Library.Restart, "Initializing", true, null );
}
if( Scribe.mode != LoadSaveMode.Inactive )
{
// Do nothing while a save/load sequence is happening
Expand Down
Loading

1 comment on commit bd2d238

@ForsakenShell
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a potential fix for issue #168

Please sign in to comment.