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;
}
}