Refactor DefInjection

This commit is contained in:
amevarashi 2022-06-05 00:01:45 +05:00
parent d792e93fcd
commit 61bd959ba8
1 changed files with 20 additions and 26 deletions

View File

@ -1,11 +1,7 @@
using System;
using RJWSexperience.Logs;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Verse;
using HarmonyLib;
namespace RJWSexperience
{
@ -19,17 +15,15 @@ namespace RJWSexperience
private static void InjectRaces()
{
List<ThingDef> PawnDefs = DefDatabase<ThingDef>.AllDefs.Where(x => x.race != null && !x.race.IsMechanoid).ToList();
InjectComp(PawnDefs);
}
IEnumerable<ThingDef> PawnDefs = DefDatabase<ThingDef>.AllDefs.Where(x => x.race != null && !x.race.IsMechanoid);
if (PawnDefs.EnumerableNullOrEmpty())
return;
private static void InjectComp(List<ThingDef> PawnDefs)
{
CompProperties comp = new CompProperties(typeof(SexHistoryComp));
if (!PawnDefs.NullOrEmpty()) foreach(ThingDef def in PawnDefs)
{
foreach (ThingDef def in PawnDefs)
def.comps.Add(comp);
}
LogManager.GetLogger("StaticConstructorOnStartup").Message($"Injected SexHistoryComp into {PawnDefs.Count()} pawn Defs");
}
}
}