Skip to content

Commit

Permalink
Added prefix to Reflection utility classes to avoid namespace conflic…
Browse files Browse the repository at this point in the history
…t confusion
  • Loading branch information
edbmods committed Dec 26, 2022
1 parent 71ecc1c commit fd85c5c
Show file tree
Hide file tree
Showing 11 changed files with 25 additions and 31 deletions.
2 changes: 1 addition & 1 deletion Source/ColonistFiles.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public static class ColonistFiles {
public static string SavedColonistsFolderPath {
get {
try {
return Reflection.GenFilePaths.FolderUnderSaveData("PrepareCarefully");
return Reflection.ReflectorGenFilePaths.FolderUnderSaveData("PrepareCarefully");
}
catch (Exception e) {
Logger.Error("Failed to get colonist save directory");
Expand Down
4 changes: 2 additions & 2 deletions Source/ControllerPawns.cs
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,9 @@ public void RandomizeBackstories() {
float adultStoryAge = alienRace == null ? providerAlienRaces.DefaultMinAgeForAdulthood : alienRace.MinAgeForAdulthood;
//Logger.Debug(String.Format("Adulthood age for {0} is {1}", state.CurrentPawn.Pawn.def.defName, adultStoryAge));

List<BackstoryCategoryFilter> backstoryCategoryFiltersFor = Reflection.PawnBioAndNameGenerator.GetBackstoryCategoryFiltersFor(currentPawn.Pawn, factionDef);
List<BackstoryCategoryFilter> backstoryCategoryFiltersFor = Reflection.ReflectorPawnBioAndNameGenerator.GetBackstoryCategoryFiltersFor(currentPawn.Pawn, factionDef);
// Generate a bio from which to get the backstories
if (!Reflection.PawnBioAndNameGenerator.TryGetRandomUnusedSolidBioFor(backstoryCategoryFiltersFor, kindDef, currentPawn.Gender, null, out PawnBio pawnBio)) {
if (!Reflection.ReflectorPawnBioAndNameGenerator.TryGetRandomUnusedSolidBioFor(backstoryCategoryFiltersFor, kindDef, currentPawn.Gender, null, out PawnBio pawnBio)) {
// Other mods are patching the vanilla method in ways that cause it to return false. If that happens,
// we use our duplicate implementation instead.
var providerBackstories = PrepareCarefully.Instance.Providers.Backstories;
Expand Down
2 changes: 1 addition & 1 deletion Source/CustomPawn.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1501,7 +1501,7 @@ public string ResetCachedIncapableOf() {
List<string> incapableList = new List<string>();
WorkTags combinedDisabledWorkTags = pawn.story.DisabledWorkTagsBackstoryAndTraits;
if (combinedDisabledWorkTags != WorkTags.None) {
IEnumerable<WorkTags> list = Reflection.CharacterCardUtility.WorkTagsFrom(combinedDisabledWorkTags);
IEnumerable<WorkTags> list = Reflection.ReflectorCharacterCardUtility.WorkTagsFrom(combinedDisabledWorkTags);
foreach (var tag in list) {
incapableList.Add(WorkTypeDefsUtility.LabelTranslated(tag).CapitalizeFirst());
}
Expand Down
6 changes: 3 additions & 3 deletions Source/ExtensionsPawn.cs
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,8 @@ public static void ClearCachedDisabledSkillRecords(this Pawn pawn) {
if (pawn.skills != null && pawn.skills.skills != null) {
pawn.skills.Notify_SkillDisablesChanged();
}
Reflection.Pawn.ClearCachedDisabledWorkTypes(pawn);
Reflection.Pawn.ClearCachedDisabledWorkTypesPermanent(pawn);
Reflection.ReflectorPawn.ClearCachedDisabledWorkTypes(pawn);
Reflection.ReflectorPawn.ClearCachedDisabledWorkTypesPermanent(pawn);
}

public static void ClearCachedHealth(this Pawn pawn) {
Expand Down Expand Up @@ -167,7 +167,7 @@ public static CustomXenotype MatchGenesToCustomXenotype(this Pawn pawn) {
if (!ModsConfig.BiotechActive) {
return null;
}
var customXenotypes = Reflection.CharacterCardUtility.CustomXenotypes;
var customXenotypes = Reflection.ReflectorCharacterCardUtility.CustomXenotypes;
if (customXenotypes == null) {
return null;
}
Expand Down
2 changes: 1 addition & 1 deletion Source/Injury.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public override void AddToPawn(CustomPawn customPawn, Pawn pawn) {
HediffComp_GetsPermanent getsPermanent = hediff.TryGetComp<HediffComp_GetsPermanent>();
if (getsPermanent != null) {
getsPermanent.IsPermanent = true;
Reflection.HediffComp_GetsPermanent.SetPainCategory(getsPermanent, PainCategoryForFloat(painFactor == null ? 0 : painFactor.Value));
Reflection.ReflectorHediffComp_GetsPermanent.SetPainCategory(getsPermanent, PainCategoryForFloat(painFactor == null ? 0 : painFactor.Value));
}

pawn.health.AddHediff(hediff, BodyPartRecord);
Expand Down
6 changes: 3 additions & 3 deletions Source/PawnBioGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ public static bool TryGetRandomUnusedSolidBioFor(List<BackstoryCategoryFilter> b
});
// Settle for a default category filter if none was chosen.
if (categoryFilter == null) {
categoryFilter = Reflection.PawnBioAndNameGenerator.GetFallbackCategoryGroup();
categoryFilter = Reflection.ReflectorPawnBioAndNameGenerator.GetFallbackCategoryGroup();
}
// Choose a weighted bio.
return (from bio in SolidBioDatabase.allBios.TakeRandom(20)
where Reflection.PawnBioAndNameGenerator.IsBioUseable(bio, categoryFilter, kind, gender, requiredLastName)
select bio).TryRandomElementByWeight(new Func<PawnBio, float>(Reflection.PawnBioAndNameGenerator.BioSelectionWeight), out result);
where Reflection.ReflectorPawnBioAndNameGenerator.IsBioUseable(bio, categoryFilter, kind, gender, requiredLastName)
select bio).TryRandomElementByWeight(new Func<PawnBio, float>(Reflection.ReflectorPawnBioAndNameGenerator.BioSelectionWeight), out result);
}
}
}
2 changes: 1 addition & 1 deletion Source/PrepareCarefully.cs
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ private static PawnKindDef RandomPet(ScenPart_StartingAnimal startingAnimal) {
return animalKindDef;
}
if (animalKindDef == null) {
IEnumerable<PawnKindDef> animalKindDefs = Reflection.ScenPart_StartingAnimal.RandomPets(startingAnimal);
IEnumerable<PawnKindDef> animalKindDefs = Reflection.ReflectorScenPart_StartingAnimal.RandomPets(startingAnimal);
if (animalKindDefs != null) {
var enumerator = animalKindDefs.GetEnumerator();
if (enumerator != null) {
Expand Down
2 changes: 1 addition & 1 deletion Source/PresetFiles.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public static class PresetFiles {
public static string SavedPresetsFolderPath {
get {
try {
return Reflection.GenFilePaths.FolderUnderSaveData("PrepareCarefully");
return Reflection.ReflectorGenFilePaths.FolderUnderSaveData("PrepareCarefully");
}
catch (Exception e) {
Logger.Error("Failed to get preset save directory");
Expand Down
2 changes: 1 addition & 1 deletion Source/PresetLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public static bool LoadFromFile(PrepareCarefully loadout, string presetName) {
public static void ClearSaveablesAndCrossRefs() {
// I don't fully understand how these cross-references and saveables are resolved, but
// if we don't clear them out, we get null pointer exceptions.
Reflection.PostLoadIniter.ClearSaveablesToPostLoad(Scribe.loader.initer);
Reflection.ReflectorPostLoadIniter.ClearSaveablesToPostLoad(Scribe.loader.initer);
if (Scribe.loader.crossRefs.crossReferencingExposables != null) {
Scribe.loader.crossRefs.crossReferencingExposables.Clear();
}
Expand Down
2 changes: 1 addition & 1 deletion Source/ProviderHealthOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ protected void InitializeInjuryOptions(OptionsHealth options, ThingDef pawnThing
// Get all of the hediffs that can be added via the "forced hediff" scenario part and
// add them to a hash set so that we can quickly look them up.
ScenPart_ForcedHediff scenPart = new ScenPart_ForcedHediff();
IEnumerable<HediffDef> scenPartDefs = Reflection.ScenPart_ForcedHediff.PossibleHediffs(scenPart);
IEnumerable<HediffDef> scenPartDefs = Reflection.ReflectorScenPart_ForcedHediff.PossibleHediffs(scenPart);
HashSet<HediffDef> scenPartDefSet = new HashSet<HediffDef>(scenPartDefs);

// Add injury options.
Expand Down
26 changes: 10 additions & 16 deletions Source/Reflection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,46 +9,41 @@

namespace EdB.PrepareCarefully {
namespace Reflection {
public static class CharacterCardUtility {
public static class ReflectorCharacterCardUtility {
public static IEnumerable<WorkTags> WorkTagsFrom(WorkTags workTags) {
return (IEnumerable<WorkTags>)ReflectionCache.Instance.CharacterCardUtility_WorkTagsFrom.Invoke(null, new object[] { workTags });
}
public static List<CustomXenotype> CustomXenotypes {
get {
return ReflectionUtil.GetStaticPropertyValue<List<CustomXenotype>>(typeof(RimWorld.CharacterCardUtility), "CustomXenotypes");
return ReflectionUtil.GetStaticPropertyValue<List<CustomXenotype>>(typeof(CharacterCardUtility), "CustomXenotypes");
}
}
}

public static class ScenPart_StartingAnimal {
public static class ReflectorScenPart_StartingAnimal {
public static IEnumerable<PawnKindDef> RandomPets(RimWorld.ScenPart_StartingAnimal scenPart) {
return (IEnumerable<PawnKindDef>)ReflectionCache.Instance.ScenPart_StartingAnimal_RandomPets.Invoke(scenPart, null);
}
}
public static class GenFilePaths {
public static class ReflectorGenFilePaths {
public static string FolderUnderSaveData(string name) {
return (string)ReflectionCache.Instance.GenFilePaths_FolderUnderSaveData.Invoke(null, new object[] { name });
}
}
public static class ScenPart_ForcedHediff {
public static IEnumerable<HediffDef> PossibleHediffs(RimWorld.ScenPart_ForcedHediff scenPart) {
public static class ReflectorScenPart_ForcedHediff {
public static IEnumerable<HediffDef> PossibleHediffs(ScenPart_ForcedHediff scenPart) {
return (IEnumerable<HediffDef>)ReflectionCache.Instance.ScenPart_ForcedHediff_PossibleHediffs.Invoke(scenPart, null);
}
}
//public static class GraphicDatabaseHeadRecords {
// public static void BuildDatabaseIfNecessary() {
// ReflectionCache.Instance.GraphicDatabaseHeadRecords_BuildDatabaseIfNecessary.Invoke(null, null);
// }
//}
public static class Pawn {
public static class ReflectorPawn {
public static void ClearCachedDisabledWorkTypes(Verse.Pawn pawn) {
ReflectionCache.Instance.Pawn_CachedDisabledWorkTypes.SetValue(pawn, null);
}
public static void ClearCachedDisabledWorkTypesPermanent(Verse.Pawn pawn) {
ReflectionCache.Instance.Pawn_CachedDisabledWorkTypesPermanent.SetValue(pawn, null);
}
}
public static class PawnBioAndNameGenerator {
public static class ReflectorPawnBioAndNameGenerator {
public static float BioSelectionWeight(PawnBio b) {
return (float)ReflectionCache.Instance.PawnBioAndNameGenerator_BioSelectionWeight.Invoke(null,
new object[] { b }
Expand Down Expand Up @@ -77,16 +72,15 @@ public static List<string> GetTmpNames() {
return (List<string>)ReflectionCache.Instance.PawnBioAndNameGenerator_tmpNames.GetValue(null);
}
}
public static class PostLoadIniter {
public static class ReflectorPostLoadIniter {
public static void ClearSaveablesToPostLoad(Verse.PostLoadIniter initer) {
HashSet<IExposable> saveables = (HashSet<IExposable>)ReflectionCache.Instance.PostLoadIniter_SaveablesToPostLoad.GetValue(Scribe.loader.initer);
if (saveables != null) {
saveables.Clear();
}
}
}

public static class HediffComp_GetsPermanent {
public static class ReflectorHediffComp_GetsPermanent {
public static void SetPainCategory(Verse.HediffComp_GetsPermanent comp, PainCategory painCategory) {
ReflectionCache.Instance.HediffComp_GetsPermanent_PainCategory.SetValue(comp, painCategory);
}
Expand Down

0 comments on commit fd85c5c

Please sign in to comment.