Optimized gizmo injection

This commit is contained in:
amevarashi 2022-03-23 21:27:06 +05:00
parent 55e55fbc35
commit e67010239b
2 changed files with 15 additions and 31 deletions

View file

@ -17,43 +17,27 @@ namespace RJW_Menstruation
return; return;
} }
List<Gizmo> gizmoList = __result.ToList();
if (__instance.ShouldShowWombGizmo()) if (__instance.ShouldShowWombGizmo())
{ {
AddWombGizmos(__instance, ref gizmoList); __result = AddWombGizmos(__instance, __result);
}
} }
//if (Configurations.EnableWombIcon && __instance.gender == Gender.Female) private static IEnumerable<Gizmo> AddWombGizmos(Pawn __instance, IEnumerable<Gizmo> gizmos)
//{
// if (!__instance.IsAnimal())
// {
// AddWombGizmos(__instance, ref gizmoList);
// }
// else if (Configurations.EnableAnimalCycle)
// {
// AddWombGizmos(__instance, ref gizmoList);
// }
//}
__result = gizmoList;
}
private static void AddWombGizmos(Pawn __instance, ref List<Gizmo> gizmoList)
{ {
foreach (Gizmo gizmo in gizmos)
yield return gizmo;
HediffComp_Menstruation comp = __instance.GetMenstruationComp(); HediffComp_Menstruation comp = __instance.GetMenstruationComp();
if (comp != null) AddMenstruationGizmos(__instance, comp, ref gizmoList); if (comp == null) yield break;
foreach (Gizmo gizmo in GetMenstruationGizmos(__instance, comp))
yield return gizmo;
} }
private static void AddMenstruationGizmos(Pawn pawn, HediffComp_Menstruation comp, ref List<Gizmo> gizmolist) public static List<Gizmo> GetMenstruationGizmos(Pawn pawn, HediffComp_Menstruation comp)
{ {
gizmolist.Add(CreateGizmo_WombStatus(pawn, comp)); return new List<Gizmo>() { CreateGizmo_WombStatus(pawn, comp) };
} }

View file

@ -13,15 +13,15 @@ using HarmonyLib;
namespace RJW_Menstruation.Sexperience namespace RJW_Menstruation.Sexperience
{ {
[HarmonyPatch(typeof(Pawn_GetGizmos), "AddMenstruationGizmos")] [HarmonyPatch(typeof(Pawn_GetGizmos), nameof(Pawn_GetGizmos.GetMenstruationGizmos))]
public static class GetGizmos_Patch public static class GetGizmos_Patch
{ {
public static void Postfix(Pawn pawn, HediffComp_Menstruation comp, ref List<Gizmo> gizmolist) public static void Postfix(Pawn pawn, HediffComp_Menstruation comp, ref List<Gizmo> __result)
{ {
gizmolist.Add(CreateGizmo_GatherCum(pawn, comp)); __result.Add(CreateGizmo_GatherCum(comp));
} }
private static Gizmo CreateGizmo_GatherCum(Pawn pawn, HediffComp_Menstruation comp) private static Gizmo CreateGizmo_GatherCum(HediffComp_Menstruation comp)
{ {
Texture2D icon = TextureCache.GatherCum_Bucket; Texture2D icon = TextureCache.GatherCum_Bucket;
string label = Keyed.RS_GatherCum; string label = Keyed.RS_GatherCum;