Skip to content

Commit c56515f

Browse files
authored
Merge pull request #327 from HumabHatterZed/cost-emission-mask
Config to prevent emissions from covering play costs
2 parents 0385ea3 + 928305b commit c56515f

File tree

3 files changed

+60
-14
lines changed

3 files changed

+60
-14
lines changed

InscryptionAPI/Compatibility/TypeMapper.cs

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,11 @@ namespace APIPlugin;
1010
public class IgnoreMappingAttribute : Attribute { }
1111

1212
[Obsolete("Unnecessary", true)]
13-
public static class TypeMapper<S, D> where S : class where D : class
14-
{
13+
public static class TypeMapper<S, D> where S : class where D : class {
1514
private static Dictionary<string, MethodInfo> _accessors = null;
16-
private static Dictionary<string, MethodInfo> FieldAccessors
17-
{
18-
get
19-
{
20-
if (_accessors is null)
21-
{
15+
private static Dictionary<string, MethodInfo> FieldAccessors {
16+
get {
17+
if (_accessors is null) {
2218
_accessors = new();
2319

2420
foreach (var _field in AccessTools.GetDeclaredFields(typeof(S)).Where(x => !x.GetCustomAttributes(typeof(IgnoreMappingAttribute), false).Any()))
@@ -38,12 +34,9 @@ private static Dictionary<string, MethodInfo> FieldAccessors
3834
}
3935

4036
private static Dictionary<string, MethodInfo> _setters = null;
41-
private static Dictionary<string, MethodInfo> FieldSetters
42-
{
43-
get
44-
{
45-
if (_setters == null)
46-
{
37+
private static Dictionary<string, MethodInfo> FieldSetters {
38+
get {
39+
if (_setters == null) {
4740
_setters = new();
4841

4942
foreach (var _field in AccessTools.GetDeclaredFields(typeof(D)))
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
using DiskCardGame;
2+
using HarmonyLib;
3+
using System;
4+
using System.Collections.Generic;
5+
using System.Text;
6+
using UnityEngine;
7+
8+
namespace InscryptionCommunityPatch.Card;
9+
10+
[HarmonyPatch]
11+
public class Part1CostEmissionMaskRender {
12+
public static readonly Dictionary<CardDisplayer3D, SpriteRenderer> CostEmissionMaskRenderers = new();
13+
14+
public static SpriteRenderer Verify3DCostEmissionMaskRenderer(CardDisplayer3D cardDisplayer, bool emissionEnabled) {
15+
// add entry for new CardDisplayer3D's
16+
if (!CostEmissionMaskRenderers.TryGetValue(cardDisplayer, out SpriteRenderer result)) {
17+
//PatchPlugin.Logger.LogDebug("[Verify3DCostEmissionMaskRenderer] Add cost mask renderer to CardDisplay3D");
18+
GameObject obj = GameObject.Instantiate(cardDisplayer.costRenderer.gameObject, cardDisplayer.transform);
19+
obj.name = "CostEmissionMask";
20+
obj.layer = cardDisplayer.emissivePortraitRenderer.gameObject.layer;
21+
result = obj.GetComponent<SpriteRenderer>();
22+
result.color = Color.black;
23+
result.sortingOrder = 100;
24+
CostEmissionMaskRenderers.Add(cardDisplayer, result);
25+
}
26+
27+
if (result == null) {
28+
PatchPlugin.Logger.LogWarning("[Verify3DCostEmissionMaskRenderer] Could not find/create SpriteRenderer for CardDisplayer3D instance");
29+
}
30+
else {
31+
// disable if config is false ; otherwise toggle based on appearance of emissive portrait
32+
result.gameObject.SetActive(PatchPlugin.configCostMask.Value && emissionEnabled);
33+
}
34+
35+
return result;
36+
}
37+
38+
[HarmonyPrefix, HarmonyPatch(typeof(CardDisplayer3D), nameof(CardDisplayer3D.Awake))]
39+
private static void AddCostEmissionMaskOnAwake(CardDisplayer3D __instance) {
40+
Verify3DCostEmissionMaskRenderer(__instance, false);
41+
}
42+
43+
[HarmonyPriority(Priority.Last), HarmonyPostfix, HarmonyPatch(typeof(CardDisplayer3D), nameof(CardDisplayer3D.DisplayInfo))]
44+
private static void UpdateCostEmissionMask(CardDisplayer3D __instance) {
45+
SpriteRenderer rend = Verify3DCostEmissionMaskRenderer(__instance, __instance.emissivePortraitRenderer.gameObject.activeSelf);
46+
if (rend != null) {
47+
//PatchPlugin.Logger.LogDebug("[UpdateCostEmissionMask] Update Cost emission mask");
48+
rend.sprite = __instance.costRenderer.sprite;
49+
}
50+
}
51+
}

InscryptionCommunityPatch/InscryptionCommunityPatchPlugin.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ public class PatchPlugin : BaseUnityPlugin
3131
internal static ConfigEntry<bool> configShowSquirrelTribeOnCards;
3232
internal static ConfigEntry<bool> configAct3Bones;
3333

34+
internal static ConfigEntry<bool> configCostMask;
3435
internal static ConfigEntry<bool> configResetEyes;
3536
internal static ConfigEntry<bool> undeadCatEmission;
3637

@@ -107,6 +108,7 @@ private void Awake()
107108
configFullDebug = Config.Bind("General", "Full Debug", true, "If true, displays all debug logs in the console.");
108109
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.");
109110
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.");
111+
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.");
110112
undeadCatEmission = Config.Bind("General", "Undead Cat Emission", false, "If true, Undead Cat will have a forced red emission.");
111113
}
112114

0 commit comments

Comments
 (0)