2025-07-31 23:54:47 +00:00
|
|
|
using HarmonyLib;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
|
|
namespace MuzikaGromche
|
|
|
|
|
{
|
2025-08-01 22:41:49 +00:00
|
|
|
[HarmonyPatch(typeof(RoundManager))]
|
|
|
|
|
static class AllPoweredLightsPatch
|
|
|
|
|
{
|
|
|
|
|
// Vanilla method assumes that GameObjects with tag "PoweredLight" only contain a single Light component each.
|
|
|
|
|
// This is, however, not true for certains double-light setups, such as:
|
|
|
|
|
// - double PointLight (even though one of them is 'Point' another is 'Spot') inside CeilingFanAnimContainer in BedroomTile/BedroomTileB;
|
|
|
|
|
// - MineshaftSpotlight when it has not only `Point Light` but also `IndirectLight` in BirthdayRoomTile;
|
|
|
|
|
// - (maybe more?)
|
|
|
|
|
// In order to fix that, replace singular GetComponentInChildren<Light> with plural GetComponentsInChildren<Light> version.
|
|
|
|
|
[HarmonyPatch(nameof(RoundManager.RefreshLightsList))]
|
2026-04-01 03:04:37 +00:00
|
|
|
[HarmonyPostfix]
|
|
|
|
|
static void OnRefreshLightsList(RoundManager __instance)
|
2025-08-01 22:41:49 +00:00
|
|
|
{
|
2025-08-24 22:29:39 +00:00
|
|
|
var behaviour = __instance.gameObject.GetComponent<PoweredLightsBehaviour>() ?? __instance.gameObject.AddComponent<PoweredLightsBehaviour>();
|
|
|
|
|
behaviour.Refresh();
|
2025-08-01 22:41:49 +00:00
|
|
|
}
|
2025-08-24 22:29:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
internal class PoweredLightsBehaviour : MonoBehaviour
|
|
|
|
|
{
|
|
|
|
|
private struct LightData
|
|
|
|
|
{
|
|
|
|
|
public Light Light;
|
|
|
|
|
public Color InitialColor;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private readonly List<LightData> AllPoweredLights = [];
|
|
|
|
|
|
|
|
|
|
public static PoweredLightsBehaviour Instance { get; private set; } = null!;
|
|
|
|
|
|
|
|
|
|
void Awake()
|
|
|
|
|
{
|
|
|
|
|
if (Instance == null)
|
|
|
|
|
{
|
|
|
|
|
Instance = this;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Refresh()
|
|
|
|
|
{
|
|
|
|
|
AllPoweredLights.Clear();
|
|
|
|
|
foreach (var light in RoundManager.Instance.allPoweredLights)
|
|
|
|
|
{
|
|
|
|
|
AllPoweredLights.Add(new LightData
|
|
|
|
|
{
|
|
|
|
|
Light = light,
|
|
|
|
|
InitialColor = light.color,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void SetLightColor(SetLightsColorEvent e)
|
|
|
|
|
{
|
|
|
|
|
foreach (var data in AllPoweredLights)
|
|
|
|
|
{
|
|
|
|
|
var color = e.GetColor(data.InitialColor);
|
|
|
|
|
data.Light.color = color;
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-08-22 22:49:12 +00:00
|
|
|
|
2025-08-24 22:29:39 +00:00
|
|
|
public void ResetLightColor()
|
2025-08-22 22:49:12 +00:00
|
|
|
{
|
2025-08-24 22:29:39 +00:00
|
|
|
foreach (var data in AllPoweredLights)
|
2025-08-22 22:49:12 +00:00
|
|
|
{
|
2025-08-24 22:29:39 +00:00
|
|
|
data.Light.color = data.InitialColor;
|
2025-08-22 22:49:12 +00:00
|
|
|
}
|
|
|
|
|
}
|
2025-08-01 22:41:49 +00:00
|
|
|
}
|
2025-07-31 23:54:47 +00:00
|
|
|
}
|