using ADOFAIRenderer.Core;
using HarmonyLib;
namespace ADOFAIRenderer.Patch.Game;
///
/// Applies the configured color of the third (green, "wind") planet used by multi-planet levels.
///
/// Patched members: PlanetarySystem.Init(), which creates the planets including planetGreen (default color
/// RGB 0.3, 0.7, 0.0); and PlanetarySystem.ApplyMultiplanetColors(), which recolors the extra planets
/// (green, yellow, purple, ...) from the red/blue planet colors (skipped by the game when GCS.staticPlanetColors is set).
/// Both postfixes reapply the override after the game has set its color.
///
/// Active from stage Load until the stage returns to None. The fire/ice colors are handled by .
///
[HarmonyPatch(typeof(PlanetarySystem))]
public static class PlanetarySystemPatch
{
/// Postfix of PlanetarySystem.Init: applies the wind planet color override to the new planets.
/// The planetary system that was initialized.
[HarmonyPostfix]
[HarmonyPatch("Init")]
// ReSharper disable once InconsistentNaming
public static void OnInit(PlanetarySystem __instance)
{
ApplyWindPlanetColor(__instance);
}
/// Postfix of PlanetarySystem.ApplyMultiplanetColors: reapplies the wind planet color override.
/// The planetary system whose extra planet colors were updated.
[HarmonyPostfix]
[HarmonyPatch("ApplyMultiplanetColors")]
// ReSharper disable once InconsistentNaming
public static void OnApplyMultiplanetColors(PlanetarySystem __instance)
{
ApplyWindPlanetColor(__instance);
}
///
/// Sets planetGreen's renderer color to AdvancedConfig.windPlanetColor when a render is in progress
/// (stage != None) and the override is set. Does nothing when the override is null or the planet does not exist.
///
/// The planetary system to update.
private static void ApplyWindPlanetColor(PlanetarySystem planetarySystem)
{
if (RenderManager.Instance == null || RenderManager.Instance.stage == RenderStage.None) return;
var advConf = RenderManager.Instance.Configuration.AdvancedConfig;
if (advConf.windPlanetColor.HasValue && planetarySystem.planetGreen)
{
planetarySystem.planetGreen.planetRenderer.SetColor(new PlanetColor(advConf.windPlanetColor.Value));
}
}
}