31 lines
945 B
C#
31 lines
945 B
C#
using HarmonyLib;
|
|
using RimWorld;
|
|
using rjwquirks.Modules.Shared.Events;
|
|
using Verse;
|
|
|
|
namespace rjwquirks.HarmonyPatches
|
|
{
|
|
/// <summary>
|
|
/// Patch to generate events on record changes
|
|
/// </summary>
|
|
[HarmonyPatch(typeof(Pawn_RecordsTracker))]
|
|
public static class Patch_RecordsTracker_NotifyRecordChanged
|
|
{
|
|
[HarmonyPatch(nameof(Pawn_RecordsTracker.Increment))]
|
|
[HarmonyPostfix]
|
|
public static void IncrementPostfix(Pawn_RecordsTracker __instance, RecordDef def)
|
|
{
|
|
NotifyEvent(__instance.pawn, def);
|
|
}
|
|
|
|
[HarmonyPatch(nameof(Pawn_RecordsTracker.AddTo))]
|
|
[HarmonyPostfix]
|
|
public static void AddToPostfix(Pawn_RecordsTracker __instance, RecordDef def)
|
|
{
|
|
NotifyEvent(__instance.pawn, def);
|
|
}
|
|
|
|
private static void NotifyEvent(Pawn pawn, RecordDef def) => RjwEventManager.NotifyEvent(new RjwEvent(RjwEventDefOf.RecordChanged, pawn.Named(RjwEventArgNames.Pawn), def.Named(RjwEventArgNames.Record)));
|
|
}
|
|
}
|