Skip to content

Commit

Permalink
feat: simplified FemtoHelper's CustomMoonCreature
Browse files Browse the repository at this point in the history
  • Loading branch information
DemoJameson committed Feb 20, 2024
1 parent 7959425 commit 42fe634
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public static class HitboxSimplified {
"Celeste.Mod.JungleHelper.Entities.Firefly",
"Celeste.Mod.ClutterHelper.CustomClutter",
"Celeste.Mod.HonlyHelper.FloatyBgTile",
"BrokemiaHelper.PixelRendered.Vineinator",
};

public static Dictionary<Follower, bool> Followers = new();
Expand All @@ -52,8 +53,14 @@ private static void Initialize() {
UselessTypes.Add(type);
}
}

HookHelper.SkipMethod(typeof(HitboxSimplified), nameof(IsSimplifiedHitboxes), "DebugRender",
ModUtils.GetType("FemtoHelper", "CustomMoonCreature")
);
}

private static bool IsSimplifiedHitboxes() => TasSettings.ShowHitboxes && TasSettings.SimplifiedHitboxes;

[Load]
private static void Load() {
IL.Monocle.Entity.DebugRender += ModDebugRender;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ public static class SimplifiedGraphicsFeature {
"4-cliffside/bridge_a",
};

private static readonly List<Type> ClutteredTypes = new() {
typeof(FloatingDebris), typeof(MoonCreature), typeof(ResortLantern)
};

private static bool lastSimplifiedGraphics = TasSettings.SimplifiedGraphics;
private static SolidTilesStyle currentSolidTilesStyle;
private static bool creatingSolidTiles;
Expand Down Expand Up @@ -202,19 +206,20 @@ private static void Initialize() {
ModUtils.GetType("ContortHelper", "ContortHelper.BetterLightningStrike")
);


HookHelper.SkipMethod(t, nameof(IsSimplifiedClutteredEntity), "Render",
typeof(ReflectionTentacles), typeof(SummitCloud), typeof(TempleEye), typeof(Wire),
typeof(Cobweb), typeof(HangingLamp),
typeof(DustGraphic).GetNestedType("Eyeballs", BindingFlags.NonPublic),
ModUtils.GetType("BrokemiaHelper", "BrokemiaHelper.PixelRendered.PixelComponent")
);
HookHelper.SkipMethod(t, nameof(IsSimplifiedClutteredEntity), "DebugRender",
ModUtils.GetType("BrokemiaHelper", "BrokemiaHelper.PixelRendered.PixelComponent")
);
On.Celeste.FloatingDebris.ctor_Vector2 += FloatingDebris_ctor;
On.Celeste.MoonCreature.ctor_Vector2 += MoonCreature_ctor;
On.Celeste.ResortLantern.ctor_Vector2 += ResortLantern_ctor;
if (ModUtils.GetType("FemtoHelper", "CustomMoonCreature") is { } customMoonCreatureType
&& customMoonCreatureType.GetMethodInfo("Added") is { } customMoonCreatureAdded) {
customMoonCreatureAdded.HookAfter<Entity>(CustomMoonCreatureAdded);
ClutteredTypes.Add(customMoonCreatureType);
}

HookHelper.SkipMethod(
t,
Expand Down Expand Up @@ -282,9 +287,11 @@ private static void OnSimplifiedGraphicsChanged(bool simplifiedGraphics) {
return;
}

if (simplifiedGraphics) {
level.Tracker.GetEntities<FloatingDebris>().ForEach(debris => debris.RemoveSelf());
level.Entities.FindAll<MoonCreature>().ForEach(creature => creature.RemoveSelf());
if (simplifiedGraphics && TasSettings.SimplifiedClutteredEntity) {
IEnumerable<Entity> clutteredEntities = level.Entities.Where(e => ClutteredTypes.Any(t => e.GetType().IsSameOrSubclassOf(t)));
foreach (Entity entity in clutteredEntities) {
entity.RemoveSelf();
}
}

if (simplifiedGraphics && currentSolidTilesStyle != TasSettings.SimplifiedSolidTilesStyle ||
Expand Down Expand Up @@ -559,6 +566,12 @@ private static void ResortLantern_ctor(On.Celeste.ResortLantern.orig_ctor_Vector
}
}

private static void CustomMoonCreatureAdded(Entity customMoonCreature) {
if (IsSimplifiedClutteredEntity()) {
customMoonCreature.Add(new RemoveSelfComponent());
}
}

private static void LightningRenderer_RenderIL(ILContext il) {
ILCursor c = new(il);
if (c.TryGotoNext(i => i.MatchLdfld<Entity>("Visible"))) {
Expand Down
2 changes: 1 addition & 1 deletion CelesteTAS-EverestInterop/Source/Utils/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ public static long GetCustomHashCode<T>(this IEnumerable<T> enumerable) {

internal static class TypeExtensions {
public static bool IsSameOrSubclassOf(this Type potentialDescendant, Type potentialBase) {
return potentialDescendant.IsSubclassOf(potentialBase) || potentialDescendant == potentialBase;
return potentialDescendant == potentialBase || potentialDescendant.IsSubclassOf(potentialBase);
}

public static bool IsSameOrSubclassOf(this Type potentialDescendant, params Type[] potentialBases) {
Expand Down

0 comments on commit 42fe634

Please sign in to comment.