diff --git a/InscryptionAPI/Compatibility/TypeMapper.cs b/InscryptionAPI/Compatibility/TypeMapper.cs index e4d0625c..680104cf 100644 --- a/InscryptionAPI/Compatibility/TypeMapper.cs +++ b/InscryptionAPI/Compatibility/TypeMapper.cs @@ -10,15 +10,11 @@ namespace APIPlugin; public class IgnoreMappingAttribute : Attribute { } [Obsolete("Unnecessary", true)] -public static class TypeMapper where S : class where D : class -{ +public static class TypeMapper where S : class where D : class { private static Dictionary _accessors = null; - private static Dictionary FieldAccessors - { - get - { - if (_accessors is null) - { + private static Dictionary FieldAccessors { + get { + if (_accessors is null) { _accessors = new(); foreach (var _field in AccessTools.GetDeclaredFields(typeof(S)).Where(x => !x.GetCustomAttributes(typeof(IgnoreMappingAttribute), false).Any())) @@ -38,12 +34,9 @@ private static Dictionary FieldAccessors } private static Dictionary _setters = null; - private static Dictionary FieldSetters - { - get - { - if (_setters == null) - { + private static Dictionary FieldSetters { + get { + if (_setters == null) { _setters = new(); foreach (var _field in AccessTools.GetDeclaredFields(typeof(D))) diff --git a/InscryptionCommunityPatch/Card/Part1CostEmissionMaskRender.cs b/InscryptionCommunityPatch/Card/Part1CostEmissionMaskRender.cs new file mode 100644 index 00000000..d4149a4c --- /dev/null +++ b/InscryptionCommunityPatch/Card/Part1CostEmissionMaskRender.cs @@ -0,0 +1,51 @@ +using DiskCardGame; +using HarmonyLib; +using System; +using System.Collections.Generic; +using System.Text; +using UnityEngine; + +namespace InscryptionCommunityPatch.Card; + +[HarmonyPatch] +public class Part1CostEmissionMaskRender { + public static readonly Dictionary CostEmissionMaskRenderers = new(); + + public static SpriteRenderer Verify3DCostEmissionMaskRenderer(CardDisplayer3D cardDisplayer, bool emissionEnabled) { + // add entry for new CardDisplayer3D's + if (!CostEmissionMaskRenderers.TryGetValue(cardDisplayer, out SpriteRenderer result)) { + //PatchPlugin.Logger.LogDebug("[Verify3DCostEmissionMaskRenderer] Add cost mask renderer to CardDisplay3D"); + GameObject obj = GameObject.Instantiate(cardDisplayer.costRenderer.gameObject, cardDisplayer.transform); + obj.name = "CostEmissionMask"; + obj.layer = cardDisplayer.emissivePortraitRenderer.gameObject.layer; + result = obj.GetComponent(); + result.color = Color.black; + result.sortingOrder = 100; + CostEmissionMaskRenderers.Add(cardDisplayer, result); + } + + if (result == null) { + PatchPlugin.Logger.LogWarning("[Verify3DCostEmissionMaskRenderer] Could not find/create SpriteRenderer for CardDisplayer3D instance"); + } + else { + // disable if config is false ; otherwise toggle based on appearance of emissive portrait + result.gameObject.SetActive(PatchPlugin.configCostMask.Value && emissionEnabled); + } + + return result; + } + + [HarmonyPrefix, HarmonyPatch(typeof(CardDisplayer3D), nameof(CardDisplayer3D.Awake))] + private static void AddCostEmissionMaskOnAwake(CardDisplayer3D __instance) { + Verify3DCostEmissionMaskRenderer(__instance, false); + } + + [HarmonyPriority(Priority.Last), HarmonyPostfix, HarmonyPatch(typeof(CardDisplayer3D), nameof(CardDisplayer3D.DisplayInfo))] + private static void UpdateCostEmissionMask(CardDisplayer3D __instance) { + SpriteRenderer rend = Verify3DCostEmissionMaskRenderer(__instance, __instance.emissivePortraitRenderer.gameObject.activeSelf); + if (rend != null) { + //PatchPlugin.Logger.LogDebug("[UpdateCostEmissionMask] Update Cost emission mask"); + rend.sprite = __instance.costRenderer.sprite; + } + } +} diff --git a/InscryptionCommunityPatch/InscryptionCommunityPatchPlugin.cs b/InscryptionCommunityPatch/InscryptionCommunityPatchPlugin.cs index 71937425..1ea6974d 100644 --- a/InscryptionCommunityPatch/InscryptionCommunityPatchPlugin.cs +++ b/InscryptionCommunityPatch/InscryptionCommunityPatchPlugin.cs @@ -31,6 +31,7 @@ public class PatchPlugin : BaseUnityPlugin internal static ConfigEntry configShowSquirrelTribeOnCards; internal static ConfigEntry configAct3Bones; + internal static ConfigEntry configCostMask; internal static ConfigEntry configResetEyes; internal static ConfigEntry undeadCatEmission; @@ -107,6 +108,7 @@ private void Awake() configFullDebug = Config.Bind("General", "Full Debug", true, "If true, displays all debug logs in the console."); configTestState = Config.Bind("General", "Test Mode", false, "Puts the game into test mode. This will cause (among potentially other things) a new run to spawn a number of cards into your opening deck that will demonstrate card behaviors."); configResetEyes = Config.Bind("Act 1", "Reset Red Eyes", false, "Resets Leshy's eyes to normal if they were turned red due to a boss fight's grizzly bear sequence."); + configCostMask = Config.Bind("Act 1", "Render Costs Above Emission", true, "Applies a mask to card emissions that prevents them from covering play costs when rendering in-game."); undeadCatEmission = Config.Bind("General", "Undead Cat Emission", false, "If true, Undead Cat will have a forced red emission."); }