Skip to content

Commit 5dca636

Browse files
Add config to allow for vanilla style sigil stacking in specific conditions
1 parent d7a7183 commit 5dca636

2 files changed

Lines changed: 77 additions & 29 deletions

File tree

InscryptionCommunityPatch/Card/StackAbilityIcons.cs

Lines changed: 73 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public static class StackAbilityIcons
5656

5757
private static Sprite GetGBCNumberSprite(int number)
5858
{
59-
var stackGBC = "stack_gbc.png";
59+
string stackGBC = "stack_gbc.png";
6060
if (!PatchPlugin.act2StackIconType.Value)
6161
stackGBC = "stack_gbc_alt.png";
6262

@@ -101,13 +101,6 @@ private static Color[] LEFT_BORDER
101101
private static readonly Dictionary<string, Texture2D> patchedTexture = new();
102102
private static readonly Dictionary<Ability, Tuple<Vector2Int, int>> patchLocations = new();
103103

104-
[HarmonyPatch(typeof(CardAbilityIcons), "GetDistinctShownAbilities")]
105-
[HarmonyPostfix]
106-
private static void ClearStackableIcons(ref List<Ability> __result, CardInfo info, List<CardModificationInfo> mods, List<Ability> hiddenAbilities)
107-
{
108-
__result = __result.Distinct().ToList();
109-
}
110-
111104
private static Vector2Int FindMatchingOnesDigit(Texture2D searchTex, bool normalSize = true)
112105
{
113106
Texture2D onesTexture = normalSize ? NUMBER_TEXTURES[1] : MEDIUM_NUMBER_TEXTURES[1];
@@ -301,6 +294,18 @@ private static Texture2D PatchTexture(Ability ability, int count)
301294
return newTexture;
302295
}
303296

297+
[HarmonyPatch(typeof(CardAbilityIcons), "GetDistinctShownAbilities")]
298+
[HarmonyPostfix]
299+
private static void ClearStackableIcons(ref List<Ability> __result, CardInfo info, List<CardModificationInfo> mods, List<Ability> hiddenAbilities)
300+
{
301+
int preDistinctCount = __result.Count;
302+
__result = __result.Distinct().ToList();
303+
if (PatchPlugin.doubleStackSplit.Value && __result.Count == 1 && preDistinctCount == 2 && AbilitiesUtil.GetInfo(__result[0]).canStack)
304+
{
305+
__result.Add(__result[0]);
306+
}
307+
}
308+
304309
[HarmonyPatch(typeof(AbilityIconInteractable), "AssignAbility")]
305310
[HarmonyPostfix]
306311
private static void AddIconNumber(Ability ability, CardInfo info, PlayableCard card, ref AbilityIconInteractable __instance)
@@ -312,12 +317,12 @@ private static void AddIconNumber(Ability ability, CardInfo info, PlayableCard c
312317
// Find all abilities on the card
313318
// Replace all of the textures where it stacks with a texture showing that it stacks
314319
// Okay, go through each ability on the card and see how many instances it has.
315-
List<Ability> baseAbilities = new(info.Abilities);
316320
int? count = null;
321+
List<Ability> baseAbilities = new(info.Abilities);
322+
AbilityInfo ai = AbilityManager.AllAbilityInfos.AbilityByID(ability);
317323
if (card != null)
318324
{
319-
baseAbilities.AddRange(AbilitiesUtil.GetAbilitiesFromMods(card.TemporaryMods));
320-
AbilityInfo ai = AbilityManager.AllAbilityInfos.AbilityByID(ability);
325+
baseAbilities.AddRange(AbilitiesUtil.GetAbilitiesFromMods(card.TemporaryMods/*.Where(x => !x.fromTotem && (!x.fromCardMerge || PatchPlugin.configMergeOnBottom.Value)).ToList()*/));
321326
if (ai.GetHideSingleStacks())
322327
{
323328
for (int i = 0; i < card.Status.hiddenAbilities.Count(x => x == ability); i++)
@@ -333,10 +338,15 @@ private static void AddIconNumber(Ability ability, CardInfo info, PlayableCard c
333338
}
334339

335340
count ??= baseAbilities.Count(ab => ab == ability);
336-
//Debug.Log($"[{AbilitiesUtil.GetInfo(ability).rulebookName}] {count}");
341+
Debug.Log($"[{AbilitiesUtil.GetInfo(ability).rulebookName}] {count} {baseAbilities.Count}");
337342

338-
if (count > 1) // We need to add an override
339-
__instance.SetIcon(PatchTexture(ability, (int)count));
343+
if (count > 1) // we have a stack and need to add an override
344+
{
345+
if (PatchPlugin.doubleStackSplit.Value && count == 2 && count == baseAbilities.Count)
346+
__instance.SetIcon(__instance.LoadIcon(info, ai, card != null && card.OpponentCard));//RenderSameSigilTwice(__instance, ai, info, card);
347+
else
348+
__instance.SetIcon(PatchTexture(ability, (int)count));
349+
}
340350
}
341351

342352
[HarmonyPatch(typeof(PixelCardAbilityIcons), "DisplayAbilities", new Type[] { typeof(List<Ability>), typeof(PlayableCard) })]
@@ -348,30 +358,62 @@ private static bool PatchPixelCardStacks(PixelCardAbilityIcons __instance, List<
348358

349359
public static bool RenderPixelAbilityStacks(PixelCardAbilityIcons __instance, List<Ability> abilities, PlayableCard card)
350360
{
351-
List<Tuple<Ability, int>> grps = abilities.Distinct().Select(a => new Tuple<Ability, int>(a, abilities.Where(ab => ab == a).Count())).ToList();
352361
List<GameObject> abilityIconGroups = __instance.abilityIconGroups;
353362
if (abilityIconGroups.Count == 0)
354363
return false;
355364

356365
foreach (GameObject gameObject in abilityIconGroups)
357366
gameObject.gameObject.SetActive(false);
358367

359-
if (grps.Count > 0 && grps.Count - 1 < abilityIconGroups.Count)
368+
List<Ability> allDisplayableAbilities = new(abilities);
369+
if (card != null)
360370
{
371+
allDisplayableAbilities.AddRange(AbilitiesUtil.GetAbilitiesFromMods(card.TemporaryMods));
372+
}
373+
374+
List<Tuple<Ability, int>> grps = allDisplayableAbilities.Distinct().Select(a => new Tuple<Ability, int>(a, abilities.Where(ab => ab == a).Count())).ToList();
375+
376+
if (grps.Count > 0 && grps.Count - 1 < abilityIconGroups.Count) // if there are displayable sigils and there are enough icon groups
377+
{
378+
// if there is only 1 ability and there are two stacks of it, render it twice
379+
if (PatchPlugin.doubleStackSplit.Value && grps.Count == 1 && grps[0].Item2 == 2)
380+
{
381+
PatchPlugin.Logger.LogDebug($"Displaying {grps[0].Item1} twice");
382+
grps[0] = new Tuple<Ability, int>(grps[0].Item1, 1);
383+
grps.Add(grps[0]);
384+
}
385+
361386
GameObject iconGroup = abilityIconGroups[grps.Count - 1];
362387
iconGroup.gameObject.SetActive(true);
363388

364-
List<SpriteRenderer> componentsInChildren = new();
389+
List<SpriteRenderer> abilityRenderers = new();
365390
foreach (Transform child in iconGroup.transform)
366-
componentsInChildren.Add(child.gameObject.GetComponent<SpriteRenderer>());
391+
abilityRenderers.Add(child.gameObject.GetComponent<SpriteRenderer>());
367392

368-
componentsInChildren.RemoveAll(sr => sr == null);
393+
abilityRenderers.RemoveAll(sr => sr == null);
369394

370-
for (int i = 0; i < componentsInChildren.Count; i++)
395+
CardInfo cardInfo = card?.Info ?? __instance.GetComponentInParent<DiskCardGame.Card>()?.Info;
396+
for (int i = 0; i < abilityRenderers.Count; i++)
371397
{
372-
SpriteRenderer abilityRenderer = componentsInChildren[i];
398+
SpriteRenderer abilityRenderer = abilityRenderers[i];
373399
AbilityInfo abilityInfo = AbilitiesUtil.GetInfo(grps[i].Item1);
374-
CardInfo cardInfo = card?.Info ?? __instance.GetComponentInParent<DiskCardGame.Card>()?.Info;
400+
int stackCount = grps[i].Item2;
401+
if (card != null)
402+
{
403+
if (abilityInfo.GetHideSingleStacks())
404+
{
405+
for (int j = 0; j < card.Status.hiddenAbilities.Count(x => x == grps[i].Item1); j++)
406+
{
407+
stackCount--;
408+
}
409+
}
410+
else if (card.Status.hiddenAbilities.Contains(grps[i].Item1))
411+
stackCount -= allDisplayableAbilities.Count(x => x == grps[i].Item1);
412+
413+
if (abilityInfo.IsShieldAbility())
414+
stackCount = card.GetShieldBehaviour(grps[i].Item1)?.NumShields ?? 0;
415+
}
416+
375417
abilityRenderer.sprite = abilityInfo.activated ? new() : OverridePixelSprite(abilityInfo, cardInfo, card);
376418
if (abilityInfo.flipYIfOpponent && card != null && card.OpponentCard)
377419
{
@@ -383,7 +425,8 @@ public static bool RenderPixelAbilityStacks(PixelCardAbilityIcons __instance, Li
383425
else
384426
abilityRenderer.flipY = false;
385427

386-
AddStackCount(abilityRenderer, grps[i]);
428+
PatchPlugin.Logger.LogDebug($"Pixel Stacks: [{grps[i].Item1}] Count: {stackCount}");
429+
AddStackCount(abilityRenderer, grps[i].Item1, stackCount);
387430
}
388431
}
389432
__instance.conduitIcon.SetActive(abilities.Exists((Ability x) => AbilitiesUtil.GetInfo(x).conduit));
@@ -402,14 +445,14 @@ public static bool RenderPixelAbilityStacks(PixelCardAbilityIcons __instance, Li
402445

403446
return false;
404447
}
405-
private static void AddStackCount(SpriteRenderer abilityRenderer, Tuple<Ability, int> grpsI)
448+
private static void AddStackCount(SpriteRenderer abilityRenderer, Ability ability, int count)
406449
{
407450
// And now my custom code to add the ability counter if we need to
408451
Transform countTransform = abilityRenderer.transform.Find("Count");
409452

410453
if (countTransform == null)
411454
{
412-
if (grpsI.Item2 <= 1)
455+
if (count <= 1)
413456
return;
414457

415458
GameObject counter = new();
@@ -428,17 +471,18 @@ private static void AddStackCount(SpriteRenderer abilityRenderer, Tuple<Ability,
428471
countTransform = counter.transform;
429472
}
430473

431-
if (grpsI.Item2 <= 1)
474+
if (count <= 1)
432475
countTransform.gameObject.SetActive(false);
433476
else
434477
{
435478
countTransform.gameObject.SetActive(true);
436-
Debug.Log($"countTransform {grpsI.Item2 - 1}");
437-
countTransform.gameObject.GetComponent<SpriteRenderer>().sprite = GBC_NUMBER_SPRITES[grpsI.Item2 - 1];
479+
Debug.Log($"countTransform [{count - 1}]");
480+
countTransform.gameObject.GetComponent<SpriteRenderer>().sprite = GBC_NUMBER_SPRITES[count - 1];
438481
}
439482
}
440483
private static Sprite OverridePixelSprite(AbilityInfo abilityInfo, CardInfo cardInfo, PlayableCard card)
441484
{
485+
// countdown numbers for evolve and transformer
442486
if (cardInfo != null && (abilityInfo.ability == Ability.Evolve || abilityInfo.ability == Ability.Transformer))
443487
{
444488
int turnsInPlay = card?.GetComponentInChildren<Evolve>()?.numTurnsInPlay ?? 0;
@@ -457,7 +501,7 @@ private static Sprite OverridePixelSprite(AbilityInfo abilityInfo, CardInfo card
457501
return TextureHelper.ConvertTexture(texture, TextureHelper.SpriteType.PixelAbilityIcon);
458502
}
459503

460-
if (card && card.RenderInfo.overriddenAbilityIcons.ContainsKey(abilityInfo.ability))
504+
if (card != null && card.RenderInfo.overriddenAbilityIcons.ContainsKey(abilityInfo.ability))
461505
{
462506
card.RenderInfo.overriddenAbilityIcons.TryGetValue(abilityInfo.ability, out Texture texture);
463507

InscryptionCommunityPatch/InscryptionCommunityPatchPlugin.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ public class PatchPlugin : BaseUnityPlugin
3636

3737
internal static ConfigEntry<bool> rightAct2Cost;
3838
internal static ConfigEntry<bool> act2CostRender;
39+
internal static ConfigEntry<bool> doubleStackSplit;
3940

4041
internal static ConfigEntry<bool> act2StackIconType;
4142

@@ -54,6 +55,7 @@ public class PatchPlugin : BaseUnityPlugin
5455

5556
internal static ConfigEntry<bool> act2TutorCenterRows;
5657

58+
5759
new internal static ManualLogSource Logger;
5860

5961
private readonly Harmony HarmonyInstance = new(ModGUID);
@@ -93,6 +95,8 @@ private void Awake()
9395
rightAct2Cost = Config.Bind("Card Costs", "GBC Cost On Right", true, "GBC Cards display their costs on the top-right corner. If false, display on the top-left corner");
9496
configMergeOnBottom = Config.Bind("Sigil Display", "Merge_On_Botom", false, "Makes it so if enabled, merged sigils will display on the bottom of the card instead of on the artwork. In extreme cases, this can cause some visual bugs.");
9597
configRemovePatches = Config.Bind("Sigil Display", "Remove_Patches", false, "Makes it so if enabled, merged sigils will not have a patch behind them anymore and will instead be glowing yellow (only works with Merge_On_Bottom).");
98+
doubleStackSplit = Config.Bind("Sigil Display", "Vanilla Stacking", false, "If enabled, cards with only two visible sigils will display each separately even if they can stack.");
99+
96100
configSmallPricetags = Config.Bind("Act 1", "Smaller Pricetags", false, "If enabled, the price tags placed on cards while buying from the Trapper will be scaled down.");
97101
configMovePricetags = Config.Bind("Act 1", "Move Pricetags", false, "If enabled, the price tags placed on cards while buying from the Trapper will be moved to the right.");
98102
act2StackIconType = Config.Bind("Sigil Display", "Act 2 Sigil icon type", true, "If true, stacking icons are a cream outline with a black center. If false, stacking icons are a black outline with a cream center. Act 2");

0 commit comments

Comments
 (0)