From a698a4add8f70479dfee216651626279922728b4 Mon Sep 17 00:00:00 2001 From: edbmods Date: Sat, 14 Mar 2020 15:00:53 -0700 Subject: [PATCH 01/10] Added better error handling and tool tip caching for the traits panel --- Source/PanelTraits.cs | 102 +++++++++++++++++++++++++++++++----------- 1 file changed, 76 insertions(+), 26 deletions(-) diff --git a/Source/PanelTraits.cs b/Source/PanelTraits.cs index d67814f..0577a73 100644 --- a/Source/PanelTraits.cs +++ b/Source/PanelTraits.cs @@ -31,8 +31,34 @@ public class PanelTraits : PanelBase { protected Rect RectScrollFrame; protected Rect RectScrollView; + public class TipCache { + public Dictionary Lookup = new Dictionary(); + private CustomPawn pawn = null; + private bool ready = false; + public void CheckPawn(CustomPawn pawn) { + if (this.pawn != pawn) { + this.pawn = pawn; + Invalidate(); + } + } + public void Invalidate() { + this.ready = false; + Lookup.Clear(); + } + public void MakeReady() { + this.ready = true; + } + public bool Ready { + get { + return ready; + } + } + } + protected TipCache tipCache = new TipCache(); + public PanelTraits() { } + public override string PanelHeader { get { return "Traits".Translate(); @@ -54,6 +80,8 @@ public override void Resize(Rect rect) { protected override void DrawPanelContent(State state) { CustomPawn currentPawn = state.CurrentPawn; + tipCache.CheckPawn(currentPawn); + if (currentPawn.TraitCount > Constraints.MaxVanillaTraits) { Warning = "EdB.PC.Panel.Traits.Warning.TooManyTraits".Translate(); } @@ -180,6 +208,8 @@ protected override void DrawPanelContent(State state) { GUI.EndGroup(); } + tipCache.MakeReady(); + GUI.color = Color.white; if (clickAction != null) { @@ -198,6 +228,7 @@ protected override void DrawPanelContent(State state) { GUI.DrawTexture(randomizeRect, Textures.TextureButtonRandom); if (Widgets.ButtonInvisible(randomizeRect, false)) { SoundDefOf.Tick_Low.PlayOneShotOnCamera(); + tipCache.Invalidate(); TraitsRandomized(); } @@ -234,6 +265,7 @@ protected override void DrawPanelContent(State state) { CloseAction = () => { if (selectedTrait != null) { TraitAdded(selectedTrait); + tipCache.Invalidate(); } } }; @@ -245,42 +277,60 @@ protected override void DrawPanelContent(State state) { TraitRemoved(trait); } traitsToRemove.Clear(); + tipCache.Invalidate(); } } protected string GetTraitTip(Trait trait, CustomPawn pawn) { - string baseTip = trait.TipString(pawn.Pawn); - string conflictingNames = null; - if (!conflictingTraitList.TryGetValue(trait, out conflictingNames)) { - List conflictingTraits = providerTraits.Traits.Where((Trait t) => { - return trait.def.conflictingTraits.Contains(t.def) || (t.def == trait.def && t.Label != trait.Label); - }).ToList(); - if (conflictingTraits.Count == 0) { - conflictingTraitList.Add(trait, null); - } - else { - conflictingNames = ""; - if (conflictingTraits.Count == 1) { - conflictingNames = "EdB.PC.Panel.Traits.Tip.Conflict.List.1".Translate(conflictingTraits[0].LabelCap); - } - else if (conflictingTraits.Count == 2) { - conflictingNames = "EdB.PC.Panel.Traits.Tip.Conflict.List.2".Translate(conflictingTraits[0].LabelCap, conflictingTraits[1].LabelCap); + if (!tipCache.Ready || !tipCache.Lookup.ContainsKey(trait)) { + string value = GenerateTraitTip(trait, pawn); + tipCache.Lookup.Add(trait, value); + return value; + } + else { + return tipCache.Lookup[trait]; + } + } + + protected string GenerateTraitTip(Trait trait, CustomPawn pawn) { + try { + string baseTip = trait.TipString(pawn.Pawn); + string conflictingNames = null; + if (!conflictingTraitList.TryGetValue(trait, out conflictingNames)) { + List conflictingTraits = providerTraits.Traits.Where((Trait t) => { + return trait.def.conflictingTraits.Contains(t.def) || (t.def == trait.def && t.Label != trait.Label); + }).ToList(); + if (conflictingTraits.Count == 0) { + conflictingTraitList.Add(trait, null); } else { - int c = conflictingTraits.Count; - conflictingNames = "EdB.PC.Panel.Traits.Tip.Conflict.List.Last".Translate(conflictingTraits[c - 2].LabelCap, conflictingTraits[c - 1].LabelCap); - for (int i = c - 3; i >= 0; i--) { - conflictingNames = "EdB.PC.Panel.Traits.Tip.Conflict.List.Many".Translate(conflictingTraits[i].LabelCap, conflictingNames); + conflictingNames = ""; + if (conflictingTraits.Count == 1) { + conflictingNames = "EdB.PC.Panel.Traits.Tip.Conflict.List.1".Translate(conflictingTraits[0].LabelCap); + } + else if (conflictingTraits.Count == 2) { + conflictingNames = "EdB.PC.Panel.Traits.Tip.Conflict.List.2".Translate(conflictingTraits[0].LabelCap, conflictingTraits[1].LabelCap); } + else { + int c = conflictingTraits.Count; + conflictingNames = "EdB.PC.Panel.Traits.Tip.Conflict.List.Last".Translate(conflictingTraits[c - 2].LabelCap, conflictingTraits[c - 1].LabelCap); + for (int i = c - 3; i >= 0; i--) { + conflictingNames = "EdB.PC.Panel.Traits.Tip.Conflict.List.Many".Translate(conflictingTraits[i].LabelCap, conflictingNames); + } + } + conflictingTraitList.Add(trait, conflictingNames); } - conflictingTraitList.Add(trait, conflictingNames); + } + if (conflictingNames == null) { + return baseTip; + } + else { + return "EdB.PC.Panel.Traits.Tip.Conflict".Translate(baseTip, conflictingNames).Resolve(); } } - if (conflictingNames == null) { - return baseTip; - } - else { - return "EdB.PC.Panel.Traits.Tip.Conflict".Translate(baseTip, conflictingNames); + catch (Exception e) { + Logger.Warning("There was an error when trying to generate a mouseover tip for trait {" + (trait?.LabelCap ?? "null") + "}\n" + e); + return null; } } From 2cdfca511d10b6ea6b7f0bdbcabb91c51ddc9d0f Mon Sep 17 00:00:00 2001 From: edbmods Date: Sat, 14 Mar 2020 15:10:24 -0700 Subject: [PATCH 02/10] Added TaggedString resolution to backstory tooltips --- Source/ExtensionsBackstory.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Source/ExtensionsBackstory.cs b/Source/ExtensionsBackstory.cs index a95a777..6d38c99 100644 --- a/Source/ExtensionsBackstory.cs +++ b/Source/ExtensionsBackstory.cs @@ -17,10 +17,10 @@ public static string CheckedDescriptionFor(this Backstory backstory, Pawn pawn) if (ProblemBackstories.Contains(backstory.untranslatedTitle)) { return PartialDescriptionFor(backstory); } - string description = backstory.FullDescriptionFor(pawn); + string description = backstory.FullDescriptionFor(pawn).Resolve(); if (description.StartsWith("Could not resolve")) { return PartialDescriptionFor(backstory); - //Log.Message("Failed to resolve description for backstory with this pawn: " + backstory.title + ", " + backstory.identifier); + //Logger.Debug("Failed to resolve description for backstory with this pawn: " + backstory.title + ", " + backstory.identifier); } return description; } From 7c40fe10597356e7531a2e344de0324c9ea7792d Mon Sep 17 00:00:00 2001 From: edbmods Date: Mon, 16 Mar 2020 19:40:53 -0700 Subject: [PATCH 03/10] Fix for faction apparel exceptions when loading presets. --- Source/Logger.cs | 10 +++++- Source/PawnCompRules.cs | 1 + Source/PawnCompsSaver.cs | 3 ++ Source/Version5/PawnLoaderV5.cs | 55 +++++++++++++++++++++++++++++++-- 4 files changed, 65 insertions(+), 4 deletions(-) diff --git a/Source/Logger.cs b/Source/Logger.cs index e79c963..a6226d1 100644 --- a/Source/Logger.cs +++ b/Source/Logger.cs @@ -8,7 +8,7 @@ public static class Logger { public static void Debug(string message) { if (DebugEnabled) { - Log.Message(message); + Log.Message("" + message + ""); } } @@ -20,9 +20,17 @@ public static void Warning(string message) { Log.Warning(Prefix + message); } + public static void Warning(string message, Exception e) { + Log.Warning(Prefix + message + "\n" + e); + } + public static void Error(string message) { Log.Error(Prefix + message); } + + public static void Error(string message, Exception e) { + Log.Error(Prefix + message + "\n" + e); + } } } diff --git a/Source/PawnCompRules.cs b/Source/PawnCompRules.cs index 53541aa..37a8d57 100644 --- a/Source/PawnCompRules.cs +++ b/Source/PawnCompRules.cs @@ -89,6 +89,7 @@ public static void InitializeRulesForSaving() { .IncludeComp("VanillaHairExpanded.CompBeard") .IncludeComp("Psychology.CompPsychology") .IncludeComp("GradientHair.CompGradientHair") + .IncludeCompWithPrefix("ReviaRace.") .ExcludeField("pawnFaction"); } diff --git a/Source/PawnCompsSaver.cs b/Source/PawnCompsSaver.cs index a3c6a72..8964448 100644 --- a/Source/PawnCompsSaver.cs +++ b/Source/PawnCompsSaver.cs @@ -32,6 +32,9 @@ public void ExposeData() { comp.PostExposeData(); savedComps.Add(comp.GetType().FullName); } + else { + //Logger.Debug("Excluded comp: " + comp.GetType().FullName); + } } } } diff --git a/Source/Version5/PawnLoaderV5.cs b/Source/Version5/PawnLoaderV5.cs index 352831a..757546e 100644 --- a/Source/Version5/PawnLoaderV5.cs +++ b/Source/Version5/PawnLoaderV5.cs @@ -143,18 +143,61 @@ public CustomPawn ConvertSaveRecordToPawn(SaveRecordPawnV5 record) { if (thingDef != null) { pawnThingDef = thingDef; } + else { + Logger.Warning("Pawn's thing definition {" + record.thingDef + "} was not found. Defaulting to the thing definition for humans."); + } + } + else { + Logger.Warning("Pawn's thing definition was null. Defaulting to the thing definition for humans."); } + // Create the pawn generation request. PawnGenerationRequestWrapper generationRequest = new PawnGenerationRequestWrapper() { FixedBiologicalAge = record.biologicalAge, FixedChronologicalAge = record.chronologicalAge, FixedGender = record.gender }; - + // Add a faction to the generation request, if possible. + if (record.originalFactionDef != null) { + FactionDef factionDef = DefDatabase.GetNamedSilentFail(record.originalFactionDef); + if (factionDef != null) { + Faction faction = PrepareCarefully.Instance.Providers.Factions.GetFaction(factionDef); + if (faction != null) { + generationRequest.Faction = faction; + } + else { + Logger.Warning("No faction found for faction definition {" + record.originalFactionDef + "}"); + } + } + else { + Logger.Warning("No faction defition defition found for {" + record.originalFactionDef + "}"); + } + } + // Add a pawn kind definition to the generation request, if possible. if (pawnKindDef != null) { generationRequest.KindDef = pawnKindDef; } - Pawn source = PawnGenerator.GeneratePawn(generationRequest.Request); + + // Create the pawn. + Pawn source = null; + try { + source = PawnGenerator.GeneratePawn(generationRequest.Request); + } + catch (Exception e) { + Logger.Warning("Failed to generate a pawn from preset for pawn {" + (record.nickName) + "}. Will try to create it using fallback settings", e); + generationRequest = new PawnGenerationRequestWrapper() { + FixedBiologicalAge = record.biologicalAge, + FixedChronologicalAge = record.chronologicalAge, + FixedGender = record.gender + }; + try { + source = PawnGenerator.GeneratePawn(generationRequest.Request); + } + catch (Exception) { + Logger.Warning("Failed to generate a pawn using fallback settings from preset for pawn {" + (record.nickName) + "}", e); + return null; + } + } if (source.health != null) { source.health.Reset(); @@ -201,7 +244,13 @@ public CustomPawn ConvertSaveRecordToPawn(SaveRecordPawnV5 record) { } pawn.OriginalKindDef = pawnKindDef; - if (pawn.Type == CustomPawnType.World) { + if (pawn.Type == CustomPawnType.Colonist) { + Faction playerFaction = Faction.OfPlayerSilentFail; + if (playerFaction != null) { + pawn.Pawn.SetFactionDirect(playerFaction); + } + } + else if (pawn.Type == CustomPawnType.World) { if (record.faction != null) { if (record.faction.def != null) { FactionDef factionDef = DefDatabase.GetNamedSilentFail(record.faction.def); From 2bcac7ef798333b68d67fc509efcdb586c20615a Mon Sep 17 00:00:00 2001 From: edbmods Date: Mon, 16 Mar 2020 22:23:04 -0700 Subject: [PATCH 04/10] Incremented version number to 1.1.9 --- Properties/AssemblyInfo.cs | 2 +- Resources/About/About.xml | 2 +- Resources/About/Manifest.xml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Properties/AssemblyInfo.cs b/Properties/AssemblyInfo.cs index fe77e68..6ea4ffa 100644 --- a/Properties/AssemblyInfo.cs +++ b/Properties/AssemblyInfo.cs @@ -14,4 +14,4 @@ [assembly: AssemblyVersion("1.1.1")] // Increment for each new release -[assembly: AssemblyFileVersion("1.1.8")] +[assembly: AssemblyFileVersion("1.1.9")] diff --git a/Resources/About/About.xml b/Resources/About/About.xml index 2608cd2..a8c1829 100644 --- a/Resources/About/About.xml +++ b/Resources/About/About.xml @@ -12,6 +12,6 @@ If you get a set of starting colonists that you like, save them as a preset so that you can start your game the same way next time. -[Version 1.1.8] +[Version 1.1.9] \ No newline at end of file diff --git a/Resources/About/Manifest.xml b/Resources/About/Manifest.xml index 184d3ca..fdb5c4f 100644 --- a/Resources/About/Manifest.xml +++ b/Resources/About/Manifest.xml @@ -1,7 +1,7 @@ EdBPrepareCarefully - 1.1.8 + 1.1.9
  • Core
  • HugsLib
  • From c63e7236a54d751edff29c04934bb20378a12b8d Mon Sep 17 00:00:00 2001 From: edbmods Date: Tue, 17 Mar 2020 09:30:07 -0700 Subject: [PATCH 05/10] Improved how we distinguish implant hediffs from injuries. --- Source/ProviderHealthOptions.cs | 79 +++++++++++++++++---------------- 1 file changed, 40 insertions(+), 39 deletions(-) diff --git a/Source/ProviderHealthOptions.cs b/Source/ProviderHealthOptions.cs index da3aa22..328f6b8 100644 --- a/Source/ProviderHealthOptions.cs +++ b/Source/ProviderHealthOptions.cs @@ -172,53 +172,54 @@ protected void InitializeInjuryOptions(OptionsHealth options, ThingDef pawnThing // Add injury options. foreach (var hd in DefDatabase.AllDefs) { - // TODO: Missing body part seems to be a special case. The hediff giver doesn't itself remove - // limbs, so disable it until we can add special-case handling. - if (hd.defName == "MissingBodyPart") { - continue; - } - // Filter out defs that were already added via the hediff giver sets. - if (addedDefs.Contains(hd)) { - continue; - } - // Filter out implants. - if (hd.hediffClass == typeof(Hediff_AddedPart)) { - continue; - } - - // If it's an old injury, use the old injury properties to get the label. - HediffCompProperties p = hd.CompPropsFor(typeof(HediffComp_GetsPermanent)); - HediffCompProperties_GetsPermanent getsPermanentProperties = p as HediffCompProperties_GetsPermanent; - String label; - if (getsPermanentProperties != null) { - if (getsPermanentProperties.permanentLabel != null) { - label = getsPermanentProperties.permanentLabel.CapitalizeFirst(); + try { + // TODO: Missing body part seems to be a special case. The hediff giver doesn't itself remove + // limbs, so disable it until we can add special-case handling. + if (hd.defName == "MissingBodyPart") { + continue; } - else { - Log.Warning("Prepare Carefully could not find label for old injury: " + hd.defName); + // Filter out defs that were already added via the hediff giver sets. + if (addedDefs.Contains(hd)) { continue; } - } - // If it's not an old injury, make sure it's one of the available hediffs that can - // be added via ScenPart_ForcedHediff. If it's not, filter it out. - else { - if (!scenPartDefSet.Contains(hd)) { + // Filter out implants. + if (hd.hediffClass != null && typeof(Hediff_Implant).IsAssignableFrom(hd.hediffClass)) { continue; } - label = hd.LabelCap; - } - // Add the injury option.. - InjuryOption option = new InjuryOption(); - option.HediffDef = hd; - option.Label = label; - if (getsPermanentProperties != null) { - option.IsOldInjury = true; + // If it's an old injury, use the old injury properties to get the label. + HediffCompProperties p = hd.CompPropsFor(typeof(HediffComp_GetsPermanent)); + HediffCompProperties_GetsPermanent getsPermanentProperties = p as HediffCompProperties_GetsPermanent; + String label; + if (getsPermanentProperties != null) { + if (getsPermanentProperties.permanentLabel != null) { + label = getsPermanentProperties.permanentLabel.CapitalizeFirst(); + } + else { + Log.Warning("Prepare Carefully could not find label for old injury: " + hd.defName); + continue; + } + } + else { + label = hd.LabelCap; + } + + // Add the injury option.. + InjuryOption option = new InjuryOption(); + option.HediffDef = hd; + option.Label = label; + if (getsPermanentProperties != null) { + option.IsOldInjury = true; + } + else { + option.ValidParts = new List(); + } + options.AddInjury(option); } - else { - option.ValidParts = new List(); + catch (Exception e) { + Logger.Warning("There was en error while processing hediff {" + hd.defName + "} when trying to add it to the list of available injury options", e); + continue; } - options.AddInjury(option); } // Disambiguate duplicate injury labels. From f4f26dfb873887147d0b6d96aa5238ae7496d87c Mon Sep 17 00:00:00 2001 From: edbmods Date: Wed, 18 Mar 2020 18:09:06 -0700 Subject: [PATCH 06/10] Equipment initialization no longer creates Things for each item and animal. --- Source/CostCalculator.cs | 76 +++++++------------------- Source/EquipmentDatabase.cs | 89 ++++++++++++++----------------- Source/EquipmentRecord.cs | 18 +++---- Source/Logger.cs | 2 +- Source/PanelEquipmentAvailable.cs | 13 +++-- Source/PanelEquipmentSelected.cs | 2 +- Source/WidgetEquipmentIcon.cs | 9 +--- 7 files changed, 81 insertions(+), 128 deletions(-) diff --git a/Source/CostCalculator.cs b/Source/CostCalculator.cs index 3527f7c..b81c28b 100644 --- a/Source/CostCalculator.cs +++ b/Source/CostCalculator.cs @@ -86,6 +86,7 @@ public void ComputeTotal() { public class CostCalculator { protected HashSet freeApparel = new HashSet(); protected HashSet cheapApparel = new HashSet(); + StatWorker statWorker = null; public CostCalculator() { cheapApparel.Add("Apparel_Pants"); @@ -247,64 +248,28 @@ public double CalculateEquipmentCost(EquipmentSelection equipment) { } } - /* - public double CalculateAnimalCost(SelectedAnimal animal) { - AnimalRecord record = PrepareCarefully.Instance.AnimalDatabase.FindAnimal(animal.Key); - if (record != null) { - return (double)animal.Count * record.Cost; - } - else { - return 0; + public double GetAnimalCost(Thing thing) { + if (statWorker == null) { + StatDef marketValueStatDef = StatDefOf.MarketValue; + statWorker = marketValueStatDef.Worker; } + float value = statWorker.GetValue(StatRequest.For(thing)); + return value; } - */ public double GetBaseThingCost(ThingDef def, ThingDef stuffDef) { - if (def == null) { - Log.Warning("Prepare Carefully is trying to calculate the cost of a null ThingDef"); - return 0; + double value = 0; + if (stuffDef != null) { + value = StatWorker_MarketValue.CalculatedBaseMarketValue(def, stuffDef); } - if (def.BaseMarketValue > 0) { - if (stuffDef == null) { - return def.BaseMarketValue; - } - else { - // EVERY RELEASE: - // Should look at ThingMaker.MakeThing() to decide which validations we need to do - // before calling that method. That method doesn't do null checks everywhere, so we - // may need to do those validations ourselves to avoid null pointer exceptions. - // Should re-evaluate for each new release. - if (def.thingClass == null) { - Log.Warning("Prepare Carefully trying to calculate the cost of a ThingDef with null thingClass: " + def.defName); - return 0; - } - if (def.MadeFromStuff && stuffDef == null) { - Log.Warning("Prepare Carefully trying to calculate the cost of a \"made-from-stuff\" ThingDef without specifying any stuff: " + def.defName); - return 0; - } - - try { - // TODO: Creating an instance of a thing may not be the best way to calculate - // its market value. It may be considered a relatively expensive operation, - // especially when a lot of mods are enabled. There may be a lower-level set of - // methods in the vanilla codebase that could be called. Should investigate. - Thing thing = ThingMaker.MakeThing(def, stuffDef); - if (thing == null) { - Log.Warning("Prepare Carefully failed when calling MakeThing(" + def.defName + ", ...) to calculate a ThingDef's market value"); - return 0; - } - return thing.MarketValue; - } - catch (Exception e) { - Log.Warning("Prepare Carefully failed to calculate the cost of a ThingDef (" + def.defName + "): "); - Log.Warning(e.ToString()); - return 0; - } - } + if (value == 0) { + value = def.BaseMarketValue; } - else { - return 0; + if (value > 100) { + value = Math.Round(value / 5.0) * 5.0; } + value = Math.Round(value, 2); + return value; } public double CalculateStackCost(ThingDef def, ThingDef stuffDef, double baseCost) { @@ -312,19 +277,18 @@ public double CalculateStackCost(ThingDef def, ThingDef stuffDef, double baseCos if (def.MadeFromStuff) { if (def.IsApparel) { - cost = cost * 1; + cost *= 1; } else { - cost = cost * 0.5; + cost *= 0.5; } } if (def.IsRangedWeapon) { - cost = cost * 2; + cost *= 2; } - //cost = cost * 1.25; - cost = Math.Round(cost, 1); + cost = Math.Round(cost, 2); return cost; } diff --git a/Source/EquipmentDatabase.cs b/Source/EquipmentDatabase.cs index 4abe2de..dce8fbf 100644 --- a/Source/EquipmentDatabase.cs +++ b/Source/EquipmentDatabase.cs @@ -223,6 +223,12 @@ public EquipmentType ClassifyThingDef(ThingDef def) { if (def.isUnfinishedThing) { return TypeDiscard; } + if (!def.scatterableOnMapGen) { + return TypeDiscard; + } + if (def.destroyOnDrop) { + return TypeDiscard; + } if (BelongsToCategoryOrParentCategory(def, ThingCategoryDefOf.Corpses)) { return TypeDiscard; } @@ -235,20 +241,21 @@ public EquipmentType ClassifyThingDef(ThingDef def) { if (def.IsFrame) { return TypeDiscard; } - if (BelongsToCategory(def, "Toy")) { - return TypeResources; + if (def.plant != null) { + return TypeDiscard; + } + if (def.IsApparel) { + return TypeApparel; } if (def.weaponTags != null && def.weaponTags.Count > 0 && def.IsWeapon) { return TypeWeapons; } + if (BelongsToCategory(def, "Toy")) { + return TypeResources; + } if (BelongsToCategoryContaining(def, "Weapon")) { return TypeWeapons; } - - if (def.IsApparel && !def.destroyOnDrop) { - return TypeApparel; - } - if (BelongsToCategory(def, "Foods")) { return TypeFood; } @@ -515,7 +522,7 @@ public EquipmentRecord AddThingDefWithStuff(ThingDef def, ThingDef stuff, Equipm return null; } EquipmentKey key = new EquipmentKey(def, stuff); - EquipmentRecord entry = CreateEquipmentEntry(def, stuff, type); + EquipmentRecord entry = CreateEquipmentRecord(def, stuff, type); if (entry != null) { AddRecordIfNotThereAlready(key, entry); } @@ -546,7 +553,7 @@ protected void AddThingDef(ThingDef def, EquipmentType type) { foreach (var s in stuff) { if (s.stuffProps.CanMake(def)) { EquipmentKey key = new EquipmentKey(def, s); - EquipmentRecord entry = CreateEquipmentEntry(def, s, type); + EquipmentRecord entry = CreateEquipmentRecord(def, s, type); if (entry != null) { AddRecordIfNotThereAlready(key, entry); } @@ -555,18 +562,18 @@ protected void AddThingDef(ThingDef def, EquipmentType type) { } else if (def.race != null && def.race.Animal) { if (def.race.hasGenders) { - EquipmentRecord femaleEntry = CreateEquipmentEntry(def, Gender.Female, type); + EquipmentRecord femaleEntry = CreateAnimalEquipmentRecord(def, Gender.Female); if (femaleEntry != null) { AddRecordIfNotThereAlready(new EquipmentKey(def, Gender.Female), femaleEntry); } - EquipmentRecord maleEntry = CreateEquipmentEntry(def, Gender.Male, type); + EquipmentRecord maleEntry = CreateAnimalEquipmentRecord(def, Gender.Male); if (maleEntry != null) { AddRecordIfNotThereAlready(new EquipmentKey(def, Gender.Male), maleEntry); } } else { EquipmentKey key = new EquipmentKey(def, Gender.None); - EquipmentRecord entry = CreateEquipmentEntry(def, Gender.None, type); + EquipmentRecord entry = CreateAnimalEquipmentRecord(def, Gender.None); if (entry != null) { AddRecordIfNotThereAlready(key, entry); } @@ -574,28 +581,38 @@ protected void AddThingDef(ThingDef def, EquipmentType type) { } else { EquipmentKey key = new EquipmentKey(def, null); - EquipmentRecord entry = CreateEquipmentEntry(def, null, Gender.None, type); + EquipmentRecord entry = CreateEquipmentRecord(def, null, type); if (entry != null) { AddRecordIfNotThereAlready(key, entry); } } } - protected EquipmentRecord CreateEquipmentEntry(ThingDef def, ThingDef stuffDef, EquipmentType type) { - return CreateEquipmentEntry(def, stuffDef, Gender.None, type); - } - - protected EquipmentRecord CreateEquipmentEntry(ThingDef def, Gender gender, EquipmentType type) { - return CreateEquipmentEntry(def, null, gender, type); + protected EquipmentRecord CreateAnimalEquipmentRecord(ThingDef def, Gender gender) { + if (def.BaseMarketValue == 0) { + //Logger.Debug("Animal base market value was zero: " + def.defName); + return null; + } + EquipmentRecord result = new EquipmentRecord() { + type = TypeAnimals, + def = def, + stuffDef = null, + stackSize = 1, + stacks = false, + gear = false, + animal = true, + cost = def.BaseMarketValue, + gender = gender + }; + return result; } - protected EquipmentRecord CreateEquipmentEntry(ThingDef def, ThingDef stuffDef, Gender gender, EquipmentType type) { + protected EquipmentRecord CreateEquipmentRecord(ThingDef def, ThingDef stuffDef, EquipmentType type) { double baseCost = costs.GetBaseThingCost(def, stuffDef); if (baseCost == 0) { return null; } int stackSize = CalculateStackCount(def, baseCost); - EquipmentRecord result = new EquipmentRecord(); result.type = type; result.def = def; @@ -652,25 +669,6 @@ protected EquipmentRecord CreateEquipmentEntry(ThingDef def, ThingDef stuffDef, result.hideFromPortrait = true; } - if (def.race != null && def.race.Animal) { - result.animal = true; - result.gender = gender; - try { - Pawn pawn = CreatePawn(def, stuffDef, gender); - if (pawn == null) { - return null; - } - else { - result.thing = pawn; - } - } - catch (Exception e) { - Log.Warning("Prepare Carefully failed to create a pawn for animal equipment entry: " + def.defName); - Log.Message(" Exception message: " + e); - return null; - } - } - return result; } @@ -680,9 +678,7 @@ public int CalculateStackCount(ThingDef def, double basePrice) { } public Pawn CreatePawn(ThingDef def, ThingDef stuffDef, Gender gender) { - PawnKindDef kindDef = (from td in DefDatabase.AllDefs - where td.race == def - select td).FirstOrDefault(); + PawnKindDef kindDef = (from td in DefDatabase.AllDefs where td.race == def select td).FirstOrDefault(); RulePackDef nameGenerator = kindDef.RaceProps.GetNameGenerator(gender); if (nameGenerator == null) { @@ -696,22 +692,15 @@ public Pawn CreatePawn(ThingDef def, ThingDef stuffDef, Gender gender) { KindDef = kindDef, Faction = faction, MustBeCapableOfViolence = true - }.Request; messageCount = ReflectionUtil.GetNonPublicStatic(typeof(Log), "messageCount"); Pawn pawn = PawnGenerator.GeneratePawn(request); - if (ReflectionUtil.GetNonPublicStatic(typeof(Log), "messageCount") > messageCount) { - Log.Warning("Prepare Carefully failed to generate a pawn/animal for the equipment list: " + def.defName); - } if (pawn.Dead || pawn.Downed) { return null; } pawn.gender = gender; messageCount = ReflectionUtil.GetNonPublicStatic(typeof(Log), "messageCount"); pawn.Drawer.renderer.graphics.ResolveAllGraphics(); - if (ReflectionUtil.GetNonPublicStatic(typeof(Log), "messageCount") > messageCount) { - Log.Warning("Prepare Carefully failed to load all graphics for equipment list pawn/animal: " + def.defName); - } return pawn; } else { diff --git a/Source/EquipmentRecord.cs b/Source/EquipmentRecord.cs index 1e87b4a..0dbc95e 100644 --- a/Source/EquipmentRecord.cs +++ b/Source/EquipmentRecord.cs @@ -1,4 +1,4 @@ -using RimWorld; +using RimWorld; using System; using UnityEngine; using Verse; @@ -8,7 +8,7 @@ public class EquipmentRecord { public ThingDef def; public ThingDef stuffDef = null; public Gender gender = Gender.None; - public Thing thing = null; + //public Thing thing = null; public EquipmentType type; public int stackSize; public double cost = 0; @@ -28,7 +28,7 @@ public bool Minifiable { public string Label { get { if (label == null) { - if (thing != null && animal == true) { + if (animal) { return LabelForAnimal; } else { @@ -44,7 +44,7 @@ public string Label { public string LabelNoCount { get { if (label == null) { - if (thing != null && animal == true) { + if (animal) { return LabelForAnimal; } else { @@ -59,12 +59,11 @@ public string LabelNoCount { public string LabelForAnimal { get { - Pawn pawn = thing as Pawn; - if (pawn.def.race.hasGenders) { - return "EdB.PC.Equipment.AnimalLabel".Translate(pawn.gender.GetLabel(), pawn.kindDef.label).CapitalizeFirst(); + if (def.race.hasGenders) { + return "EdB.PC.Equipment.AnimalLabel".Translate(gender.GetLabel(), def.label).CapitalizeFirst(); } else { - return pawn.LabelCap; + return GenLabel.ThingLabel(def, null, 1).CapitalizeFirst(); } } } @@ -81,9 +80,8 @@ public override string ToString() { (stuffDef != null ? stuffDef.defName : "null"), gender); } - } - + } } diff --git a/Source/Logger.cs b/Source/Logger.cs index a6226d1..227266c 100644 --- a/Source/Logger.cs +++ b/Source/Logger.cs @@ -8,7 +8,7 @@ public static class Logger { public static void Debug(string message) { if (DebugEnabled) { - Log.Message("" + message + ""); + Log.Message("" + message + "", true); } } diff --git a/Source/PanelEquipmentAvailable.cs b/Source/PanelEquipmentAvailable.cs index fb7dda9..9ca26fd 100644 --- a/Source/PanelEquipmentAvailable.cs +++ b/Source/PanelEquipmentAvailable.cs @@ -21,6 +21,8 @@ public class ViewEquipmentList { public static readonly string ColumnNameName = "Name"; public static readonly string ColumnNameCost = "Cost"; + public StatDef marketValueStatDef = null; + protected Rect RectDropdownTypes; protected Rect RectDropdownMaterials; protected Rect RectDropdownQuality; @@ -50,6 +52,10 @@ public PanelEquipmentAvailable() { public override void Resize(Rect rect) { base.Resize(rect); + if (marketValueStatDef == null) { + marketValueStatDef = StatDefOf.MarketValue; + } + Vector2 padding = new Vector2(12, 12); RectDropdownTypes = new Rect(padding.x, padding.y, 140, 28); @@ -120,7 +126,7 @@ public override void Resize(Rect rect) { GUI.DrawTexture(infoRect, Textures.TextureButtonInfo); if (Widgets.ButtonInvisible(infoRect)) { if (entry.animal) { - Find.WindowStack.Add((Window)new Dialog_InfoCard(entry.thing)); + Find.WindowStack.Add((Window)new Dialog_InfoCard(entry.def)); } else if (entry.stuffDef != null) { Find.WindowStack.Add((Window)new Dialog_InfoCard(entry.def, entry.stuffDef)); @@ -151,6 +157,7 @@ public override void Resize(Rect rect) { Text.Font = GameFont.Small; Text.Anchor = TextAnchor.MiddleLeft; Widgets.Label(columnRect, entry.Label); + //Widgets.Label(columnRect, entry.def.defName); GUI.color = Color.white; Text.Anchor = TextAnchor.UpperLeft; } @@ -165,8 +172,8 @@ public override void Resize(Rect rect) { GUI.color = Style.ColorText; Text.Font = GameFont.Small; Text.Anchor = TextAnchor.MiddleRight; - Widgets.Label(new Rect(columnRect.x, columnRect.y, columnRect.width, columnRect.height), - "" + entry.cost); + string costString = GenText.ToStringByStyle((float)entry.cost, ToStringStyle.FloatTwo); + Widgets.Label(new Rect(columnRect.x, columnRect.y, columnRect.width, columnRect.height), costString); GUI.color = Color.white; Text.Anchor = TextAnchor.UpperLeft; }, diff --git a/Source/PanelEquipmentSelected.cs b/Source/PanelEquipmentSelected.cs index ecbcbfa..ec9dccb 100644 --- a/Source/PanelEquipmentSelected.cs +++ b/Source/PanelEquipmentSelected.cs @@ -80,7 +80,7 @@ public override void Resize(Rect rect) { GUI.DrawTexture(infoRect, Textures.TextureButtonInfo); if (Widgets.ButtonInvisible(infoRect)) { if (entry.record.animal) { - Find.WindowStack.Add((Window)new Dialog_InfoCard(entry.record.thing)); + Find.WindowStack.Add((Window)new Dialog_InfoCard(entry.ThingDef)); } else if (entry.StuffDef != null) { Find.WindowStack.Add((Window)new Dialog_InfoCard(entry.ThingDef, entry.StuffDef)); diff --git a/Source/WidgetEquipmentIcon.cs b/Source/WidgetEquipmentIcon.cs index 927fa32..de6a328 100644 --- a/Source/WidgetEquipmentIcon.cs +++ b/Source/WidgetEquipmentIcon.cs @@ -1,4 +1,4 @@ -using RimWorld; +using RimWorld; using System; using System.Collections.Generic; using System.Linq; @@ -8,12 +8,7 @@ namespace EdB.PrepareCarefully { public static class WidgetEquipmentIcon { public static void Draw(Rect rect, EquipmentRecord entry) { - if (entry.thing == null) { - Draw(rect, entry.def, entry.color); - } - else { - Draw(rect, entry.thing, entry.color); - } + Draw(rect, entry.def, entry.color); } public static void Draw(Rect rect, AnimalRecord animal) { Draw(rect, animal.Thing, Color.white); From 5bf1858de62b902333cb788d1694bb88d07e666f Mon Sep 17 00:00:00 2001 From: edbmods Date: Wed, 18 Mar 2020 19:02:26 -0700 Subject: [PATCH 07/10] Miscellaneous fixes and tweaks --- Source/CustomHeadType.cs | 2 +- Source/CustomPawn.cs | 5 +++-- Source/OptionsHeadType.cs | 4 ++-- Source/PanelTraits.cs | 2 ++ Source/ProviderHeadTypes.cs | 2 ++ 5 files changed, 10 insertions(+), 5 deletions(-) diff --git a/Source/CustomHeadType.cs b/Source/CustomHeadType.cs index 649e4fb..85ef782 100644 --- a/Source/CustomHeadType.cs +++ b/Source/CustomHeadType.cs @@ -62,7 +62,7 @@ protected static string GetHeadLabel(string path) { return values[values.Count() - 2] + ", " + values[values.Count() - 1]; } catch (Exception) { - Logger.Warning("Prepare Carefully could not determine head type label from graphics path: " + path); + Logger.Warning("Could not determine head type label from graphics path: " + path); return "EdB.PC.Common.Default".Translate(); } } diff --git a/Source/CustomPawn.cs b/Source/CustomPawn.cs index d64e1ef..dead18c 100644 --- a/Source/CustomPawn.cs +++ b/Source/CustomPawn.cs @@ -271,8 +271,9 @@ public void InitializeInjuriesAndImplantsFromPawn(Pawn pawn) { injuries.Add(injury); } else { + //Logger.Debug("Looking for implant recipes for part {" + hediff.Part?.def + "}"); RecipeDef implantRecipe = healthOptions.ImplantRecipes.Where((RecipeDef def) => { - return (def.addsHediff != null && def.addsHediff == hediff.def && def.appliedOnFixedBodyParts.Contains(hediff.Part.def)); + return (def.addsHediff != null && def.addsHediff == hediff.def && def.appliedOnFixedBodyParts.Contains(hediff.Part?.def)); }).RandomElementWithFallback(null); if (implantRecipe != null) { Implant implant = new Implant(); @@ -281,7 +282,7 @@ public void InitializeInjuriesAndImplantsFromPawn(Pawn pawn) { implants.Add(implant); } else if (hediff.def.defName != "MissingBodyPart") { - Log.Warning("Prepare Carefully could not add a hediff to the pawn: " + hediff.def.defName + ", " + (hediff.Part != null ? hediff.Part.def.defName : "no part")); + Logger.Warning("Could not add hediff {" + hediff.def.defName + "} to the pawn because no recipe adds it to the body part {" + (hediff.Part?.def?.defName ?? "WholeBody") + "}"); } } } diff --git a/Source/OptionsHeadType.cs b/Source/OptionsHeadType.cs index 403e732..14e7281 100644 --- a/Source/OptionsHeadType.cs +++ b/Source/OptionsHeadType.cs @@ -24,6 +24,7 @@ public OptionsHeadType() { } public void AddHeadType(CustomHeadType headType) { headTypes.Add(headType); + //Logger.Debug(headType.ToString()); pathDictionary.Add(headType.GraphicPath, headType); if (headType.AlternateGraphicPath != null) { pathDictionary.Add(headType.AlternateGraphicPath, headType); @@ -53,8 +54,7 @@ public CustomHeadType FindHeadTypeForPawn(Pawn pawn) { } } public CustomHeadType FindHeadTypeByGraphicsPath(string graphicsPath) { - CustomHeadType result; - if (pathDictionary.TryGetValue(graphicsPath, out result)) { + if (pathDictionary.TryGetValue(graphicsPath, out CustomHeadType result)) { return result; } else { diff --git a/Source/PanelTraits.cs b/Source/PanelTraits.cs index 0577a73..20869fb 100644 --- a/Source/PanelTraits.cs +++ b/Source/PanelTraits.cs @@ -409,11 +409,13 @@ protected void SelectPreviousTrait(CustomPawn customPawn, int traitIndex) { protected void ClearTrait(CustomPawn customPawn, int traitIndex) { TraitUpdated(traitIndex, null); + tipCache.Invalidate(); } public void ScrollToTop() { scrollView.ScrollToTop(); } + public void ScrollToBottom() { scrollView.ScrollToBottom(); } diff --git a/Source/ProviderHeadTypes.cs b/Source/ProviderHeadTypes.cs index 9870f2d..5d97438 100644 --- a/Source/ProviderHeadTypes.cs +++ b/Source/ProviderHeadTypes.cs @@ -199,6 +199,7 @@ protected CustomHeadType CreateMultiGenderAlienHeadTypeFromCrownType(string grap } pathValue += crownType; result.GraphicPath = pathValue; + result.AlternateGraphicPath = null; result.Label = LabelFromCrownType(crownType); result.Gender = null; result.CrownType = FindCrownTypeEnumValue(crownType); @@ -209,6 +210,7 @@ protected CustomHeadType CreateMultiGenderAlienHeadTypeFromCrownType(string grap protected CustomHeadType CreateHumanHeadTypeFromGenderedGraphicPath(string graphicPath) { CustomHeadType result = new CustomHeadType(); result.GraphicPath = graphicPath; + result.AlternateGraphicPath = null; result.Label = LabelFromGraphicsPath(graphicPath); string[] strArray = Path.GetFileNameWithoutExtension(graphicPath).Split('_'); try { From ea4f6e82c437cdd0f8c3f6143f4eed9775afa9ad Mon Sep 17 00:00:00 2001 From: edbmods Date: Wed, 18 Mar 2020 19:03:47 -0700 Subject: [PATCH 08/10] Added a tooltip description to injuries --- Source/PanelHealth.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Source/PanelHealth.cs b/Source/PanelHealth.cs index b07609d..7adce8a 100644 --- a/Source/PanelHealth.cs +++ b/Source/PanelHealth.cs @@ -1,4 +1,4 @@ -using RimWorld; +using RimWorld; using System; using System.Collections.Generic; using System.Linq; @@ -306,6 +306,9 @@ public void DrawAddButton() { NameFunc = (InjuryOption option) => { return option.Label; }, + DescriptionFunc = (InjuryOption option) => { + return option.HediffDef?.description; + }, SelectedFunc = (InjuryOption option) => { return selectedInjury == option; }, From b16f2ec59a98765f6d76beedc4237bf95d308119 Mon Sep 17 00:00:00 2001 From: edbmods Date: Wed, 18 Mar 2020 19:05:54 -0700 Subject: [PATCH 09/10] Changelog for version 1.1.9 --- Resources/CHANGELOG.txt | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/Resources/CHANGELOG.txt b/Resources/CHANGELOG.txt index bfe732f..2e2291b 100644 --- a/Resources/CHANGELOG.txt +++ b/Resources/CHANGELOG.txt @@ -1,3 +1,16 @@ + _____________________________________________________________________________ + + Version 1.1.9 + _____________________________________________________________________________ + + - Better error handling in various panels. + - Fixed Backstory and Trait panel tooltip display so that tagged strings + are properly highlighted. + - Support for more injuries and health conditions. + - Added a tooltip description when choosing injuries and health conditions. + - Apparel/faction-related bug fix when loading presets. + - Performance improvements when initializing the equipment panel. + _____________________________________________________________________________ Version 1.1.8 From bf4fb4688d3289dc48a2cbb9e1096f75f6f65d88 Mon Sep 17 00:00:00 2001 From: edbmods Date: Wed, 18 Mar 2020 19:37:01 -0700 Subject: [PATCH 10/10] Converter logging statements to use the Logger class --- Source/AgeInjuryUtility.cs | 2 +- Source/AnimalDatabase.cs | 3 +- Source/ColonistFiles.cs | 2 +- Source/ColonistLoader.cs | 2 +- Source/ColonistSaver.cs | 2 +- Source/Controller.cs | 10 +-- Source/ControllerPawns.cs | 8 +- Source/CostCalculator.cs | 2 +- Source/CustomPawn.cs | 6 +- Source/DialogManageImplants.cs | 6 +- Source/EquipmentDatabase.cs | 7 +- Source/GenStep_CustomScatterThings.cs | 2 +- Source/HarmonyPatches.cs | 6 +- Source/OptionsHeadType.cs | 2 +- Source/OptionsHealth.cs | 4 +- Source/PanelAppearance.cs | 4 +- Source/PanelEquipmentSelected.cs | 2 +- Source/PanelHealth.cs | 6 +- Source/PanelPawnList.cs | 12 +-- Source/PawnColorUtils.cs | 4 +- Source/PrepareCarefully.cs | 6 +- Source/PresetFiles.cs | 2 +- Source/PresetLoader.cs | 2 +- Source/PresetSaver.cs | 16 ++-- Source/ProviderAgeLimits.cs | 10 +-- Source/ProviderAlienRaces.cs | 36 ++++---- Source/ProviderBodyTypes.cs | 12 +-- Source/ProviderFactions.cs | 4 +- Source/ProviderHeadTypes.cs | 14 +-- Source/ProviderHealthOptions.cs | 2 +- Source/ProviderPawnLayers.cs | 4 +- Source/RelationshipManager.cs | 22 ++--- Source/UtilityCopy.cs | 10 +-- Source/Version3/ColonistLoaderVersion3.cs | 10 +-- Source/Version3/PresetLoaderVersion3.cs | 104 +++++++++++----------- Source/Version4/ColonistLoaderVersion4.cs | 10 +-- Source/Version4/PresetLoaderVersion4.cs | 86 +++++++++--------- Source/Version5/PawnLoaderV5.cs | 14 +-- Source/Version5/PresetLoaderV5.cs | 46 +++++----- 39 files changed, 249 insertions(+), 253 deletions(-) diff --git a/Source/AgeInjuryUtility.cs b/Source/AgeInjuryUtility.cs index 7d9893d..1b14844 100644 --- a/Source/AgeInjuryUtility.cs +++ b/Source/AgeInjuryUtility.cs @@ -1,4 +1,4 @@ -using RimWorld; +using RimWorld; using RimWorld.Planet; using System; using System.Collections; diff --git a/Source/AnimalDatabase.cs b/Source/AnimalDatabase.cs index e777f3f..58a83bb 100644 --- a/Source/AnimalDatabase.cs +++ b/Source/AnimalDatabase.cs @@ -81,8 +81,7 @@ protected AnimalRecord CreateAnimalRecord(ThingDef def, Gender gender) { } } catch (Exception e) { - Log.Warning("Prepare Carefully failed to create a pawn for animal database record: " + def.defName); - Log.Message(" Exception message: " + e); + Logger.Warning("Failed to create a pawn for animal database record: " + def.defName, e); return null; } return result; diff --git a/Source/ColonistFiles.cs b/Source/ColonistFiles.cs index f1425a2..834fa96 100644 --- a/Source/ColonistFiles.cs +++ b/Source/ColonistFiles.cs @@ -13,7 +13,7 @@ public static string SavedColonistsFolderPath { return Reflection.GenFilePaths.FolderUnderSaveData("PrepareCarefully"); } catch (Exception e) { - Log.Error("Failed to get colonist save directory"); + Logger.Error("Failed to get colonist save directory"); throw e; } } diff --git a/Source/ColonistLoader.cs b/Source/ColonistLoader.cs index 4319cc4..b8257d7 100644 --- a/Source/ColonistLoader.cs +++ b/Source/ColonistLoader.cs @@ -14,7 +14,7 @@ public static CustomPawn LoadFromFile(PrepareCarefully loadout, string name) { Scribe_Values.Look(ref version, "version", "unknown", false); } catch (Exception e) { - Log.Error("Failed to load preset file"); + Logger.Error("Failed to load preset file"); throw e; } finally { diff --git a/Source/ColonistSaver.cs b/Source/ColonistSaver.cs index 583307e..4cd848d 100644 --- a/Source/ColonistSaver.cs +++ b/Source/ColonistSaver.cs @@ -21,7 +21,7 @@ public static void SaveToFile(CustomPawn customPawn, string colonistName) { Scribe_Deep.Look(ref pawn, "pawn"); } catch (Exception e) { - Log.Error("Failed to save preset file"); + Logger.Error("Failed to save preset file"); throw e; } finally { diff --git a/Source/Controller.cs b/Source/Controller.cs index e490d77..bb3e229 100644 --- a/Source/Controller.cs +++ b/Source/Controller.cs @@ -1,4 +1,4 @@ -using RimWorld; +using RimWorld; using System; using System.Collections.Generic; using System.IO; @@ -81,7 +81,7 @@ public void StartGame() { public void LoadPreset(string name) { if (string.IsNullOrEmpty(name)) { - Log.Warning("Trying to load a preset without a name"); + Logger.Warning("Trying to load a preset without a name"); return; } bool result = PresetLoader.LoadFromFile(PrepareCarefully.Instance, name); @@ -96,7 +96,7 @@ public void LoadPreset(string name) { public void SavePreset(string name) { PrepareCarefully.Instance.Filename = name; if (string.IsNullOrEmpty(name)) { - Log.Warning("Trying to save a preset without a name"); + Logger.Warning("Trying to save a preset without a name"); return; } PresetSaver.SaveToFile(PrepareCarefully.Instance, PrepareCarefully.Instance.Filename); @@ -183,7 +183,7 @@ protected void AddPawnToWorld(CustomPawn pawn) { pawn.Pawn.SetFaction(pawn.Faction.Faction, null); } catch (Exception) { - Log.Warning("Prepare Carefully failed to add a world pawn to the expected faction"); + Logger.Warning("Failed to add a world pawn to the expected faction"); } } // If they are assigned to a random faction of a specific def, choose the random faction and assign it. @@ -193,7 +193,7 @@ protected void AddPawnToWorld(CustomPawn pawn) { pawn.Pawn.SetFaction(pawn.Faction.Faction, null); } catch (Exception) { - Log.Warning("Prepare Carefully failed to add a world pawn to the expected faction"); + Logger.Warning("Failed to add a world pawn to the expected faction"); } } } diff --git a/Source/ControllerPawns.cs b/Source/ControllerPawns.cs index 4491050..3d94cbd 100644 --- a/Source/ControllerPawns.cs +++ b/Source/ControllerPawns.cs @@ -265,7 +265,7 @@ public void DeletePawn(CustomPawn pawn) { } public void LoadCharacter(string name) { if (string.IsNullOrEmpty(name)) { - Log.Warning("Trying to load a character without a name"); + Logger.Warning("Trying to load a character without a name"); return; } CustomPawn pawn = ColonistLoader.LoadFromFile(PrepareCarefully.Instance, name); @@ -284,7 +284,7 @@ public void LoadCharacter(string name) { } public void SaveCharacter(CustomPawn pawn, string filename) { if (string.IsNullOrEmpty(filename)) { - Log.Warning("Trying to save a character without a name"); + Logger.Warning("Trying to save a character without a name"); return; } ColonistSaver.SaveToFile(pawn, filename); @@ -317,9 +317,7 @@ public void AddFactionPawn(PawnKindDef kindDef, bool startingPawn) { } } catch (Exception e) { - Log.Warning("Failed to create faction pawn of kind " + kindDef.defName); - Log.Message(e.Message); - Log.Message(e.StackTrace); + Logger.Warning("Failed to create faction pawn of kind " + kindDef.defName, e); if (pawn != null) { pawn.Destroy(); } diff --git a/Source/CostCalculator.cs b/Source/CostCalculator.cs index b81c28b..54a9261 100644 --- a/Source/CostCalculator.cs +++ b/Source/CostCalculator.cs @@ -195,7 +195,7 @@ public void CalculatePawnCost(ColonistCostDetails cost, CustomPawn pawn) { // Check if there are any ancestor parts that override the selection. UniqueBodyPart uniquePart = healthOptions.FindBodyPartsForRecord(option.BodyPartRecord); if (uniquePart == null) { - Log.Warning("Prepare Carefully could not find body part record when computing the cost of an implant: " + option.BodyPartRecord.def.defName); + Logger.Warning("Could not find body part record when computing the cost of an implant: " + option.BodyPartRecord.def.defName); continue; } if (pawn.AtLeastOneImplantedPart(uniquePart.Ancestors.Select((UniqueBodyPart p) => { return p.Record; }))) { diff --git a/Source/CustomPawn.cs b/Source/CustomPawn.cs index dead18c..ef09754 100644 --- a/Source/CustomPawn.cs +++ b/Source/CustomPawn.cs @@ -302,7 +302,7 @@ public void InitializeInjuriesAndImplantsFromPawn(Pawn pawn) { protected void InitializeSkillLevelsAndPassions() { if (pawn.skills == null) { - Log.Warning("Prepare Carefully could not initialize skills for the pawn. No pawn skill tracker for " + pawn.def.defName + ", " + pawn.kindDef.defName); + Logger.Warning("Could not initialize skills for the pawn. No pawn skill tracker for " + pawn.def.defName + ", " + pawn.kindDef.defName); } // Save the original passions and set the current values to the same. @@ -1299,7 +1299,7 @@ protected void ResetCachedHead() { // gender, swapping to the correct head type if necessary. CustomHeadType filteredHeadType = PrepareCarefully.Instance.Providers.HeadTypes.FindHeadTypeForGender(pawn.def, headType, Gender); if (filteredHeadType == null) { - Log.Warning("No filtered head type found"); //TODO + Logger.Warning("No filtered head type found"); //TODO } SetHeadGraphicPathOnPawn(pawn, filteredHeadType.GraphicPath); } @@ -1468,7 +1468,7 @@ public void AddImplant(Implant implant) { InitializeInjuriesAndImplantsFromPawn(this.pawn); } else { - Log.Warning("Discarding implant because of missing body part: " + implant.BodyPartRecord.def.defName); + Logger.Warning("Discarding implant because of missing body part: " + implant.BodyPartRecord.def.defName); } } diff --git a/Source/DialogManageImplants.cs b/Source/DialogManageImplants.cs index ea07d6e..31687ef 100644 --- a/Source/DialogManageImplants.cs +++ b/Source/DialogManageImplants.cs @@ -1,4 +1,4 @@ -using RimWorld; +using RimWorld; using System; using System.Collections.Generic; using System.Linq; @@ -215,9 +215,9 @@ protected void ResetDisabledState() { validImplants.Add(implant); } - //Log.Warning("Valid implants"); + //Logger.Debug("Valid implants"); //foreach (var i in validImplants) { - // Log.Message(" " + i.recipe.LabelCap + ", " + i.PartName + (i.ReplacesPart ? ", replaces part" : "")); + // Logger.Debug(" " + i.recipe.LabelCap + ", " + i.PartName + (i.ReplacesPart ? ", replaces part" : "")); //} // Iterate each each body part option for each recipe to determine if that body part is missing, diff --git a/Source/EquipmentDatabase.cs b/Source/EquipmentDatabase.cs index dce8fbf..ca59725 100644 --- a/Source/EquipmentDatabase.cs +++ b/Source/EquipmentDatabase.cs @@ -113,7 +113,7 @@ protected void NextPhase() { protected void CountDefs() { for (int i = 0; i < LoadingProgress.defsToCountPerFrame; i++) { if (!LoadingProgress.enumerator.MoveNext()) { - //Log.Message("Prepare Carefully finished counting " + LoadingProgress.defCount + " thing definition(s)"); + //Logger.Message("Finished counting " + LoadingProgress.defCount + " thing definition(s)"); NextPhase(); return; } @@ -196,8 +196,7 @@ protected bool AddThingToEquipmentLists(ThingDef def) { } } catch (Exception e) { - Log.Warning("Prepare Carefully failed to process thing definition while building equipment lists: " + def.defName); - Log.Message(" Exception: " + e); + Logger.Warning("Failed to process thing definition while building equipment lists: " + def.defName, e); } return false; } @@ -518,7 +517,7 @@ public EquipmentRecord LookupEquipmentRecord(EquipmentKey key) { public EquipmentRecord AddThingDefWithStuff(ThingDef def, ThingDef stuff, EquipmentType type) { if (type == null) { - Log.Warning("Prepare Carefully could not add unclassified equipment: " + def); + Logger.Warning("Could not add unclassified equipment: " + def); return null; } EquipmentKey key = new EquipmentKey(def, stuff); diff --git a/Source/GenStep_CustomScatterThings.cs b/Source/GenStep_CustomScatterThings.cs index ff22a41..c52e82a 100644 --- a/Source/GenStep_CustomScatterThings.cs +++ b/Source/GenStep_CustomScatterThings.cs @@ -160,7 +160,7 @@ private bool IsRotationValid(IntVec3 loc, Rot4 rot, Map map) { protected override void ScatterAt(IntVec3 loc, Map map, GenStepParams parms, int stackCount = 1) { Rot4 rot; if (!this.TryGetRandomValidRotation(loc, map, out rot)) { - Log.Warning("Could not find any valid rotation for " + this.thingDef, false); + Logger.Warning("Could not find any valid rotation for " + this.thingDef); return; } if (this.clearSpaceSize > 0) { diff --git a/Source/HarmonyPatches.cs b/Source/HarmonyPatches.cs index 94062a6..38cba16 100644 --- a/Source/HarmonyPatches.cs +++ b/Source/HarmonyPatches.cs @@ -29,7 +29,7 @@ static Main() { || !patchedMethods.Contains((typeof(Verse.Game), "InitNewGame")) ) { String methodsMessage = String.Join(", ", harmony.GetPatchedMethods().Select(i => i.DeclaringType + "." + i.Name)); - Log.Warning("[Prepare Carefully] Did not patch all of the expected methods. The following patched methods were found: " + Logger.Warning("Did not patch all of the expected methods. The following patched methods were found: " + (!methodsMessage.NullOrEmpty() ? methodsMessage : "none")); } } @@ -72,7 +72,7 @@ static void Postfix(Page_ConfigureStartingPawns __instance, ref Rect rect) { PrepareCarefully prepareCarefully = PrepareCarefully.Instance; if (prepareCarefully == null) { - Log.Error("Could not open Prepare Carefully screen, because we failed to get the Prepare Carefully singleton."); + Logger.Error("Could not open Prepare Carefully screen, because we failed to get the Prepare Carefully singleton."); return; } prepareCarefully.Initialize(); @@ -81,7 +81,7 @@ static void Postfix(Page_ConfigureStartingPawns __instance, ref Rect rect) { State state = prepareCarefully.State; if (state == null) { - Log.Error("Could not open Prepare Carefully screen, because the Prepare Carefully state was null."); + Logger.Error("Could not open Prepare Carefully screen, because the Prepare Carefully state was null."); return; } state.Page = page; diff --git a/Source/OptionsHeadType.cs b/Source/OptionsHeadType.cs index 14e7281..3580191 100644 --- a/Source/OptionsHeadType.cs +++ b/Source/OptionsHeadType.cs @@ -94,7 +94,7 @@ public CustomHeadType FindHeadTypeForGender(CustomHeadType headType, Gender gend } CustomHeadType result = FindHeadTypeByGraphicsPath(graphicsPath); if (result == null) { - Log.Warning("Could not find head type for gender: " + graphicsPath); + Logger.Warning("Could not find head type for gender: " + graphicsPath); } return result != null ? result : headType; } diff --git a/Source/OptionsHealth.cs b/Source/OptionsHealth.cs index 30417fc..822d58c 100644 --- a/Source/OptionsHealth.cs +++ b/Source/OptionsHealth.cs @@ -82,14 +82,14 @@ public UniqueBodyPart FindBodyPart(BodyPartDef def, int index) { } public UniqueBodyPart FindBodyPartByName(string name, int index) { if (name == null) { - Log.Warning("Cannot complete a body part lookup by name with a null name value"); + Logger.Warning("Cannot complete a body part lookup by name with a null name value"); return null; } BodyPartDef def = DefDatabase.GetNamedSilentFail(name); if (def != null) { return FindBodyPart(def, index); } - Log.Warning("Did not find body part: " + name);/* + Logger.Warning("Did not find body part: " + name);/* List result; if (bodyPartDefLookup.TryGetValue(def, out result)) { if (index < result.Count) { diff --git a/Source/PanelAppearance.cs b/Source/PanelAppearance.cs index 86cd7e1..bb998ef 100644 --- a/Source/PanelAppearance.cs +++ b/Source/PanelAppearance.cs @@ -288,7 +288,7 @@ protected override void DrawPanelContent(State state) { ThingDef apparelDef = customPawn.GetSelectedApparel(selectedPawnLayer); if (apparelDef != null && apparelDef.MadeFromStuff) { if (customPawn.GetSelectedStuff(selectedPawnLayer) == null) { - Log.Error("Selected stuff for " + selectedPawnLayer.ApparelLayer + " is null"); + Logger.Error("Selected stuff for " + selectedPawnLayer.ApparelLayer + " is null"); } Rect stuffFieldRect = new Rect(RectPortrait.x, cursorY, RectPortrait.width, 28); DrawFieldSelector(stuffFieldRect, customPawn.GetSelectedStuff(selectedPawnLayer).LabelCap, @@ -825,7 +825,7 @@ protected void SelectNextBodyType(CustomPawn customPawn, int direction) { List bodyTypes = provider.GetBodyTypesForPawn(customPawn); int index = bodyTypes.IndexOf(customPawn.BodyType); if (index == -1) { - Log.Warning("Could not find the current pawn's body type in list of available options: " + customPawn.BodyType); + Logger.Warning("Could not find the current pawn's body type in list of available options: " + customPawn.BodyType); return; } index += direction; diff --git a/Source/PanelEquipmentSelected.cs b/Source/PanelEquipmentSelected.cs index ec9dccb..8f826bc 100644 --- a/Source/PanelEquipmentSelected.cs +++ b/Source/PanelEquipmentSelected.cs @@ -204,7 +204,7 @@ protected void ScrollTo(EquipmentRecord entry) { // if (entry == null) { // string thing = def != null ? def.defName : "null"; // string stuff = equipment.StuffDef != null ? equipment.StuffDef.defName : "null"; - // Log.Warning(string.Format("Could not draw unrecognized resource/equipment. Invalid item was removed. This may have been caused by an invalid thing/stuff combination. (thing = {0}, stuff={1})", thing, stuff)); + // Logger.Warning(string.Format("Could not draw unrecognized resource/equipment. Invalid item was removed. This may have been caused by an invalid thing/stuff combination. (thing = {0}, stuff={1})", thing, stuff)); // PrepareCarefully.Instance.RemoveEquipment(equipment); // return null; // } diff --git a/Source/PanelHealth.cs b/Source/PanelHealth.cs index 7adce8a..1b82975 100644 --- a/Source/PanelHealth.cs +++ b/Source/PanelHealth.cs @@ -216,7 +216,7 @@ public void DrawAddButton() { AddInjuryToPawn(selectedInjury, selectedSeverity, part.Record); } else { - Log.Warning("Could not find body part record for definition: " + p.defName); + Logger.Warning("Could not find body part record for definition: " + p.defName); } } } @@ -404,9 +404,9 @@ public void DrawAddButton() { } protected void ApplyImplantsToPawn(CustomPawn pawn, List implants) { - //Log.Warning("Updated implants"); + //Logger.Debug("Updated implants"); //foreach (var i in implants) { - // Log.Message(" " + i.recipe.LabelCap + ", " + i.PartName + (i.ReplacesPart ? ", replaces part" : "")); + // Logger.Debug(" " + i.recipe.LabelCap + ", " + i.PartName + (i.ReplacesPart ? ", replaces part" : "")); //} pawn.UpdateImplants(implants); } diff --git a/Source/PanelPawnList.cs b/Source/PanelPawnList.cs index 0cd1867..267cf05 100644 --- a/Source/PanelPawnList.cs +++ b/Source/PanelPawnList.cs @@ -108,32 +108,32 @@ protected override void DrawPanelContent(State state) { portraitWidth -= 1f; float portraitHeight = Mathf.Floor(portraitWidth * 1.4f); RectPortrait = new Rect(RectPortrait.x, RectPortrait.y, portraitWidth, portraitHeight); - Log.Message("RectPortrait = " + RectPortrait); + Logger.Debug("RectPortrait = " + RectPortrait); } else if (Event.current.keyCode == KeyCode.RightArrow) { float portraitWidth = RectPortrait.width; portraitWidth += 1f; float portraitHeight = Mathf.Floor(portraitWidth * 1.4f); RectPortrait = new Rect(RectPortrait.x, RectPortrait.y, portraitWidth, portraitHeight); - Log.Message("RectPortrait = " + RectPortrait); + Logger.Debug("RectPortrait = " + RectPortrait); } } else { if (Event.current.keyCode == KeyCode.LeftArrow) { RectPortrait = RectPortrait.OffsetBy(new Vector2(-1, 0)); - Log.Message("RectPortrait = " + RectPortrait); + Logger.Debug("RectPortrait = " + RectPortrait); } else if (Event.current.keyCode == KeyCode.RightArrow) { RectPortrait = RectPortrait.OffsetBy(new Vector2(1, 0)); - Log.Message("RectPortrait = " + RectPortrait); + Logger.Debug("RectPortrait = " + RectPortrait); } else if (Event.current.keyCode == KeyCode.UpArrow) { RectPortrait = RectPortrait.OffsetBy(new Vector2(0, -1)); - Log.Message("RectPortrait = " + RectPortrait); + Logger.Debug("RectPortrait = " + RectPortrait); } else if (Event.current.keyCode == KeyCode.DownArrow) { RectPortrait = RectPortrait.OffsetBy(new Vector2(0, 1)); - Log.Message("RectPortrait = " + RectPortrait); + Logger.Debug("RectPortrait = " + RectPortrait); } } } diff --git a/Source/PawnColorUtils.cs b/Source/PawnColorUtils.cs index 0a7918d..e58dfac 100644 --- a/Source/PawnColorUtils.cs +++ b/Source/PawnColorUtils.cs @@ -61,7 +61,7 @@ public static void InitializeColors() { RoundedColors[i].b = (float)Math.Round(color.b, 3); RoundedColors[i].a = (float)Math.Round(color.a, 3); ColorValues[i] = v; - //Log.Message("Color added: (" + color.r + ", " + color.g + ", " + color.b + ")"); + //Logger.Debug("Color added: (" + color.r + ", " + color.g + ", " + color.b + ")"); } } @@ -176,7 +176,7 @@ public static float FindMelaninValueFromColor(Color color) { return result; } - Log.Warning("Prepare Carefully could not find a valid matching value for the saved Color"); + Logger.Warning("Could not find a valid matching value for the saved Color"); return 0.5f; } } diff --git a/Source/PrepareCarefully.cs b/Source/PrepareCarefully.cs index 455d5c4..9d387ed 100644 --- a/Source/PrepareCarefully.cs +++ b/Source/PrepareCarefully.cs @@ -200,7 +200,7 @@ protected void InitializeDefaultEquipment() { EquipmentKey key = new EquipmentKey(thingDef, stuffDef); EquipmentRecord record = equipmentDatabase.LookupEquipmentRecord(key); if (record == null) { - Log.Warning("Prepare Carefully couldn't initialize all scenario equipment. Didn't find an equipment entry for " + thingDef.defName); + Logger.Warning("Couldn't initialize all scenario equipment. Didn't find an equipment entry for " + thingDef.defName); record = AddNonStandardScenarioEquipmentEntry(key); } if (record != null) { @@ -223,7 +223,7 @@ record = AddNonStandardScenarioEquipmentEntry(key); EquipmentKey key = new EquipmentKey(thingDef, stuffDef); EquipmentRecord entry = equipmentDatabase.LookupEquipmentRecord(key); if (entry == null) { - Log.Warning("Prepare Carefully couldn't initialize all scenario equipment. Didn't find an equipment entry for " + thingDef.defName); + Logger.Warning("Couldn't initialize all scenario equipment. Didn't find an equipment entry for " + thingDef.defName); entry = AddNonStandardScenarioEquipmentEntry(key); } if (entry != null) { @@ -252,7 +252,7 @@ record = AddNonStandardScenarioEquipmentEntry(key); AddEquipment(entry); } else { - Log.Warning("Prepare Carefully failed to add the expected scenario animal to list of selected equipment"); + Logger.Warning("Failed to add the expected scenario animal to list of selected equipment"); } } } diff --git a/Source/PresetFiles.cs b/Source/PresetFiles.cs index 19df8eb..a73956b 100644 --- a/Source/PresetFiles.cs +++ b/Source/PresetFiles.cs @@ -13,7 +13,7 @@ public static string SavedPresetsFolderPath { return Reflection.GenFilePaths.FolderUnderSaveData("PrepareCarefully"); } catch (Exception e) { - Log.Error("Failed to get preset save directory"); + Logger.Error("Failed to get preset save directory"); throw e; } } diff --git a/Source/PresetLoader.cs b/Source/PresetLoader.cs index 491a930..510c54b 100644 --- a/Source/PresetLoader.cs +++ b/Source/PresetLoader.cs @@ -14,7 +14,7 @@ public static bool LoadFromFile(PrepareCarefully loadout, string presetName) { Scribe_Values.Look(ref version, "version", "unknown", false); } catch (Exception e) { - Log.Error("Failed to load preset file"); + Logger.Error("Failed to load preset file"); throw e; } finally { diff --git a/Source/PresetSaver.cs b/Source/PresetSaver.cs index 5b81faf..41a102c 100644 --- a/Source/PresetSaver.cs +++ b/Source/PresetSaver.cs @@ -46,7 +46,7 @@ public static void SaveToFile(PrepareCarefully data, string presetName) { preset.pawns.Add(pawn); } else { - Log.Warning("Prepare Carefully found an empty pawn in a parent child relationship while saving the preset. Skipping that pawn."); + Logger.Warning("Found an empty pawn in a parent child relationship while saving the preset. Skipping that pawn."); } } foreach (var child in g.Children) { @@ -56,7 +56,7 @@ public static void SaveToFile(PrepareCarefully data, string presetName) { preset.pawns.Add(pawn); } else { - Log.Warning("Prepare Carefully found an empty pawn in a parent child relationship while saving the preset. Skipping that pawn."); + Logger.Warning("Found an empty pawn in a parent child relationship while saving the preset. Skipping that pawn."); } } } @@ -69,12 +69,12 @@ public static void SaveToFile(PrepareCarefully data, string presetName) { } else { problem = true; - Log.Warning("Prepare Carefully found an invalid custom relationship when saving a preset: " + presetName); + Logger.Warning("Found an invalid custom relationship when saving a preset: " + presetName); if (r.target != null && r.source != null) { - Log.Warning(" Relationship = { source = " + r.source.Id + ", target = " + r.target.Id + ", relationship = " + r.def + "}"); + Logger.Warning(" Relationship = { source = " + r.source.Id + ", target = " + r.target.Id + ", relationship = " + r.def + "}"); } else { - Log.Warning(" Relationship = { source = " + r.source + ", target = " + r.target + ", relationship = " + r.def + "}"); + Logger.Warning(" Relationship = { source = " + r.source + ", target = " + r.target + ", relationship = " + r.def + "}"); } } } @@ -88,7 +88,7 @@ public static void SaveToFile(PrepareCarefully data, string presetName) { foreach (var p in g.Parents) { if (p.Pawn == null) { problem = true; - Log.Warning("Prepare Carefully found an invalid parent/child relationship when saving the preset: " + presetName); + Logger.Warning("Found an invalid parent/child relationship when saving the preset: " + presetName); continue; } else { @@ -98,7 +98,7 @@ public static void SaveToFile(PrepareCarefully data, string presetName) { foreach (var p in g.Children) { if (p.Pawn == null) { problem = true; - Log.Warning("Prepare Carefully found an invalid parent/child relationship when saving the preset: " + presetName); + Logger.Warning("Found an invalid parent/child relationship when saving the preset: " + presetName); continue; } else { @@ -118,7 +118,7 @@ public static void SaveToFile(PrepareCarefully data, string presetName) { } catch (Exception e) { PrepareCarefully.Instance.State.AddError("EdB.PC.Dialog.Preset.Error.SaveFailed".Translate()); - Log.Error("Failed to save preset file"); + Logger.Error("Failed to save preset file"); throw e; } finally { diff --git a/Source/ProviderAgeLimits.cs b/Source/ProviderAgeLimits.cs index 98913f6..6aead9f 100644 --- a/Source/ProviderAgeLimits.cs +++ b/Source/ProviderAgeLimits.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Linq; using System.Reflection; @@ -18,10 +18,10 @@ public int MinAgeForPawn(Pawn pawn) { if (!minAgeLookup.TryGetValue(pawn.def, out int age)) { SimpleCurve simpleCurve = pawn.def.race.ageGenerationCurve; if (simpleCurve == null) { - Log.Warning("Prepare Carefully :: No age generation curve defined for " + pawn.def.defName + ". Using default age generation curve to determine minimum age."); + Logger.Warning("No age generation curve defined for " + pawn.def.defName + ". Using default age generation curve to determine minimum age."); simpleCurve = DefaultAgeGenerationCurve; if (simpleCurve == null) { - Log.Warning("Prepare Carefully :: Failed to get default age generation curve. Using default minimum age of " + DEFAULT_MIN_AGE); + Logger.Warning("Failed to get default age generation curve. Using default minimum age of " + DEFAULT_MIN_AGE); age = DEFAULT_MIN_AGE; } else { @@ -41,10 +41,10 @@ public int MaxAgeForPawn(Pawn pawn) { if (!maxAgeLookup.TryGetValue(pawn.def, out int age)) { SimpleCurve simpleCurve = pawn.def.race.ageGenerationCurve; if (simpleCurve == null) { - Log.Warning("Prepare Carefully :: No age generation curve defined for " + pawn.def.defName + ". Using default age generation curve to determine maximum age."); + Logger.Warning("No age generation curve defined for " + pawn.def.defName + ". Using default age generation curve to determine maximum age."); simpleCurve = DefaultAgeGenerationCurve; if (simpleCurve == null) { - Log.Warning("Prepare Carefully :: Failed to get default age generation curve. Using default maximum age of " + DEFAULT_MAX_AGE); + Logger.Warning("Failed to get default age generation curve. Using default maximum age of " + DEFAULT_MAX_AGE); age = DEFAULT_MAX_AGE; } else { diff --git a/Source/ProviderAlienRaces.cs b/Source/ProviderAlienRaces.cs index ea4c53c..2ffbb8c 100644 --- a/Source/ProviderAlienRaces.cs +++ b/Source/ProviderAlienRaces.cs @@ -93,12 +93,12 @@ protected AlienRace InitializeAlienRace(ThingDef raceDef) { } /* - Log.Message("GraphicsPaths for " + raceDef.defName + ":"); + Logger.Debug("GraphicsPaths for " + raceDef.defName + ":"); if (graphicPathsCollection.Count > 0) { foreach (object o in graphicPathsCollection) { - Log.Message(" GraphicsPath"); - Log.Message(" .body = " + GetFieldValueAsString(raceDef, o, "body")); - Log.Message(" .head = " + GetFieldValueAsString(raceDef, o, "head")); + Logger.Debug(" GraphicsPath"); + Logger.Debug(" .body = " + GetFieldValueAsString(raceDef, o, "body")); + Logger.Debug(" .head = " + GetFieldValueAsString(raceDef, o, "head")); System.Collections.ICollection lifeStagesCollections = GetFieldValueAsCollection(raceDef, o, "lifeStageDefs"); } } @@ -121,13 +121,13 @@ protected AlienRace InitializeAlienRace(ThingDef raceDef) { foreach (object o in alienBodyTypesCollection) { if (o.GetType() == typeof(BodyTypeDef)) { BodyTypeDef def = o as BodyTypeDef; - //Log.Debug(" - " + def.defName + ", " + def.LabelCap); + //Logger.Debug(" - " + def.defName + ", " + def.LabelCap); bodyTypes.Add((BodyTypeDef)o); } } } else { - //Log.Debug(" none"); + //Logger.Debug(" none"); } result.BodyTypes = bodyTypes; @@ -144,13 +144,13 @@ protected AlienRace InitializeAlienRace(ThingDef raceDef) { return null; } List crownTypes = new List(); - //Log.Message("Crown Types for " + raceDef.defName + ":"); + //Logger.Debug("Crown Types for " + raceDef.defName + ":"); if (alienCrownTypesCollection.Count > 0) { foreach (object o in alienCrownTypesCollection) { string crownTypeString = o as string; if (crownTypeString != null) { crownTypes.Add(crownTypeString); - //Log.Message(" " + crownTypeString); + //Logger.Debug(" " + crownTypeString); } } } @@ -270,19 +270,19 @@ protected AlienRace InitializeAlienRace(ThingDef raceDef) { AlienRaceBodyAddon addon = new AlienRaceBodyAddon(); string path = GetFieldValueAsString(raceDef, o, "path"); if (path == null) { - Log.Warning("Failed to get path for body add-on for alien race: " + raceDef.defName); + Logger.Warning("Failed to get path for body add-on for alien race: " + raceDef.defName); continue; } addon.Path = path; int? variantCount = GetFieldValueAsInt(raceDef, o, "variantCount"); if (variantCount == null) { - Log.Warning("Failed to get variant count for body add-on for alien race: " + raceDef.defName); + Logger.Warning("Failed to get variant count for body add-on for alien race: " + raceDef.defName); continue; } addon.OptionCount = variantCount.Value; string name = ParseAddonName(path); if (name == null) { - Log.Warning("Failed to parse a name from its path for body add-on for alien race: " + raceDef.defName); + Logger.Warning("Failed to parse a name from its path for body add-on for alien race: " + raceDef.defName); continue; } addon.Name = name; @@ -312,13 +312,13 @@ protected object GetFieldValue(ThingDef raceDef, object source, string name, boo try { FieldInfo field = source.GetType().GetField(name, BindingFlags.Public | BindingFlags.Instance); if (field == null) { - Log.Warning("Prepare carefully could not find " + name + " field for " + raceDef.defName); + Logger.Warning("Could not find " + name + " field for " + raceDef.defName); return null; } object result = field.GetValue(source); if (result == null) { if (!allowNull) { - Log.Warning("Prepare carefully could not find " + name + " field value for " + raceDef.defName); + Logger.Warning("Could not find " + name + " field value for " + raceDef.defName); } return null; } @@ -327,7 +327,7 @@ protected object GetFieldValue(ThingDef raceDef, object source, string name, boo } } catch (Exception) { - Log.Warning("Prepare carefully could resolve value of the " + name + " field for " + raceDef.defName); + Logger.Warning("Could resolve value of the " + name + " field for " + raceDef.defName); return null; } } @@ -338,7 +338,7 @@ protected System.Collections.ICollection GetFieldValueAsCollection(ThingDef race } System.Collections.ICollection collection = result as System.Collections.ICollection; if (collection == null) { - Log.Warning("Prepare carefully could not convert " + name + " field value into a collection for " + raceDef.defName + "."); + Logger.Warning("Could not convert " + name + " field value into a collection for " + raceDef.defName + "."); return null; } else { @@ -354,7 +354,7 @@ protected System.Collections.ICollection GetFieldValueAsCollection(ThingDef race return (bool)result; } else { - Log.Warning("Prepare carefully could not convert " + name + " field value into a bool for " + raceDef.defName + "."); + Logger.Warning("Could not convert " + name + " field value into a bool for " + raceDef.defName + "."); return null; } } @@ -368,7 +368,7 @@ protected string GetFieldValueAsString(ThingDef raceDef, object source, string n return result; } else { - Log.Warning("Prepare carefully could not convert " + name + " field value into a string for " + raceDef.defName + "."); + Logger.Warning("Could not convert " + name + " field value into a string for " + raceDef.defName + "."); return null; } } @@ -381,7 +381,7 @@ protected string GetFieldValueAsString(ThingDef raceDef, object source, string n return (int)value; } catch (Exception) { - Log.Warning("Prepare carefully could not convert " + name + " field value into an int for " + raceDef.defName + "."); + Logger.Warning("Could not convert " + name + " field value into an int for " + raceDef.defName + "."); return null; } } diff --git a/Source/ProviderBodyTypes.cs b/Source/ProviderBodyTypes.cs index 97845dd..9a52afb 100644 --- a/Source/ProviderBodyTypes.cs +++ b/Source/ProviderBodyTypes.cs @@ -1,4 +1,4 @@ -using RimWorld; +using RimWorld; using System; using System.Collections.Generic; using System.Linq; @@ -65,7 +65,7 @@ protected OptionsBodyType InitializeBodyTypes(ThingDef def) { else { OptionsBodyType result = InitializeAlienRaceBodyTypes(def); if (result == null) { - Log.Warning("Prepare Carefully could not initialize body types for alien race, " + def.defName + ". Defaulting to humanlike body types."); + Logger.Warning("Could not initialize body types for alien race, " + def.defName + ". Defaulting to humanlike body types."); return InitializeHumanlikeBodyTypes(); } return result; @@ -160,20 +160,20 @@ protected OptionsBodyType InitializeAlienRaceBodyTypes(ThingDef def) { // string path = race.GraphicsPathForBodyTypes + "/" + def.bodyNakedGraphicPath.Split('/').Last(); // path = path.Replace("//", "/"); // path += "_south"; - // Log.Warning("ValidateBodyTypeForRace(" + race + ", " + def.defName + "), path = " + path); + // Logger.Debug("ValidateBodyTypeForRace(" + race + ", " + def.defName + "), path = " + path); // try { // // TODO: Figure out which mod we're dealing with and only go through that content pack. // List modsListForReading = LoadedModManager.RunningModsListForReading; // for (int index = modsListForReading.Count - 1; index >= 0; --index) { // ModContentPack pack = modsListForReading[index]; - // Log.Message("Looking for path in " + pack.Identifier); + // Logger.Debug("Looking for path in " + pack.Identifier); // var contentHolder = pack.GetContentHolder(); // if (contentHolder.contentList.ContainsKey(path)) { - // Log.Warning("Found it"); + // Logger.Warning("Found it"); // return true; // } // } - // Log.Warning("Didn't find it"); + // Logger.Debug("Didn't find it"); // return false; // } // catch (Exception) { diff --git a/Source/ProviderFactions.cs b/Source/ProviderFactions.cs index 68aef4c..34b48ed 100644 --- a/Source/ProviderFactions.cs +++ b/Source/ProviderFactions.cs @@ -45,7 +45,7 @@ public ProviderFactions() { factionDefPawnKinds.Add(kindDef); } catch (Exception) { - Log.Warning("Prepare Carefully failed to get a list of factions from a kindDef: " + kindDef.defName); + Logger.Warning("Failed to get a list of factions from a kindDef: " + kindDef.defName); } } @@ -73,7 +73,7 @@ public ProviderFactions() { } } catch (Exception) { - Log.Warning("Prepare Carefully failed to classify a FactionDef as humanlike or not: " + def.defName); + Logger.Warning("Failed to classify a FactionDef as humanlike or not: " + def.defName); } } nonPlayerHumanlikeFactionDefs.Sort((FactionDef a, FactionDef b) => { diff --git a/Source/ProviderHeadTypes.cs b/Source/ProviderHeadTypes.cs index 5d97438..f4021e8 100644 --- a/Source/ProviderHeadTypes.cs +++ b/Source/ProviderHeadTypes.cs @@ -32,7 +32,7 @@ public CustomHeadType FindHeadTypeForPawn(Pawn pawn) { OptionsHeadType headTypes = GetHeadTypesForRace(pawn.def); var result = headTypes.FindHeadTypeForPawn(pawn); if (result == null) { - Log.Warning("Could not find a head type for the pawn: " + pawn.def.defName + ". Head type selection disabled for this pawn"); + Logger.Warning("Could not find a head type for the pawn: " + pawn.def.defName + ". Head type selection disabled for this pawn"); } return result; } @@ -70,14 +70,14 @@ protected OptionsHeadType InitializeHeadTypes(ThingDef race) { else { result = InitializeAlienHeadTypes(race); } - //Log.Warning("Head Types for " + race.defName + ":"); - //Log.Warning(" Male: "); + //Logger.Debug("Head Types for " + race.defName + ":"); + //Logger.Debug(" Male: "); //foreach (var h in result.GetHeadTypesForGender(Gender.Male)) { - // Log.Message(" " + h.ToString()); + // Logger.Debug(" " + h.ToString()); //} - //Log.Warning(" Female: "); + //Logger.Debug(" Female: "); //foreach (var h in result.GetHeadTypesForGender(Gender.Female)) { - // Log.Message(" " + h.ToString()); + // Logger.Debug(" " + h.ToString()); //} return result; } @@ -233,7 +233,7 @@ protected string LabelFromGraphicsPath(string path) { return values[values.Count() - 2] + ", " + values[values.Count() - 1]; } catch (Exception) { - Log.Warning("Prepare Carefully could not determine head type label from graphics path: " + path); + Logger.Warning("Could not determine head type label from graphics path: " + path); return "EdB.PC.Common.Default".Translate(); } } diff --git a/Source/ProviderHealthOptions.cs b/Source/ProviderHealthOptions.cs index 328f6b8..d7d1c57 100644 --- a/Source/ProviderHealthOptions.cs +++ b/Source/ProviderHealthOptions.cs @@ -196,7 +196,7 @@ protected void InitializeInjuryOptions(OptionsHealth options, ThingDef pawnThing label = getsPermanentProperties.permanentLabel.CapitalizeFirst(); } else { - Log.Warning("Prepare Carefully could not find label for old injury: " + hd.defName); + Logger.Warning("Could not find label for old injury: " + hd.defName); continue; } } diff --git a/Source/ProviderPawnLayers.cs b/Source/ProviderPawnLayers.cs index a99e5a3..a7a7d0e 100644 --- a/Source/ProviderPawnLayers.cs +++ b/Source/ProviderPawnLayers.cs @@ -1,4 +1,4 @@ -using RimWorld; +using RimWorld; using System; using System.Collections.Generic; using Verse; @@ -194,7 +194,7 @@ public PawnLayer FindLayerForApparel(ApparelProperties apparelProperties) { return accessoryLayer; } else { - Log.Warning("Cannot find matching layer for apparel. Last layer: " + apparelProperties.LastLayer); + Logger.Warning("Cannot find matching layer for apparel. Last layer: " + apparelProperties.LastLayer); return null; } } diff --git a/Source/RelationshipManager.cs b/Source/RelationshipManager.cs index 876efb0..6dc67aa 100644 --- a/Source/RelationshipManager.cs +++ b/Source/RelationshipManager.cs @@ -1,4 +1,4 @@ -using RimWorld; +using RimWorld; using System; using System.Collections.Generic; using System.Linq; @@ -121,7 +121,7 @@ public PawnRelationWorker FindPawnRelationWorker(PawnRelationDef def) { else { PawnRelationWorker worker = carefullyDef.Worker; if (worker != null) { - //Log.Message("Returned carefully worker for " + def.defName + ", " + worker.GetType().FullName); + //Logger.Debug("Returned carefully worker for " + def.defName + ", " + worker.GetType().FullName); return carefullyDef.Worker; } else { @@ -148,7 +148,7 @@ private void InitializeParentChildGroupsForStartingPawns(List pawns, List< Dictionary groupLookup = new Dictionary(); foreach (Pawn child in pawns) { foreach (var r in child.relations.DirectRelations) { - //Log.Message("Relationship: " + r.def.defName + ", " + child.LabelShort + " & " + r.otherPawn.LabelShort); + //Logger.Debug("Relationship: " + r.def.defName + ", " + child.LabelShort + " & " + r.otherPawn.LabelShort); if (r.def == PawnRelationDefOf.Parent) { Pawn parent = r.otherPawn; CustomPawn parentCustomPawn = pawnCustomPawnLookup[parent]; @@ -184,11 +184,11 @@ private void InitializeParentChildGroupRelationships(List re parent = relationship.source; } if (parent == null) { - Log.Warning("Could not add relationship because of missing parent"); + Logger.Warning("Could not add relationship because of missing parent"); continue; } if (child == null) { - Log.Warning("Could not add relationship because of missing child"); + Logger.Warning("Could not add relationship because of missing child"); continue; } @@ -236,12 +236,12 @@ private void SortAndDedupeParentChildGroups(IEnumerable groups } ParentChildGroup existing; if (parentLookup.TryGetValue(hash, out existing)) { - //Log.Message("Removing duplicate group: " + group); - //Log.Message(" Duplicate of group: " + existing); + //Logger.Debug("Removing duplicate group: " + group); + //Logger.Debug(" Duplicate of group: " + existing); foreach (var child in group.Children) { existing.Children.Add(child); } - //Log.Message(" Added children from dupe: " + existing); + //Logger.Debug(" Added children from dupe: " + existing); groupsToRemove.Add(group); } else { @@ -254,7 +254,7 @@ private void SortAndDedupeParentChildGroups(IEnumerable groups foreach (var group in groups) { if (!groupsToRemove.Contains(group)) { result.Add(group); - //Log.Message(group.ToString()); + //Logger.Debug(group.ToString()); } } @@ -350,13 +350,13 @@ public void CreateParentChildPawnsForStartingPawns(List pawns, List(T type) where T : IExposable { // with the provided constructor arguments. public static T CopyExposable(T type, object[] constructorArgs) where T : IExposable { string xml = "" + Scribe.saver.DebugOutputFor(type) + ""; - //Log.Warning(xml); + //Logger.Debug(xml); InitLoadFromString(xml); T result = default(T); Scribe_Deep.Look(ref result, "saveable", constructorArgs); @@ -75,15 +75,15 @@ public static void CopyExposableViaReflection(string fieldName, object source, o // uses a StringReader instead of reading from a file. private static void InitLoadFromString(String value) { if (Scribe.mode != LoadSaveMode.Inactive) { - Log.Error("Called InitLoading() but current mode is " + Scribe.mode); + Logger.Error("Called InitLoading() but current mode is " + Scribe.mode); Scribe.ForceStop(); } if (Scribe.loader.curParent != null) { - Log.Error("Current parent is not null in InitLoading"); + Logger.Error("Current parent is not null in InitLoading"); Scribe.loader.curParent = null; } if (Scribe.loader.curPathRelToParent != null) { - Log.Error("Current path relative to parent is not null in InitLoading"); + Logger.Error("Current path relative to parent is not null in InitLoading"); Scribe.loader.curPathRelToParent = null; } try { @@ -97,7 +97,7 @@ private static void InitLoadFromString(String value) { Scribe.mode = LoadSaveMode.LoadingVars; } catch (Exception ex) { - Log.Error(string.Concat(new object[] { + Logger.Error(string.Concat(new object[] { "Exception while unmarshalling XML", "\n", ex diff --git a/Source/Version3/ColonistLoaderVersion3.cs b/Source/Version3/ColonistLoaderVersion3.cs index 258fb4c..9229677 100644 --- a/Source/Version3/ColonistLoaderVersion3.cs +++ b/Source/Version3/ColonistLoaderVersion3.cs @@ -23,13 +23,13 @@ public CustomPawn Load(PrepareCarefully loadout, string name) { catch (Exception e) { Messages.Message(modString, MessageTypeDefOf.SilentInput); Messages.Message("EdB.PC.Dialog.PawnPreset.Error.Failed".Translate(), MessageTypeDefOf.RejectInput); - Log.Warning(e.ToString()); - Log.Warning("Colonist was created with the following mods: " + modString); + Logger.Warning("Failed to load preset", e); + Logger.Warning("Colonist was created with the following mods: " + modString); return null; } } catch (Exception e) { - Log.Error("Failed to load preset file"); + Logger.Error("Failed to load preset file"); throw e; } finally { @@ -39,7 +39,7 @@ public CustomPawn Load(PrepareCarefully loadout, string name) { if (pawnRecord == null) { Messages.Message(modString, MessageTypeDefOf.SilentInput); Messages.Message("EdB.PC.Dialog.PawnPreset.Error.Failed".Translate(), MessageTypeDefOf.RejectInput); - Log.Warning("Colonist was created with the following mods: " + modString); + Logger.Warning("Colonist was created with the following mods: " + modString); return null; } @@ -57,7 +57,7 @@ public CustomPawn Load(PrepareCarefully loadout, string name) { else { loadout.State.AddError(loader.ModString); loadout.State.AddError("EdB.PC.Dialog.Preset.Error.NoCharacter".Translate()); - Log.Warning("Preset was created with the following mods: " + modString); + Logger.Warning("Preset was created with the following mods: " + modString); return null; } } diff --git a/Source/Version3/PresetLoaderVersion3.cs b/Source/Version3/PresetLoaderVersion3.cs index b174c87..769f24d 100644 --- a/Source/Version3/PresetLoaderVersion3.cs +++ b/Source/Version3/PresetLoaderVersion3.cs @@ -69,7 +69,7 @@ protected void InitializeBodyPartReplacements() { public void AddBodyPartReplacement(string name, string newPart, int index) { BodyPartDef def = DefDatabase.GetNamedSilentFail(newPart); if (def == null) { - Log.Warning("Could not find body part definition \"" + newPart + "\" to replace body part \"" + name + "\""); + Logger.Warning("Could not find body part definition \"" + newPart + "\" to replace body part \"" + name + "\""); return; } bodyPartReplacements.Add(name, new ReplacementBodyPart(def, index)); @@ -95,8 +95,8 @@ public bool Load(PrepareCarefully loadout, string presetName) { } catch (Exception e) { Messages.Message("EdB.PC.Dialog.Preset.Error.Failed".Translate(), MessageTypeDefOf.ThreatBig); - Log.Warning(e.ToString()); - Log.Warning("Preset was created with the following mods: " + ModString); + Logger.Warning("Error while loading preset", e); + Logger.Warning("Preset was created with the following mods: " + ModString); return false; } @@ -105,8 +105,8 @@ public bool Load(PrepareCarefully loadout, string presetName) { } catch (Exception e) { Messages.Message("EdB.PC.Dialog.Preset.Error.Failed".Translate(), MessageTypeDefOf.ThreatBig); - Log.Warning(e.ToString()); - Log.Warning("Preset was created with the following mods: " + ModString); + Logger.Warning("Error while loading preset", e); + Logger.Warning("Preset was created with the following mods: " + ModString); return false; } @@ -115,8 +115,8 @@ public bool Load(PrepareCarefully loadout, string presetName) { } catch (Exception e) { Messages.Message("EdB.PC.Dialog.Preset.Error.Failed".Translate(), MessageTypeDefOf.ThreatBig); - Log.Warning(e.ToString()); - Log.Warning("Preset was created with the following mods: " + ModString); + Logger.Warning("Error while loading preset", e); + Logger.Warning("Preset was created with the following mods: " + ModString); return false; } @@ -125,8 +125,8 @@ public bool Load(PrepareCarefully loadout, string presetName) { } catch (Exception e) { Messages.Message("EdB.PC.Dialog.Preset.Error.Failed".Translate(), MessageTypeDefOf.ThreatBig); - Log.Warning(e.ToString()); - Log.Warning("Preset was created with the following mods: " + ModString); + Logger.Warning("Error while loading preset", e); + Logger.Warning("Preset was created with the following mods: " + ModString); return false; } @@ -153,7 +153,7 @@ public bool Load(PrepareCarefully loadout, string presetName) { gender = (Gender)Enum.Parse(typeof(Gender), e.gender); } catch (Exception) { - Log.Warning("Failed to load gender value for animal."); + Logger.Warning("Failed to load gender value for animal."); Failed = true; continue; } @@ -166,7 +166,7 @@ public bool Load(PrepareCarefully loadout, string presetName) { equipment.Add(new EquipmentSelection(record, e.count)); } else { - Log.Warning("Could not find equipment in equipment database: " + key); + Logger.Warning("Could not find equipment in equipment database: " + key); Failed = true; continue; } @@ -178,7 +178,7 @@ public bool Load(PrepareCarefully loadout, string presetName) { if (record == null) { string thing = thingDef != null ? thingDef.defName : "null"; string stuff = stuffDef != null ? stuffDef.defName : "null"; - Log.Warning(string.Format("Could not load equipment/resource from the preset. This may be caused by an invalid thing/stuff combination: " + key)); + Logger.Warning(string.Format("Could not load equipment/resource from the preset. This may be caused by an invalid thing/stuff combination: " + key)); Failed = true; continue; } @@ -187,13 +187,13 @@ public bool Load(PrepareCarefully loadout, string presetName) { } } else { - Log.Warning("Could not load stuff definition \"" + e.stuffDef + "\" for item \"" + e.def + "\""); + Logger.Warning("Could not load stuff definition \"" + e.stuffDef + "\" for item \"" + e.def + "\""); Failed = true; } } } else { - Log.Warning("Could not load thing definition \"" + e.def + "\""); + Logger.Warning("Could not load thing definition \"" + e.def + "\""); Failed = true; } } @@ -204,14 +204,14 @@ public bool Load(PrepareCarefully loadout, string presetName) { } else { Messages.Message("EdB.PC.Dialog.Preset.Error.EquipmentFailed".Translate(), MessageTypeDefOf.ThreatBig); - Log.Warning("Failed to load equipment from preset"); + Logger.Warning("Failed to load equipment from preset"); Failed = true; } //PrepareCarefully.Instance.Config.pointsEnabled = usePoints; } catch (Exception e) { - Log.Error("Failed to load preset file"); + Logger.Error("Failed to load preset file"); throw e; } finally { @@ -229,14 +229,14 @@ public bool Load(PrepareCarefully loadout, string presetName) { } else { Messages.Message("EdB.PC.Dialog.Preset.Error.NoCharacter".Translate(), MessageTypeDefOf.ThreatBig); - Log.Warning("Preset was created with the following mods: " + ModString); + Logger.Warning("Preset was created with the following mods: " + ModString); } } } catch (Exception e) { Messages.Message("EdB.PC.Dialog.Preset.Error.Failed".Translate(), MessageTypeDefOf.ThreatBig); - Log.Warning(e.ToString()); - Log.Warning("Preset was created with the following mods: " + ModString); + Logger.Warning("Error while loading preset", e); + Logger.Warning("Preset was created with the following mods: " + ModString); return false; } @@ -250,15 +250,15 @@ public bool Load(PrepareCarefully loadout, string presetName) { hiddenCustomPawns.Add(pawn); } else { - Log.Warning("Prepare Carefully failed to load a hidden character from the preset"); + Logger.Warning("Failed to load a hidden character from the preset"); } } } } catch (Exception e) { Messages.Message("EdB.PC.Dialog.Preset.Error.Failed".Translate(), MessageTypeDefOf.ThreatBig); - Log.Warning(e.ToString()); - Log.Warning("Preset was created with the following mods: " + ModString); + Logger.Warning("Error while loading preset", e); + Logger.Warning("Preset was created with the following mods: " + ModString); return false; } @@ -276,13 +276,13 @@ public bool Load(PrepareCarefully loadout, string presetName) { foreach (SaveRecordRelationshipV3 r in savedRelationships) { if (string.IsNullOrEmpty(r.source) || string.IsNullOrEmpty(r.target) || string.IsNullOrEmpty(r.relation)) { atLeastOneRelationshipFailed = true; - Log.Warning("Prepare Carefully failed to load a custom relationship from the preset: " + r); + Logger.Warning("Failed to load a custom relationship from the preset: " + r); continue; } CustomRelationship relationship = LoadRelationship(r, allPawns); if (relationship == null) { atLeastOneRelationshipFailed = true; - Log.Warning("Prepare Carefully failed to load a custom relationship from the preset: " + r); + Logger.Warning("Failed to load a custom relationship from the preset: " + r); } else { allRelationships.Add(relationship); @@ -291,8 +291,8 @@ public bool Load(PrepareCarefully loadout, string presetName) { } catch (Exception e) { Messages.Message("EdB.PC.Dialog.Preset.Error.RelationshipFailed".Translate(), MessageTypeDefOf.ThreatBig); - Log.Warning(e.ToString()); - Log.Warning("Preset was created with the following mods: " + ModString); + Logger.Warning("Error while loading preset", e); + Logger.Warning("Preset was created with the following mods: " + ModString); return false; } if (atLeastOneRelationshipFailed) { @@ -313,11 +313,11 @@ public bool Load(PrepareCarefully loadout, string presetName) { group.Parents.Add(pawn); } else { - Log.Warning("Prepare Carefully could not load a custom parent relationship because it could not find a matching pawn in the relationship manager."); + Logger.Warning("Could not load a custom parent relationship because it could not find a matching pawn in the relationship manager."); } } else { - Log.Warning("Prepare Carefully could not load a custom parent relationship because it could not find a pawn with the saved identifer."); + Logger.Warning("Could not load a custom parent relationship because it could not find a pawn with the saved identifer."); } } } @@ -330,11 +330,11 @@ public bool Load(PrepareCarefully loadout, string presetName) { group.Children.Add(pawn); } else { - Log.Warning("Prepare Carefully could not load a custom child relationship because it could not find a matching pawn in the relationship manager."); + Logger.Warning("Could not load a custom child relationship because it could not find a matching pawn in the relationship manager."); } } else { - Log.Warning("Prepare Carefully could not load a custom child relationship because it could not find a pawn with the saved identifer."); + Logger.Warning("Could not load a custom child relationship because it could not find a pawn with the saved identifer."); } } } @@ -346,7 +346,7 @@ public bool Load(PrepareCarefully loadout, string presetName) { if (Failed) { Messages.Message(ModString, MessageTypeDefOf.SilentInput); Messages.Message("EdB.PC.Dialog.Preset.Error.ThingDefFailed".Translate(), MessageTypeDefOf.ThreatBig); - Log.Warning("Preset was created with the following mods: " + ModString); + Logger.Warning("Preset was created with the following mods: " + ModString); return false; } @@ -366,7 +366,7 @@ public CustomPawn LoadPawn(SaveRecordPawnV3 record) { if (record.pawnKindDef != null) { pawnKindDef = DefDatabase.GetNamedSilentFail(record.pawnKindDef); if (pawnKindDef == null) { - Log.Warning("Prepare Carefully could not find the pawn kind definition for the saved character: \"" + record.pawnKindDef + "\""); + Logger.Warning("Could not find the pawn kind definition for the saved character: \"" + record.pawnKindDef + "\""); return null; } } @@ -419,7 +419,7 @@ public CustomPawn LoadPawn(SaveRecordPawnV3 record) { pawn.HairDef = h; } else { - Log.Warning("Could not load hair definition \"" + record.hairDef + "\""); + Logger.Warning("Could not load hair definition \"" + record.hairDef + "\""); Failed = true; } @@ -442,7 +442,7 @@ public CustomPawn LoadPawn(SaveRecordPawnV3 record) { pawn.Childhood = backstory; } else { - Log.Warning("Could not load childhood backstory definition \"" + record.childhood + "\""); + Logger.Warning("Could not load childhood backstory definition \"" + record.childhood + "\""); Failed = true; } if (record.adulthood != null) { @@ -451,7 +451,7 @@ public CustomPawn LoadPawn(SaveRecordPawnV3 record) { pawn.Adulthood = backstory; } else { - Log.Warning("Could not load adulthood backstory definition \"" + record.adulthood + "\""); + Logger.Warning("Could not load adulthood backstory definition \"" + record.adulthood + "\""); Failed = true; } } @@ -504,7 +504,7 @@ public CustomPawn LoadPawn(SaveRecordPawnV3 record) { pawn.AddTrait(trait); } else { - Log.Warning("Could not load trait definition \"" + traitName + "\""); + Logger.Warning("Could not load trait definition \"" + traitName + "\""); Failed = true; } } @@ -513,7 +513,7 @@ public CustomPawn LoadPawn(SaveRecordPawnV3 record) { string name = record.skillNames[i]; SkillDef def = FindSkillDef(pawn.Pawn, name); if (def == null) { - Log.Warning("Could not load skill definition \"" + name + "\""); + Logger.Warning("Could not load skill definition \"" + name + "\""); Failed = true; continue; } @@ -527,7 +527,7 @@ public CustomPawn LoadPawn(SaveRecordPawnV3 record) { string name = record.skillNames[i]; SkillDef def = FindSkillDef(pawn.Pawn, name); if (def == null) { - Log.Warning("Could not load skill definition \"" + name + "\""); + Logger.Warning("Could not load skill definition \"" + name + "\""); Failed = true; continue; } @@ -545,13 +545,13 @@ public CustomPawn LoadPawn(SaveRecordPawnV3 record) { int layerIndex = record.apparelLayers[i]; PawnLayer layer = PrepareCarefully.Instance.Providers.PawnLayers.FindLayerFromDeprecatedIndex(layerIndex); if (layer == null) { - Log.Warning("Could not find pawn layer from saved pawn layer index: \"" + layerIndex + "\""); + Logger.Warning("Could not find pawn layer from saved pawn layer index: \"" + layerIndex + "\""); Failed = true; continue; } ThingDef def = DefDatabase.GetNamedSilentFail(record.apparel[i]); if (def == null) { - Log.Warning("Could not load thing definition for apparel \"" + record.apparel[i] + "\""); + Logger.Warning("Could not load thing definition for apparel \"" + record.apparel[i] + "\""); Failed = true; continue; } @@ -559,7 +559,7 @@ public CustomPawn LoadPawn(SaveRecordPawnV3 record) { if (!string.IsNullOrEmpty(record.apparelStuff[i])) { stuffDef = DefDatabase.GetNamedSilentFail(record.apparelStuff[i]); if (stuffDef == null) { - Log.Warning("Could not load stuff definition \"" + record.apparelStuff[i] + "\" for apparel \"" + record.apparel[i] + "\""); + Logger.Warning("Could not load stuff definition \"" + record.apparelStuff[i] + "\" for apparel \"" + record.apparel[i] + "\""); Failed = true; continue; } @@ -577,7 +577,7 @@ public CustomPawn LoadPawn(SaveRecordPawnV3 record) { uniqueBodyPart = FindReplacementBodyPart(healthOptions, implantRecord.bodyPart); } if (uniqueBodyPart == null) { - Log.Warning("Prepare Carefully could not add the implant because it could not find the needed body part \"" + implantRecord.bodyPart + "\"" + Logger.Warning("Could not add the implant because it could not find the needed body part \"" + implantRecord.bodyPart + "\"" + (implantRecord.bodyPartIndex != null ? " with index " + implantRecord.bodyPartIndex : "")); Failed = true; continue; @@ -586,7 +586,7 @@ public CustomPawn LoadPawn(SaveRecordPawnV3 record) { if (implantRecord.recipe != null) { RecipeDef recipeDef = FindRecipeDef(implantRecord.recipe); if (recipeDef == null) { - Log.Warning("Prepare Carefully could not add the implant because it could not find the recipe definition \"" + implantRecord.recipe + "\""); + Logger.Warning("Could not add the implant because it could not find the recipe definition \"" + implantRecord.recipe + "\""); Failed = true; continue; } @@ -598,7 +598,7 @@ public CustomPawn LoadPawn(SaveRecordPawnV3 record) { } } if (!found) { - Log.Warning("Prepare carefully could not apply the saved implant recipe \"" + implantRecord.recipe + "\" to the body part \"" + bodyPart.def.defName + "\". Recipe does not support that part."); + Logger.Warning("Could not apply the saved implant recipe \"" + implantRecord.recipe + "\" to the body part \"" + bodyPart.def.defName + "\". Recipe does not support that part."); Failed = true; continue; } @@ -613,13 +613,13 @@ public CustomPawn LoadPawn(SaveRecordPawnV3 record) { foreach (var injuryRecord in record.injuries) { HediffDef def = DefDatabase.GetNamedSilentFail(injuryRecord.hediffDef); if (def == null) { - Log.Warning("Prepare Carefully could not add the injury because it could not find the hediff definition \"" + injuryRecord.hediffDef + "\""); + Logger.Warning("Could not add the injury because it could not find the hediff definition \"" + injuryRecord.hediffDef + "\""); Failed = true; continue; } InjuryOption option = healthOptions.FindInjuryOptionByHediffDef(def); if (option == null) { - Log.Warning("Prepare Carefully could not add the injury because it could not find a matching injury option for the saved hediff \"" + injuryRecord.hediffDef + "\""); + Logger.Warning("Could not add the injury because it could not find a matching injury option for the saved hediff \"" + injuryRecord.hediffDef + "\""); Failed = true; continue; } @@ -631,7 +631,7 @@ public CustomPawn LoadPawn(SaveRecordPawnV3 record) { uniquePart = FindReplacementBodyPart(healthOptions, injuryRecord.bodyPart); } if (uniquePart == null) { - Log.Warning("Prepare Carefully could not add the injury because it could not find the needed body part \"" + injuryRecord.bodyPart + "\"" + Logger.Warning("Could not add the injury because it could not find the needed body part \"" + injuryRecord.bodyPart + "\"" + (injuryRecord.bodyPartIndex != null ? " with index " + injuryRecord.bodyPartIndex : "")); Failed = true; continue; @@ -685,19 +685,19 @@ public CustomRelationship LoadRelationship(SaveRecordRelationshipV3 saved, List< result.inverseDef = PrepareCarefully.Instance.RelationshipManager.FindInverseRelationship(result.def); } if (result.def == null) { - Log.Warning("Couldn't find relationship definition: " + saved.relation); + Logger.Warning("Couldn't find relationship definition: " + saved.relation); return null; } else if (result.source == null) { - Log.Warning("Couldn't find relationship source pawn: " + saved.source); + Logger.Warning("Couldn't find relationship source pawn: " + saved.source); return null; } else if (result.target == null) { - Log.Warning("Couldn't find relationship target pawn: " + saved.source); + Logger.Warning("Couldn't find relationship target pawn: " + saved.source); return null; } else if (result.inverseDef == null) { - Log.Warning("Couldn't determine inverse relationship: " + saved.relation); + Logger.Warning("Couldn't determine inverse relationship: " + saved.relation); return null; } return result; @@ -737,7 +737,7 @@ public Backstory FindBackstory(string name) { return b.identifier.StartsWith(backstoryMinusVersioning); }); if (matchingBackstory != null) { - Log.Message("Found replacement backstory. Using " + matchingBackstory.identifier + " in place of " + name); + Logger.Message("Found replacement backstory. Using " + matchingBackstory.identifier + " in place of " + name); } } return matchingBackstory; diff --git a/Source/Version4/ColonistLoaderVersion4.cs b/Source/Version4/ColonistLoaderVersion4.cs index d5a42b4..3b5c180 100644 --- a/Source/Version4/ColonistLoaderVersion4.cs +++ b/Source/Version4/ColonistLoaderVersion4.cs @@ -23,13 +23,13 @@ public CustomPawn Load(PrepareCarefully loadout, string name) { catch (Exception e) { Messages.Message(modString, MessageTypeDefOf.SilentInput); Messages.Message("EdB.PC.Dialog.PawnPreset.Error.Failed".Translate(), MessageTypeDefOf.RejectInput); - Log.Warning(e.ToString()); - Log.Warning("Colonist was created with the following mods: " + modString); + Logger.Warning(e.ToString()); + Logger.Warning("Colonist was created with the following mods: " + modString); return null; } } catch (Exception e) { - Log.Error("Failed to load preset file"); + Logger.Error("Failed to load preset file"); throw e; } finally { @@ -39,7 +39,7 @@ public CustomPawn Load(PrepareCarefully loadout, string name) { if (pawnRecord == null) { Messages.Message(modString, MessageTypeDefOf.SilentInput); Messages.Message("EdB.PC.Dialog.PawnPreset.Error.Failed".Translate(), MessageTypeDefOf.RejectInput); - Log.Warning("Colonist was created with the following mods: " + modString); + Logger.Warning("Colonist was created with the following mods: " + modString); return null; } @@ -57,7 +57,7 @@ public CustomPawn Load(PrepareCarefully loadout, string name) { else { loadout.State.AddError(modString); loadout.State.AddError("EdB.PC.Dialog.Preset.Error.NoCharacter".Translate()); - Log.Warning("Preset was created with the following mods: " + modString); + Logger.Warning("Preset was created with the following mods: " + modString); return null; } } diff --git a/Source/Version4/PresetLoaderVersion4.cs b/Source/Version4/PresetLoaderVersion4.cs index 6b0fb20..15a95e6 100644 --- a/Source/Version4/PresetLoaderVersion4.cs +++ b/Source/Version4/PresetLoaderVersion4.cs @@ -69,7 +69,7 @@ protected void InitializeBodyPartReplacements() { public void AddBodyPartReplacement(string name, string newPart, int index) { BodyPartDef def = DefDatabase.GetNamedSilentFail(newPart); if (def == null) { - Log.Warning("Could not find body part definition \"" + newPart + "\" to replace body part \"" + name + "\""); + Logger.Warning("Could not find body part definition \"" + newPart + "\" to replace body part \"" + name + "\""); return; } bodyPartReplacements.Add(name, new ReplacementBodyPart(def, index)); @@ -102,7 +102,7 @@ public bool Load(PrepareCarefully loadout, string presetName) { gender = (Gender)Enum.Parse(typeof(Gender), e.gender); } catch (Exception) { - Log.Warning("Failed to load gender value for animal."); + Logger.Warning("Failed to load gender value for animal."); Failed = true; continue; } @@ -115,7 +115,7 @@ public bool Load(PrepareCarefully loadout, string presetName) { equipment.Add(new EquipmentSelection(record, e.count)); } else { - Log.Warning("Could not find equipment in equipment database: " + key); + Logger.Warning("Could not find equipment in equipment database: " + key); Failed = true; continue; } @@ -127,7 +127,7 @@ public bool Load(PrepareCarefully loadout, string presetName) { if (record == null) { string thing = thingDef != null ? thingDef.defName : "null"; string stuff = stuffDef != null ? stuffDef.defName : "null"; - Log.Warning(string.Format("Could not load equipment/resource from the preset. This may be caused by an invalid thing/stuff combination: " + key)); + Logger.Warning(string.Format("Could not load equipment/resource from the preset. This may be caused by an invalid thing/stuff combination: " + key)); Failed = true; continue; } @@ -136,13 +136,13 @@ public bool Load(PrepareCarefully loadout, string presetName) { } } else { - Log.Warning("Could not load stuff definition \"" + e.stuffDef + "\" for item \"" + e.def + "\""); + Logger.Warning("Could not load stuff definition \"" + e.stuffDef + "\" for item \"" + e.def + "\""); Failed = true; } } } else { - Log.Warning("Could not load thing definition \"" + e.def + "\""); + Logger.Warning("Could not load thing definition \"" + e.def + "\""); Failed = true; } } @@ -153,12 +153,12 @@ public bool Load(PrepareCarefully loadout, string presetName) { } else { Messages.Message("EdB.PC.Dialog.Preset.Error.EquipmentFailed".Translate(), MessageTypeDefOf.ThreatBig); - Log.Warning("Failed to load equipment from preset"); + Logger.Warning("Failed to load equipment from preset"); Failed = true; } } catch (Exception e) { - Log.Error("Failed to load preset file"); + Logger.Error("Failed to load preset file"); throw e; } finally { @@ -182,14 +182,14 @@ public bool Load(PrepareCarefully loadout, string presetName) { } else { Messages.Message("EdB.PC.Dialog.Preset.Error.NoCharacter".Translate(), MessageTypeDefOf.ThreatBig); - Log.Warning("Preset was created with the following mods: " + preset.mods); + Logger.Warning("Preset was created with the following mods: " + preset.mods); } } } catch (Exception e) { Messages.Message("EdB.PC.Dialog.Preset.Error.Failed".Translate(), MessageTypeDefOf.ThreatBig); - Log.Warning(e.ToString()); - Log.Warning("Preset was created with the following mods: " + preset.mods); + Logger.Warning("Error while loading preset", e); + Logger.Warning("Preset was created with the following mods: " + preset.mods); return false; } @@ -207,13 +207,13 @@ public bool Load(PrepareCarefully loadout, string presetName) { foreach (SaveRecordRelationshipV3 r in preset.relationships) { if (string.IsNullOrEmpty(r.source) || string.IsNullOrEmpty(r.target) || string.IsNullOrEmpty(r.relation)) { atLeastOneRelationshipFailed = true; - Log.Warning("Prepare Carefully failed to load a custom relationship from the preset: " + r); + Logger.Warning("Failed to load a custom relationship from the preset: " + r); continue; } CustomRelationship relationship = LoadRelationship(r, allPawns); if (relationship == null) { atLeastOneRelationshipFailed = true; - Log.Warning("Prepare Carefully failed to load a custom relationship from the preset: " + r); + Logger.Warning("Failed to load a custom relationship from the preset: " + r); } else { allRelationships.Add(relationship); @@ -222,8 +222,8 @@ public bool Load(PrepareCarefully loadout, string presetName) { } catch (Exception e) { Messages.Message("EdB.PC.Dialog.Preset.Error.RelationshipFailed".Translate(), MessageTypeDefOf.ThreatBig); - Log.Warning(e.ToString()); - Log.Warning("Preset was created with the following mods: " + preset.mods); + Logger.Warning("Error while loading preset", e); + Logger.Warning("Preset was created with the following mods: " + preset.mods); return false; } if (atLeastOneRelationshipFailed) { @@ -244,11 +244,11 @@ public bool Load(PrepareCarefully loadout, string presetName) { group.Parents.Add(pawn); } else { - Log.Warning("Prepare Carefully could not load a custom parent relationship because it could not find a matching pawn in the relationship manager."); + Logger.Warning("Could not load a custom parent relationship because it could not find a matching pawn in the relationship manager."); } } else { - Log.Warning("Prepare Carefully could not load a custom parent relationship because it could not find a pawn with the saved identifer."); + Logger.Warning("Could not load a custom parent relationship because it could not find a pawn with the saved identifer."); } } } @@ -261,11 +261,11 @@ public bool Load(PrepareCarefully loadout, string presetName) { group.Children.Add(pawn); } else { - Log.Warning("Prepare Carefully could not load a custom child relationship because it could not find a matching pawn in the relationship manager."); + Logger.Warning("Could not load a custom child relationship because it could not find a matching pawn in the relationship manager."); } } else { - Log.Warning("Prepare Carefully could not load a custom child relationship because it could not find a pawn with the saved identifer."); + Logger.Warning("Could not load a custom child relationship because it could not find a pawn with the saved identifer."); } } } @@ -277,7 +277,7 @@ public bool Load(PrepareCarefully loadout, string presetName) { if (Failed) { Messages.Message(preset.mods, MessageTypeDefOf.SilentInput); Messages.Message("EdB.PC.Dialog.Preset.Error.ThingDefFailed".Translate(), MessageTypeDefOf.ThreatBig); - Log.Warning("Preset was created with the following mods: " + preset.mods); + Logger.Warning("Preset was created with the following mods: " + preset.mods); return false; } @@ -297,7 +297,7 @@ public CustomPawn LoadPawn(SaveRecordPawnV4 record) { if (record.pawnKindDef != null) { pawnKindDef = DefDatabase.GetNamedSilentFail(record.pawnKindDef); if (pawnKindDef == null) { - Log.Warning("Prepare Carefully could not find the pawn kind definition for the saved character: \"" + record.pawnKindDef + "\""); + Logger.Warning("Could not find the pawn kind definition for the saved character: \"" + record.pawnKindDef + "\""); return null; } } @@ -383,7 +383,7 @@ public CustomPawn LoadPawn(SaveRecordPawnV4 record) { pawn.Faction = customFaction; } else { - Log.Warning("Prepare Carefully could not place at least one preset character into a saved faction because there were not enough available factions of that type in the world"); + Logger.Warning("Could not place at least one preset character into a saved faction because there were not enough available factions of that type in the world"); randomFaction = true; } } @@ -398,7 +398,7 @@ public CustomPawn LoadPawn(SaveRecordPawnV4 record) { } } else { - Log.Warning("Prepare Carefully could not place at least one preset character into a saved faction because that faction is not available in the world"); + Logger.Warning("Could not place at least one preset character into a saved faction because that faction is not available in the world"); } } } @@ -409,7 +409,7 @@ public CustomPawn LoadPawn(SaveRecordPawnV4 record) { pawn.HairDef = h; } else { - Log.Warning("Could not load hair definition \"" + record.hairDef + "\""); + Logger.Warning("Could not load hair definition \"" + record.hairDef + "\""); Failed = true; } @@ -443,7 +443,7 @@ public CustomPawn LoadPawn(SaveRecordPawnV4 record) { pawn.Childhood = backstory; } else { - Log.Warning("Could not load childhood backstory definition \"" + record.childhood + "\""); + Logger.Warning("Could not load childhood backstory definition \"" + record.childhood + "\""); Failed = true; } if (record.adulthood != null) { @@ -452,7 +452,7 @@ public CustomPawn LoadPawn(SaveRecordPawnV4 record) { pawn.Adulthood = backstory; } else { - Log.Warning("Could not load adulthood backstory definition \"" + record.adulthood + "\""); + Logger.Warning("Could not load adulthood backstory definition \"" + record.adulthood + "\""); Failed = true; } } @@ -483,7 +483,7 @@ public CustomPawn LoadPawn(SaveRecordPawnV4 record) { pawn.AddTrait(trait); } else { - Log.Warning("Could not load trait definition \"" + traitName + "\""); + Logger.Warning("Could not load trait definition \"" + traitName + "\""); Failed = true; } } @@ -491,7 +491,7 @@ public CustomPawn LoadPawn(SaveRecordPawnV4 record) { foreach (var skill in record.skills) { SkillDef def = FindSkillDef(pawn.Pawn, skill.name); if (def == null) { - Log.Warning("Could not load skill definition \"" + skill.name + "\" from saved preset"); + Logger.Warning("Could not load skill definition \"" + skill.name + "\" from saved preset"); Failed = true; continue; } @@ -512,12 +512,12 @@ public CustomPawn LoadPawn(SaveRecordPawnV4 record) { // Find the pawn layer for the saved apparel record. PawnLayer layer = apparelLayers.FirstOrDefault((apparelLayer) => { return apparelLayer.Name == apparelRecord.layer; }); if (layer == null) { - Log.Warning("Could not find a matching pawn layer for the saved apparel \"" + apparelRecord.layer + "\""); + Logger.Warning("Could not find a matching pawn layer for the saved apparel \"" + apparelRecord.layer + "\""); Failed = true; continue; } if (apparelRecord.apparel.NullOrEmpty()) { - Log.Warning("Saved apparel entry for layer \"" + apparelRecord.layer + "\" had an empty apparel def"); + Logger.Warning("Saved apparel entry for layer \"" + apparelRecord.layer + "\" had an empty apparel def"); Failed = true; continue; } @@ -528,7 +528,7 @@ public CustomPawn LoadPawn(SaveRecordPawnV4 record) { ThingDef def = DefDatabase.GetNamedSilentFail(apparelRecord.apparel); if (def == null) { - Log.Warning("Could not load thing definition for apparel \"" + apparelRecord.apparel + "\""); + Logger.Warning("Could not load thing definition for apparel \"" + apparelRecord.apparel + "\""); Failed = true; continue; } @@ -536,7 +536,7 @@ public CustomPawn LoadPawn(SaveRecordPawnV4 record) { if (!string.IsNullOrEmpty(apparelRecord.stuff)) { stuffDef = DefDatabase.GetNamedSilentFail(apparelRecord.stuff); if (stuffDef == null) { - Log.Warning("Could not load stuff definition \"" + apparelRecord.stuff + "\" for apparel \"" + apparelRecord.apparel + "\""); + Logger.Warning("Could not load stuff definition \"" + apparelRecord.stuff + "\" for apparel \"" + apparelRecord.apparel + "\""); Failed = true; continue; } @@ -554,7 +554,7 @@ public CustomPawn LoadPawn(SaveRecordPawnV4 record) { uniqueBodyPart = FindReplacementBodyPart(healthOptions, implantRecord.bodyPart); } if (uniqueBodyPart == null) { - Log.Warning("Prepare Carefully could not add the implant because it could not find the needed body part \"" + implantRecord.bodyPart + "\"" + Logger.Warning("Could not add the implant because it could not find the needed body part \"" + implantRecord.bodyPart + "\"" + (implantRecord.bodyPartIndex != null ? " with index " + implantRecord.bodyPartIndex : "")); Failed = true; continue; @@ -563,7 +563,7 @@ public CustomPawn LoadPawn(SaveRecordPawnV4 record) { if (implantRecord.recipe != null) { RecipeDef recipeDef = FindRecipeDef(implantRecord.recipe); if (recipeDef == null) { - Log.Warning("Prepare Carefully could not add the implant because it could not find the recipe definition \"" + implantRecord.recipe + "\""); + Logger.Warning("Could not add the implant because it could not find the recipe definition \"" + implantRecord.recipe + "\""); Failed = true; continue; } @@ -575,7 +575,7 @@ public CustomPawn LoadPawn(SaveRecordPawnV4 record) { } } if (!found) { - Log.Warning("Prepare carefully could not apply the saved implant recipe \"" + implantRecord.recipe + "\" to the body part \"" + bodyPart.def.defName + "\". Recipe does not support that part."); + Logger.Warning("Could not apply the saved implant recipe \"" + implantRecord.recipe + "\" to the body part \"" + bodyPart.def.defName + "\". Recipe does not support that part."); Failed = true; continue; } @@ -590,13 +590,13 @@ public CustomPawn LoadPawn(SaveRecordPawnV4 record) { foreach (var injuryRecord in record.injuries) { HediffDef def = DefDatabase.GetNamedSilentFail(injuryRecord.hediffDef); if (def == null) { - Log.Warning("Prepare Carefully could not add the injury because it could not find the hediff definition \"" + injuryRecord.hediffDef + "\""); + Logger.Warning("Could not add the injury because it could not find the hediff definition \"" + injuryRecord.hediffDef + "\""); Failed = true; continue; } InjuryOption option = healthOptions.FindInjuryOptionByHediffDef(def); if (option == null) { - Log.Warning("Prepare Carefully could not add the injury because it could not find a matching injury option for the saved hediff \"" + injuryRecord.hediffDef + "\""); + Logger.Warning("Could not add the injury because it could not find a matching injury option for the saved hediff \"" + injuryRecord.hediffDef + "\""); Failed = true; continue; } @@ -608,7 +608,7 @@ public CustomPawn LoadPawn(SaveRecordPawnV4 record) { uniquePart = FindReplacementBodyPart(healthOptions, injuryRecord.bodyPart); } if (uniquePart == null) { - Log.Warning("Prepare Carefully could not add the injury because it could not find the needed body part \"" + injuryRecord.bodyPart + "\"" + Logger.Warning("Could not add the injury because it could not find the needed body part \"" + injuryRecord.bodyPart + "\"" + (injuryRecord.bodyPartIndex != null ? " with index " + injuryRecord.bodyPartIndex : "")); Failed = true; continue; @@ -662,19 +662,19 @@ public CustomRelationship LoadRelationship(SaveRecordRelationshipV3 saved, List< result.inverseDef = PrepareCarefully.Instance.RelationshipManager.FindInverseRelationship(result.def); } if (result.def == null) { - Log.Warning("Couldn't find relationship definition: " + saved.relation); + Logger.Warning("Couldn't find relationship definition: " + saved.relation); return null; } else if (result.source == null) { - Log.Warning("Couldn't find relationship source pawn: " + saved.source); + Logger.Warning("Couldn't find relationship source pawn: " + saved.source); return null; } else if (result.target == null) { - Log.Warning("Couldn't find relationship target pawn: " + saved.source); + Logger.Warning("Couldn't find relationship target pawn: " + saved.source); return null; } else if (result.inverseDef == null) { - Log.Warning("Couldn't determine inverse relationship: " + saved.relation); + Logger.Warning("Couldn't determine inverse relationship: " + saved.relation); return null; } return result; @@ -714,7 +714,7 @@ public Backstory FindBackstory(string name) { return b.identifier.StartsWith(backstoryMinusVersioning); }); if (matchingBackstory != null) { - Log.Message("Found replacement backstory. Using " + matchingBackstory.identifier + " in place of " + name); + Logger.Message("Found replacement backstory. Using " + matchingBackstory.identifier + " in place of " + name); } } return matchingBackstory; diff --git a/Source/Version5/PawnLoaderV5.cs b/Source/Version5/PawnLoaderV5.cs index 757546e..1977d5f 100644 --- a/Source/Version5/PawnLoaderV5.cs +++ b/Source/Version5/PawnLoaderV5.cs @@ -76,7 +76,7 @@ protected void InitializeSkillDefReplacements() { public void AddBodyPartReplacement(string name, string newPart, int index) { BodyPartDef def = DefDatabase.GetNamedSilentFail(newPart); if (def == null) { - Log.Warning("Could not find body part definition \"" + newPart + "\" to replace body part \"" + name + "\""); + Logger.Warning("Could not find body part definition \"" + newPart + "\" to replace body part \"" + name + "\""); return; } bodyPartReplacements.Add(name, new ReplacementBodyPart(def, index)); @@ -97,13 +97,13 @@ public CustomPawn Load(PrepareCarefully loadout, string name) { catch (Exception e) { Messages.Message(modString, MessageTypeDefOf.SilentInput); Messages.Message("EdB.PC.Dialog.PawnPreset.Error.Failed".Translate(), MessageTypeDefOf.RejectInput); - Log.Warning(e.ToString()); - Log.Warning("Colonist was created with the following mods: " + modString); + Logger.Warning(e.ToString()); + Logger.Warning("Colonist was created with the following mods: " + modString); return null; } } catch (Exception e) { - Log.Error("Failed to load preset file"); + Logger.Error("Failed to load preset file"); throw e; } finally { @@ -113,7 +113,7 @@ public CustomPawn Load(PrepareCarefully loadout, string name) { if (pawnRecord == null) { Messages.Message(modString, MessageTypeDefOf.SilentInput); Messages.Message("EdB.PC.Dialog.PawnPreset.Error.Failed".Translate(), MessageTypeDefOf.RejectInput); - Log.Warning("Colonist was created with the following mods: " + modString); + Logger.Warning("Colonist was created with the following mods: " + modString); return null; } @@ -315,7 +315,7 @@ public CustomPawn ConvertSaveRecordToPawn(SaveRecordPawnV5 record) { pawn.Childhood = backstory; } else { - Log.Warning("Could not load childhood backstory definition \"" + record.childhood + "\""); + Logger.Warning("Could not load childhood backstory definition \"" + record.childhood + "\""); partialFailure = true; } if (record.adulthood != null) { @@ -324,7 +324,7 @@ public CustomPawn ConvertSaveRecordToPawn(SaveRecordPawnV5 record) { pawn.Adulthood = backstory; } else { - Log.Warning("Could not load adulthood backstory definition \"" + record.adulthood + "\""); + Logger.Warning("Could not load adulthood backstory definition \"" + record.adulthood + "\""); partialFailure = true; } } diff --git a/Source/Version5/PresetLoaderV5.cs b/Source/Version5/PresetLoaderV5.cs index 2b32366..9d381c6 100644 --- a/Source/Version5/PresetLoaderV5.cs +++ b/Source/Version5/PresetLoaderV5.cs @@ -33,7 +33,7 @@ public bool Load(PrepareCarefully loadout, string presetName) { gender = (Gender)Enum.Parse(typeof(Gender), e.gender); } catch (Exception) { - Log.Warning("Failed to load gender value for animal."); + Logger.Warning("Failed to load gender value for animal."); Failed = true; continue; } @@ -46,7 +46,7 @@ public bool Load(PrepareCarefully loadout, string presetName) { equipment.Add(new EquipmentSelection(record, e.count)); } else { - Log.Warning("Could not find equipment in equipment database: " + key); + Logger.Warning("Could not find equipment in equipment database: " + key); Failed = true; continue; } @@ -58,7 +58,7 @@ public bool Load(PrepareCarefully loadout, string presetName) { if (record == null) { string thing = thingDef != null ? thingDef.defName : "null"; string stuff = stuffDef != null ? stuffDef.defName : "null"; - Log.Warning(string.Format("Could not load equipment/resource from the preset. This may be caused by an invalid thing/stuff combination: " + key)); + Logger.Warning(string.Format("Could not load equipment/resource from the preset. This may be caused by an invalid thing/stuff combination: " + key)); Failed = true; continue; } @@ -67,13 +67,13 @@ public bool Load(PrepareCarefully loadout, string presetName) { } } else { - Log.Warning("Could not load stuff definition \"" + e.stuffDef + "\" for item \"" + e.def + "\""); + Logger.Warning("Could not load stuff definition \"" + e.stuffDef + "\" for item \"" + e.def + "\""); Failed = true; } } } else { - Log.Warning("Could not load thing definition \"" + e.def + "\""); + Logger.Warning("Could not load thing definition \"" + e.def + "\""); Failed = true; } } @@ -84,12 +84,12 @@ public bool Load(PrepareCarefully loadout, string presetName) { } else { Messages.Message("EdB.PC.Dialog.Preset.Error.EquipmentFailed".Translate(), MessageTypeDefOf.ThreatBig); - Log.Warning("Failed to load equipment from preset"); + Logger.Warning("Failed to load equipment from preset"); Failed = true; } } catch (Exception e) { - Log.Error("Failed to load preset file"); + Logger.Error("Failed to load preset file"); throw e; } finally { @@ -113,14 +113,14 @@ public bool Load(PrepareCarefully loadout, string presetName) { } else { Messages.Message("EdB.PC.Dialog.Preset.Error.NoCharacter".Translate(), MessageTypeDefOf.ThreatBig); - Log.Warning("Preset was created with the following mods: " + preset.mods); + Logger.Warning("Preset was created with the following mods: " + preset.mods); } } } catch (Exception e) { Messages.Message("EdB.PC.Dialog.Preset.Error.Failed".Translate(), MessageTypeDefOf.ThreatBig); - Log.Warning(e.ToString()); - Log.Warning("Preset was created with the following mods: " + preset.mods); + Logger.Warning("Error while loading preset", e); + Logger.Warning("Preset was created with the following mods: " + preset.mods); return false; } @@ -138,13 +138,13 @@ public bool Load(PrepareCarefully loadout, string presetName) { foreach (SaveRecordRelationshipV3 r in preset.relationships) { if (string.IsNullOrEmpty(r.source) || string.IsNullOrEmpty(r.target) || string.IsNullOrEmpty(r.relation)) { atLeastOneRelationshipFailed = true; - Log.Warning("Prepare Carefully failed to load a custom relationship from the preset: " + r); + Logger.Warning("Failed to load a custom relationship from the preset: " + r); continue; } CustomRelationship relationship = LoadRelationship(r, allPawns); if (relationship == null) { atLeastOneRelationshipFailed = true; - Log.Warning("Prepare Carefully failed to load a custom relationship from the preset: " + r); + Logger.Warning("Failed to load a custom relationship from the preset: " + r); } else { allRelationships.Add(relationship); @@ -153,8 +153,8 @@ public bool Load(PrepareCarefully loadout, string presetName) { } catch (Exception e) { Messages.Message("EdB.PC.Dialog.Preset.Error.RelationshipFailed".Translate(), MessageTypeDefOf.ThreatBig); - Log.Warning(e.ToString()); - Log.Warning("Preset was created with the following mods: " + preset.mods); + Logger.Warning("Error while loading preset", e); + Logger.Warning("Preset was created with the following mods: " + preset.mods); return false; } if (atLeastOneRelationshipFailed) { @@ -175,11 +175,11 @@ public bool Load(PrepareCarefully loadout, string presetName) { group.Parents.Add(pawn); } else { - Log.Warning("Prepare Carefully could not load a custom parent relationship because it could not find a matching pawn in the relationship manager."); + Logger.Warning("Could not load a custom parent relationship because it could not find a matching pawn in the relationship manager."); } } else { - Log.Warning("Prepare Carefully could not load a custom parent relationship because it could not find a pawn with the saved identifer."); + Logger.Warning("Could not load a custom parent relationship because it could not find a pawn with the saved identifer."); } } } @@ -192,11 +192,11 @@ public bool Load(PrepareCarefully loadout, string presetName) { group.Children.Add(pawn); } else { - Log.Warning("Prepare Carefully could not load a custom child relationship because it could not find a matching pawn in the relationship manager."); + Logger.Warning("Could not load a custom child relationship because it could not find a matching pawn in the relationship manager."); } } else { - Log.Warning("Prepare Carefully could not load a custom child relationship because it could not find a pawn with the saved identifer."); + Logger.Warning("Could not load a custom child relationship because it could not find a pawn with the saved identifer."); } } } @@ -208,7 +208,7 @@ public bool Load(PrepareCarefully loadout, string presetName) { if (Failed) { Messages.Message(preset.mods, MessageTypeDefOf.SilentInput); Messages.Message("EdB.PC.Dialog.Preset.Error.ThingDefFailed".Translate(), MessageTypeDefOf.ThreatBig); - Log.Warning("Preset was created with the following mods: " + preset.mods); + Logger.Warning("Preset was created with the following mods: " + preset.mods); return false; } @@ -244,19 +244,19 @@ public CustomRelationship LoadRelationship(SaveRecordRelationshipV3 saved, List< result.inverseDef = PrepareCarefully.Instance.RelationshipManager.FindInverseRelationship(result.def); } if (result.def == null) { - Log.Warning("Couldn't find relationship definition: " + saved.relation); + Logger.Warning("Couldn't find relationship definition: " + saved.relation); return null; } else if (result.source == null) { - Log.Warning("Couldn't find relationship source pawn: " + saved.source); + Logger.Warning("Couldn't find relationship source pawn: " + saved.source); return null; } else if (result.target == null) { - Log.Warning("Couldn't find relationship target pawn: " + saved.source); + Logger.Warning("Couldn't find relationship target pawn: " + saved.source); return null; } else if (result.inverseDef == null) { - Log.Warning("Couldn't determine inverse relationship: " + saved.relation); + Logger.Warning("Couldn't determine inverse relationship: " + saved.relation); return null; } return result;