using ADOFAIRenderer.Core;
using HarmonyLib;
namespace ADOFAIRenderer.Patch.Game;
///
/// Prevents the end portal from being spawned on level tiles for the "non-tile" render option.
///
/// Patched member: scrFloor.SpawnPortalParticles(), which instantiates the animated portal prefab
/// (scrPortalParticles: glow, particles, cap and icon) as a child of the floor. The game calls it from
/// scrLevelMaker, scrController and scrFloor for the portal floor.
///
///
/// Active from stage Load when AdvancedConfig.NonTile is enabled, and only for floors that belong to
/// scrLevelMaker.listFloors (the level's tiles). See for the other tile renderers.
///
///
[HarmonyPatch(typeof(scrFloor))]
// ReSharper disable once InconsistentNaming
public class scrFloorPatch
{
/// Prefix of scrFloor.SpawnPortalParticles.
/// The floor that would receive the portal.
/// True to run the original method (spawn the portal); false to skip it (non-tile render, level floor).
[HarmonyPrefix]
[HarmonyPatch("SpawnPortalParticles")]
// ReSharper disable once InconsistentNaming
public static bool SkipPortalSpawn(scrFloor __instance)
{
if (!scrLevelMaker.instance.listFloors.Contains(__instance)) return true;
var nonTile = RenderManager.Instance.stage >= RenderStage.Load &&
RenderManager.Instance.Configuration.AdvancedConfig.NonTile;
return !nonTile;
}
///
/// Postfix of scrFloor.Start.
/// The game sets enabled = isVisible in Start(), which disables all off-screen tiles right at spawn.
/// When DisableTileCulling is enabled, force every floor to remain enabled.
///
[HarmonyPostfix]
[HarmonyPatch("Start")]
public static void ForceEnableOnStart(scrFloor __instance)
{
if (RenderManager.Instance &&
RenderManager.Instance.stage >= RenderStage.Load &&
RenderManager.Instance.Configuration.AdvancedConfig.DisableTileCulling)
{
__instance.enabled = true;
}
}
///
/// Prefix of scrFloor.OnBecameInvisible.
/// Skips disabling the floor component (enabled = false) while rendering with
/// AdvancedConfig.DisableTileCulling enabled, preventing the 1-frame update lag/glitch
/// when tiles enter the camera view.
///
[HarmonyPrefix]
[HarmonyPatch("OnBecameInvisible")]
// ReSharper disable once InconsistentNaming
public static bool PreventTileCulling(scrFloor __instance)
{
if (RenderManager.Instance &&
RenderManager.Instance.stage >= RenderStage.Load &&
RenderManager.Instance.Configuration.AdvancedConfig.DisableTileCulling)
{
return false;
}
return true;
}
}