Skip to content

Commit

Permalink
Per callback enables for Blocker Registry
Browse files Browse the repository at this point in the history
  • Loading branch information
perkinslr committed Oct 16, 2023
1 parent 3bc0133 commit 1b6590a
Showing 1 changed file with 30 additions and 15 deletions.
45 changes: 30 additions & 15 deletions Source/CombatExtended/Compatibility/BlockerRegistry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,58 +11,73 @@ namespace CombatExtended.Compatibility
{
public static class BlockerRegistry
{
private static bool enabled = false;
private static bool enabledCB = false;
private static bool enabledCFC = false;
private static bool enabledIS = false;
private static bool enabledBCW = false;
private static List<Func<ProjectileCE, Vector3, Vector3, bool>> checkForCollisionBetweenCallbacks;
private static List<Func<ProjectileCE, IntVec3, Thing, bool>> checkCellForCollisionCallbacks;
private static List<Func<ProjectileCE, Thing, bool>> impactSomethingCallbacks;
private static List<Func<ProjectileCE, Thing, bool>> beforeCollideWithCallbacks;

private static void Enable()
private static void EnableCB()
{
enabled = true;
enabledCB = true;
checkForCollisionBetweenCallbacks = new List<Func<ProjectileCE, Vector3, Vector3, bool>>();
}
private static void EnableIS()
{
enabledIS = true;
impactSomethingCallbacks = new List<Func<ProjectileCE, Thing, bool>>();
}
private static void EnableCFC()
{
enabledCFC = true;
checkCellForCollisionCallbacks = new List<Func<ProjectileCE, IntVec3, Thing, bool>>();
}
private static void EnableBCW()
{
enabledBCW = true;
beforeCollideWithCallbacks = new List<Func<ProjectileCE, Thing, bool>>();
}

public static void RegisterCheckForCollisionBetweenCallback(Func<ProjectileCE, Vector3, Vector3, bool> f)
{
if (!enabled)
if (!enabledCB)
{
Enable();
EnableCB();
}
checkForCollisionBetweenCallbacks.Add(f);
}

public static void RegisterCheckForCollisionCallback(Func<ProjectileCE, IntVec3, Thing, bool> f)
{
if (!enabled)
if (!enabledCFC)
{
Enable();
EnableCFC();
}
checkCellForCollisionCallbacks.Add(f);
}

public static void RegisterImpactSomethingCallback(Func<ProjectileCE, Thing, bool> f)
{
if (!enabled)
if (!enabledIS)
{
Enable();
EnableIS();
}
impactSomethingCallbacks.Add(f);
}
public static void RegisterBeforeCollideWithCallback(Func<ProjectileCE, Thing, bool> f)
{
if (!enabled)
if (!enabledBCW)
{
Enable();
EnableBCW();
}
beforeCollideWithCallbacks.Add(f);
}
public static bool CheckForCollisionBetweenCallback(ProjectileCE projectile, Vector3 from, Vector3 to)
{
if (!enabled)
if (!enabledCB)
{
return false;
}
Expand All @@ -78,7 +93,7 @@ public static bool CheckForCollisionBetweenCallback(ProjectileCE projectile, Vec

public static bool CheckCellForCollisionCallback(ProjectileCE projectile, IntVec3 cell, Thing launcher)
{
if (!enabled)
if (!enabledCFC)
{
return false;
}
Expand All @@ -94,7 +109,7 @@ public static bool CheckCellForCollisionCallback(ProjectileCE projectile, IntVec

public static bool ImpactSomethingCallback(ProjectileCE projectile, Thing launcher)
{
if (!enabled)
if (!enabledIS)
{
return false;
}
Expand All @@ -110,7 +125,7 @@ public static bool ImpactSomethingCallback(ProjectileCE projectile, Thing launch

public static bool BeforeCollideWithCallback(ProjectileCE projectile, Thing collideWith)
{
if (!enabled)
if (!enabledBCW)
{
return false;
}
Expand Down

0 comments on commit 1b6590a

Please sign in to comment.