diff --git a/About/About.xml b/About/About.xml index 053a9cc..a629801 100644 --- a/About/About.xml +++ b/About/About.xml @@ -1,6 +1,6 @@  - Infused + Infused (local) Latta & NotFood https://ludeon.com/forums/index.php?topic=21884.0 0.14.1220 diff --git a/DLL/Infused/ICommon/Gens/TextUtility.cs b/DLL/Infused/ICommon/Gens/TextUtility.cs index f191122..90daf9b 100644 --- a/DLL/Infused/ICommon/Gens/TextUtility.cs +++ b/DLL/Infused/ICommon/Gens/TextUtility.cs @@ -110,7 +110,7 @@ private static string NewInfusedThingLabel( Thing thing, bool isStuffed, bool is if ( !inf.PassPre ) { - result.Append( inf.Prefix.ToInfusionDef().label + " " ); + result.Append( inf.Prefix.label + " " ); } string thingLabel; @@ -124,7 +124,7 @@ private static string NewInfusedThingLabel( Thing thing, bool isStuffed, bool is } result.Append( !inf.PassSuf - ? ResourceBank.StringInfusionOf.Translate( thingLabel, inf.Suffix.ToInfusionDef().label.CapitalizeFirst() ) + ? ResourceBank.StringInfusionOf.Translate( thingLabel, inf.Suffix.label.CapitalizeFirst() ) : thingLabel ); if ( !isDetailed ) @@ -160,7 +160,7 @@ public static string GetInfusionDesc( this Thing thing ) var result = new StringBuilder( null ); if ( !inf.PassPre ) { - var prefix = inf.Prefix.ToInfusionDef(); + var prefix = inf.Prefix; result.Append( ResourceBank.StringInfusionDescFrom.Translate( prefix.LabelCap ) ) .Append( " (" ) .Append( prefix.tier.Translate() ) @@ -208,7 +208,7 @@ public static string GetInfusionDesc( this Thing thing ) return result.ToString(); } - var suffix = inf.Suffix.ToInfusionDef(); + var suffix = inf.Suffix; result.Append(ResourceBank.StringInfusionDescFrom.Translate(suffix.LabelCap)) .Append(" (") .Append(suffix.tier.Translate()) diff --git a/DLL/Infused/ICommon/ModInitializers/ModInjector.cs b/DLL/Infused/ICommon/ModInitializers/ModInjector.cs index 5e84b45..fe50489 100644 --- a/DLL/Infused/ICommon/ModInitializers/ModInjector.cs +++ b/DLL/Infused/ICommon/ModInitializers/ModInjector.cs @@ -34,33 +34,25 @@ public override bool Inject() //Inject every prerequisites to defs. private void InjectVarious() { - //Access ThingDef database with each def's defName. - String fieldName = "defsByName"; - FieldInfo field = typeof(DefDatabase< ThingDef >).GetField (fieldName, BindingFlags.NonPublic | BindingFlags.Static); - if (field == null) - throw new ArgumentOutOfRangeException("fieldName", string.Format("Field {0} was not found in Type {1}", fieldName, typeof(DefDatabase< ThingDef >).FullName)); - var defsByName = field.GetValue( null ) as Dictionary< string, ThingDef >; - if ( defsByName == null ) - throw new Exception( "Could not access private members" ); - foreach (var current in defsByName.Values.Where(current => current.IsMeleeWeapon || current.IsRangedWeapon || current.IsApparel)) + foreach (var thingDef in DefDatabase< ThingDef >.AllDefs.Where ( def => def.IsMeleeWeapon || def.IsRangedWeapon || def.IsApparel )) { - if ( AddCompInfusion( current ) ) + if ( AddCompInfusion( thingDef ) ) { - AddInfusionITab( current ); + AddInfusionITab( thingDef ); } } } //Inject new ThingComp. - private static bool AddCompInfusion( ThingDef def ) + private static bool AddCompInfusion( ThingDef thingDef ) { - if ( def.comps.Exists( s => s.compClass == typeof ( CompInfusion ) ) ) + if ( thingDef.comps.Exists( s => s.compClass == typeof ( CompInfusion ) ) ) { - Log.Message ("Infused: Component exists for " + def.label); + Log.Message ("Infused: Component exists for " + thingDef.label); return false; } - if ( !def.comps.Exists( s => s.compClass == typeof ( CompQuality ) ) ) + if ( !thingDef.comps.Exists( s => s.compClass == typeof ( CompQuality ) ) ) { return false; } @@ -68,7 +60,7 @@ private static bool AddCompInfusion( ThingDef def ) //As we are adding, not replacing, we need a fresh CompProperties. //We don't need anything except compClass as CompInfusion does not take anything. var compProperties = new CompProperties {compClass = typeof ( CompInfusion )}; - def.comps.Insert( 0, compProperties ); + thingDef.comps.Insert( 0, compProperties ); #if DEBUG Log.Message ("Infused: Component added to " + def.label); #endif @@ -76,20 +68,20 @@ private static bool AddCompInfusion( ThingDef def ) } //Inject new ITab to given def. - private static void AddInfusionITab( ThingDef def ) + private static void AddInfusionITab( ThingDef thingDef ) { - if ( def.inspectorTabs == null || def.inspectorTabs.Count == 0 ) + if ( thingDef.inspectorTabs == null || thingDef.inspectorTabs.Count == 0 ) { - def.inspectorTabs = new List< Type >(); - def.inspectorTabsResolved = new List< ITab >(); + thingDef.inspectorTabs = new List< Type >(); + thingDef.inspectorTabsResolved = new List< ITab >(); } - if ( def.inspectorTabs.Contains( typeof ( ITab_Infusion ) ) ) + if ( thingDef.inspectorTabs.Contains( typeof ( ITab_Infusion ) ) ) { - Log.Message ("Infused: Tab exists for " + def.label); + Log.Message ("Infused: Tab exists for " + thingDef.label); return; } - def.inspectorTabs.Add( typeof ( ITab_Infusion ) ); - def.inspectorTabsResolved.Add( ITabManager.GetSharedInstance( typeof ( ITab_Infusion ) ) ); + thingDef.inspectorTabs.Add( typeof ( ITab_Infusion ) ); + thingDef.inspectorTabsResolved.Add( ITabManager.GetSharedInstance( typeof ( ITab_Infusion ) ) ); } } } diff --git a/DLL/Infused/Infusions/Comp/CompInfusion.cs b/DLL/Infused/Infusions/Comp/CompInfusion.cs index a9d6e98..e921787 100644 --- a/DLL/Infused/Infusions/Comp/CompInfusion.cs +++ b/DLL/Infused/Infusions/Comp/CompInfusion.cs @@ -8,20 +8,21 @@ namespace Infused { public class CompInfusion : ThingComp { - public bool Infused { - get { return prefix != null || suffix != null; } - } - - public InfusionSet Infusions { - get { return new InfusionSet (prefix, suffix); } - } + private static readonly SoundDef InfusionSound = SoundDef.Named( "Infusion_Infused" ); // Is our infusion newly created? Only for notifications. private bool isNew; - private string prefix, suffix; + private string prefixDefName, suffixDefName; + private InfusionDef prefix, suffix; - private static readonly SoundDef InfusionSound = SoundDef.Named( "Infusion_Infused" ); + public InfusionSet Infusions { + get { return new InfusionSet (prefix, suffix); } + } + + public bool Infused { + get { return prefix != null || suffix != null; } + } public void InitializeInfusionPrefix(QualityCategory qc, TechLevel tech) { @@ -42,7 +43,7 @@ select t Log.Warning ("Infused: Couldn't find any prefixed InfusionDef! Tier: " + tier); prefix = null; } else { - prefix = preTemp.defName; + prefix = preTemp.defName.ToInfusionDef(); } isNew = true; @@ -68,7 +69,7 @@ select t } else { - suffix = preTemp.defName; + suffix = preTemp.defName.ToInfusionDef(); } isNew = true; @@ -114,8 +115,19 @@ public override void PostExposeData() { base.PostExposeData(); - Scribe_Values.LookValue( ref prefix, "prefix", null ); - Scribe_Values.LookValue( ref suffix, "suffix", null ); + // This is ugly, I need a better solution. + if (prefix != null) + prefixDefName = prefix.defName; + if (suffix != null) + suffixDefName = suffix.defName; + + Scribe_Values.LookValue (ref prefixDefName, "prefix", null); + Scribe_Values.LookValue (ref suffixDefName, "suffix", null); + + if (prefix == null) + prefix = prefixDefName.ToInfusionDef (); + if (suffix == null) + suffix = suffixDefName.ToInfusionDef (); #if DEBUG if ( (prefix != null && prefix.ToInfusionDef() == null) || (suffix != null && suffix.ToInfusionDef() == null) ) diff --git a/DLL/Infused/Infusions/InfusionSet.cs b/DLL/Infused/Infusions/InfusionSet.cs index e34b064..6a25119 100644 --- a/DLL/Infused/Infusions/InfusionSet.cs +++ b/DLL/Infused/Infusions/InfusionSet.cs @@ -11,8 +11,8 @@ public bool Equals(InfusionSet other) return string.Equals(Prefix, other.Prefix) && string.Equals(Suffix, other.Suffix); } - public string Prefix; - public string Suffix; + public InfusionDef Prefix; + public InfusionDef Suffix; public bool PassPre { get {return Prefix == null; } @@ -21,7 +21,7 @@ public bool PassSuf { get {return Suffix == null; } } - public InfusionSet(string pre, string suf) + public InfusionSet(InfusionDef pre, InfusionDef suf) { Prefix = pre; Suffix = suf; diff --git a/DLL/Infused/Infusions/MapComponent/MapComponent_InfusionManager.cs b/DLL/Infused/Infusions/MapComponent/MapComponent_InfusionManager.cs index 609fc13..a5c995f 100644 --- a/DLL/Infused/Infusions/MapComponent/MapComponent_InfusionManager.cs +++ b/DLL/Infused/Infusions/MapComponent/MapComponent_InfusionManager.cs @@ -32,8 +32,8 @@ private static void Draw() foreach (var current in InfusionLabelManager.Drawee) { var inf = current.Infusions; - var prefix = inf.Prefix.ToInfusionDef(); - var suffix = inf.Suffix.ToInfusionDef(); + var prefix = inf.Prefix; + var suffix = inf.Suffix; Color color; //When there is only suffix diff --git a/DLL/Infused/Infusions/StatParts/StatPart_InfusionModifier.cs b/DLL/Infused/Infusions/StatParts/StatPart_InfusionModifier.cs index 915b0e1..bb9f6fd 100644 --- a/DLL/Infused/Infusions/StatParts/StatPart_InfusionModifier.cs +++ b/DLL/Infused/Infusions/StatParts/StatPart_InfusionModifier.cs @@ -37,8 +37,8 @@ public override void TransformValue( StatRequest req, ref float val ) } //"Notifier" will notify below lines about the actual StatDef it is adjusting, via XML-written notifier string. //InfusionSet is also string-based, so we have to find the InfusionDef behind it. - var prefix = inf.Prefix.ToInfusionDef(); - var suffix = inf.Suffix.ToInfusionDef(); + var prefix = inf.Prefix; + var suffix = inf.Suffix; //Return if the worker has no stat specified if ( !inf.PassPre && prefix.GetStatValue( stat, out mod ) ) { @@ -73,11 +73,11 @@ protected string WriteExplanation( Thing thing, InfusionSet infusions ) if ( !infusions.PassPre ) { - result.Append( WriteExplanationDetail( thing, infusions.Prefix ) ); + result.Append( WriteExplanationDetail( thing, infusions.Prefix.defName ) ); } if ( !infusions.PassSuf ) { - result.Append( WriteExplanationDetail( thing, infusions.Suffix ) ); + result.Append( WriteExplanationDetail( thing, infusions.Suffix.defName ) ); } return result.ToString(); } diff --git a/DLL/Infused/Infusions/StatParts/StatPart_InfusionWorker.cs b/DLL/Infused/Infusions/StatParts/StatPart_InfusionWorker.cs index f894f91..72c97a3 100644 --- a/DLL/Infused/Infusions/StatParts/StatPart_InfusionWorker.cs +++ b/DLL/Infused/Infusions/StatParts/StatPart_InfusionWorker.cs @@ -36,8 +36,8 @@ public override void TransformValue( StatRequest req, ref float val ) Log.ErrorOnce( "Infused: Could not find notifier's StatDef, which is " + notifier, 3388123 ); return; } - var prefix = inf.Prefix.ToInfusionDef(); - var suffix = inf.Suffix.ToInfusionDef(); + var prefix = inf.Prefix; + var suffix = inf.Suffix; if (!inf.PassPre && prefix.GetStatValue( stat, out mod )) { @@ -69,8 +69,8 @@ public override void TransformValue( StatRequest req, ref float val ) Log.ErrorOnce( "Infused: Could not find notifier's StatDef, which is " + notifier, 3388123 ); continue; } - var prefix = inf.Prefix.ToInfusionDef(); - var suffix = inf.Suffix.ToInfusionDef(); + var prefix = inf.Prefix; + var suffix = inf.Suffix; if (!inf.PassPre && prefix.GetStatValue( stat, out mod )) { diff --git a/DLL/Infused/Infusions/UI/ITab_Infusion.cs b/DLL/Infused/Infusions/UI/ITab_Infusion.cs index 697d60a..5a0a31f 100644 --- a/DLL/Infused/Infusions/UI/ITab_Infusion.cs +++ b/DLL/Infused/Infusions/UI/ITab_Infusion.cs @@ -73,8 +73,8 @@ protected override void FillTab() private static string GetRectLabel() { var infs = SelectedCompInfusion.Infusions; - var preDef = infs.Prefix.ToInfusionDef(); - var sufDef = infs.Suffix.ToInfusionDef(); + var preDef = infs.Prefix; + var sufDef = infs.Suffix; var result = new StringBuilder(); if ( !infs.PassPre )