Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@
* Update the API to use Latest BepInEx.
* Bug Fix overlapping challenge icons.
* Removed some Debug Logging.
* Disk cost rendering resolves nodes on the active model and tolerates missing optional nodes.
* 3D ability icon groups can expand from valid templates without duplicating groups. Disk stat icons use the active card or displayer binding.
* Added `CardCostRender.GetDisplayCosts` for custom renderers that need the same current cost values as Paper and Disk displays.
* Slot assignment triggers preserve the previous and requested slots when callbacks move a card again.

# 2.24.1
* Added Extensions for setting the IconTexture of a Starter Deck.
Expand Down
36 changes: 21 additions & 15 deletions InscryptionAPI/Triggers/CustomTriggerPatches.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,25 +95,31 @@ private static IEnumerator TriggerOnOtherCardResolveInHand(IEnumerator result, P
}

[HarmonyPostfix, HarmonyPatch(typeof(BoardManager), nameof(BoardManager.AssignCardToSlot))]
private static IEnumerator TriggerOnOtherCardAssignedToSlotInHand(IEnumerator result, PlayableCard card, bool resolveTriggers)
private static IEnumerator TriggerOnOtherCardAssignedToSlotInHand(IEnumerator result, PlayableCard card, CardSlot slot, bool resolveTriggers)
{
CardSlot slot2 = card.Slot;
yield return result;
if (resolveTriggers && slot2 != card.Slot)
{
yield return CustomTriggerFinder.TriggerAll<IOnCardAssignedToSlotContext>(false, x => x.RespondsToCardAssignedToSlotContext(card, slot2, card.Slot), x =>
x.OnCardAssignedToSlotContext(card, slot2, card.Slot));
}
if (resolveTriggers && slot2 != card.Slot)
{
yield return CustomTriggerFinder.TriggerInHand<IOnOtherCardAssignedToSlotInHand>(x => x.RespondsToOtherCardAssignedToSlotInHand(card), x => x.OnOtherCardAssignedToSlotInHand(card));
}
if (resolveTriggers && slot2 != card.Slot && slot2 != null)
{
yield return CustomTriggerFinder.TriggerAll<IOnCardAssignedToSlotNoResolve>(false, x => x.RespondsToCardAssignedToSlotNoResolve(card), x => x.OnCardAssignedToSlotNoResolve(card));
}
yield break;
// Vanilla triggers can move or remove the card before this coroutine resumes.
if (!resolveTriggers || slot2 == slot || !IsCurrentAssignment(card, slot))
yield break;

// A receiver may move the card before the next receiver is evaluated.
yield return CustomTriggerFinder.TriggerAll<IOnCardAssignedToSlotContext>(false,
x => IsCurrentAssignment(card, slot) && x.RespondsToCardAssignedToSlotContext(card, slot2, slot) && IsCurrentAssignment(card, slot),
x => x.OnCardAssignedToSlotContext(card, slot2, slot));
if (!IsCurrentAssignment(card, slot))
yield break;

yield return CustomTriggerFinder.TriggerInHand<IOnOtherCardAssignedToSlotInHand>(
x => IsCurrentAssignment(card, slot) && x.RespondsToOtherCardAssignedToSlotInHand(card) && IsCurrentAssignment(card, slot),
x => x.OnOtherCardAssignedToSlotInHand(card));
if (slot2 != null && IsCurrentAssignment(card, slot))
yield return CustomTriggerFinder.TriggerAll<IOnCardAssignedToSlotNoResolve>(false,
x => IsCurrentAssignment(card, slot) && x.RespondsToCardAssignedToSlotNoResolve(card) && IsCurrentAssignment(card, slot),
x => x.OnCardAssignedToSlotNoResolve(card));
}

private static bool IsCurrentAssignment(PlayableCard card, CardSlot slot) => card != null && slot != null && card.Slot == slot && slot.Card == card;
#endregion

#region OnDie
Expand Down
6 changes: 4 additions & 2 deletions InscryptionAPI/Triggers/Interfaces.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ public interface IOnOtherCardAddedToHand
}

/// <summary>
/// Trigger that is triggered after any card is assigned to a slot, but only if it was assigned to a slot before.
/// Runs after a card moves from one slot to another with assignment triggers enabled.
/// The card must still occupy the destination after native assignment triggers finish.
/// </summary>
public interface IOnCardAssignedToSlotNoResolve
{
Expand All @@ -59,7 +60,8 @@ public interface IOnCardAssignedToSlotNoResolve
}

/// <summary>
/// Trigger that is triggered after any card is assigned to a slot. The difference between this and normal OnOtherCardAssignedToSlot is that this trigger also provides information about the new and old slot.
/// Runs after native assignment triggers if the card still occupies the requested destination.
/// Provides the slots for that assignment, including a null previous slot for initial placement.
/// </summary>
public interface IOnCardAssignedToSlotContext
{
Expand Down
62 changes: 40 additions & 22 deletions InscryptionCommunityPatch/Card/AdditionalIcons.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ internal class RenderAdditionalSigils

private static GameObject NewIconGroup(CardAbilityIcons controller, Transform parent, int newSlotNum)
{
GameObject prevIconGroup = parent.Find($"DefaultIcons_{newSlotNum - 1}Abilities").gameObject;
GameObject prevIconGroup = controller.defaultIconGroups[newSlotNum - 2];

GameObject newIconGroup = UnityObject.Instantiate(prevIconGroup, parent);
newIconGroup.name = $"DefaultIcons_{newSlotNum}Abilities";
Expand Down Expand Up @@ -48,24 +48,42 @@ private static void AddIconSlotsToCard(Transform abilityIconParent)
return;

CardAbilityIcons controller = abilityIconParent.gameObject.GetComponent<CardAbilityIcons>();
if (controller == null)
if (controller == null || controller.defaultIconGroups == null)
return;

// create the ability icon groups if they don't exist
if (abilityIconParent.Find("DefaultIcons_4Abilities") == null)
AddQuadrupleIconSlotToCard(controller, abilityIconParent);

if (abilityIconParent.Find("DefaultIcons_5Abilities") == null)
AddQuintupleIconSlotToCard(controller, abilityIconParent);

if (abilityIconParent.Find("DefaultIcons_6Abilities") == null)
AddSextupleIconSlotToCard(controller, abilityIconParent);

if (abilityIconParent.Find("DefaultIcons_7Abilities") == null)
AddSeptupleIconSlotToCard(controller, abilityIconParent);

if (abilityIconParent.Find("DefaultIcons_8Abilities") == null)
AddOctupleIconSlotToCard(controller, abilityIconParent);
List<GameObject> groups = controller.defaultIconGroups;
// Vanilla chooses an icon group by position in this list. Never append across a gap.
for (int count = 4; count <= 8; count++)
{
if (groups.Count >= count)
continue;
if (groups.Count != count - 1)
break;

Transform existing = abilityIconParent.Find($"DefaultIcons_{count}Abilities");
if (existing != null)
{
if (groups.Contains(existing.gameObject) || existing.gameObject.GetComponentsInChildren<AbilityIconInteractable>(true).Length != count)
break;

groups.Add(existing.gameObject);
continue;
}

GameObject prevIconGroup = groups[count - 2];
if (prevIconGroup == null || prevIconGroup.transform.parent != abilityIconParent || prevIconGroup.transform.childCount != count - 1
|| prevIconGroup.transform.Cast<Transform>().Any(icon => icon.gameObject.GetComponentsInChildren<AbilityIconInteractable>(true).Length != 1))
break;

switch (count)
{
case 4: AddQuadrupleIconSlotToCard(controller, abilityIconParent); break;
case 5: AddQuintupleIconSlotToCard(controller, abilityIconParent); break;
case 6: AddSextupleIconSlotToCard(controller, abilityIconParent); break;
case 7: AddSeptupleIconSlotToCard(controller, abilityIconParent); break;
case 8: AddOctupleIconSlotToCard(controller, abilityIconParent); break;
}
}
}

private static void AddQuadrupleIconSlotToCard(CardAbilityIcons controller, Transform abilityIconParent)
Expand All @@ -79,7 +97,7 @@ private static void AddQuadrupleIconSlotToCard(CardAbilityIcons controller, Tran
icons[2].localPosition = new Vector3(-0.12f, -0.077f, 0f);
icons[3].localPosition = new Vector3(0.12f, -0.077f, 0f);
}

private static void AddQuintupleIconSlotToCard(CardAbilityIcons controller, Transform abilityIconParent)
{
GameObject iconGroup5 = NewIconGroup(controller, abilityIconParent, 5);
Expand All @@ -103,7 +121,7 @@ private static void AddQuintupleIconSlotToCard(CardAbilityIcons controller, Tran
icons[4].localPosition = new Vector3(0f, -0.125f, 0f);
}
}

private static void AddSextupleIconSlotToCard(CardAbilityIcons controller, Transform abilityIconParent)
{
GameObject iconGroup6 = NewIconGroup(controller, abilityIconParent, 6);
Expand All @@ -122,7 +140,7 @@ private static void AddSextupleIconSlotToCard(CardAbilityIcons controller, Trans
icons[5].localPosition = new Vector3(0.14f, -0.125f, 0f);
}
}

private static void AddSeptupleIconSlotToCard(CardAbilityIcons controller, Transform abilityIconParent)
{
GameObject iconGroup7 = NewIconGroup(controller, abilityIconParent, 7);
Expand All @@ -146,7 +164,7 @@ private static void AddSeptupleIconSlotToCard(CardAbilityIcons controller, Trans
icons[6].localPosition = new Vector3(0.28f, -0.125f, 0f);
}
}

private static void AddOctupleIconSlotToCard(CardAbilityIcons controller, Transform abilityIconParent)
{
GameObject iconGroup8 = NewIconGroup(controller, abilityIconParent, 8);
Expand Down Expand Up @@ -333,7 +351,7 @@ private static void AddOctuplePixelIcon(PixelCardAbilityIcons controller, Transf
[HarmonyPrefix, HarmonyPatch(typeof(CardAbilityIcons), nameof(CardAbilityIcons.UpdateAbilityIcons))]
private static void AddExtraAbilityIcons(CardAbilityIcons __instance)
{
if (SaveManager.SaveFile.IsPart1 || SaveManager.SaveFile.IsPart3)
if (SaveManager.SaveFile is { } save && (save.IsPart1 || save.IsPart3))
AddIconSlotsToCard(__instance.transform);
}
}
35 changes: 35 additions & 0 deletions InscryptionCommunityPatch/Card/CardCostDisplayInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using DiskCardGame;
using InscryptionAPI.CardCosts;

namespace InscryptionCommunityPatch.Card;

/// <summary>
/// A snapshot of the costs a card renderer can display, independent of its model or display surface.
/// </summary>
public sealed class CardCostDisplayInfo
{
/// <summary>The number of sacrifices required.</summary>
public int BloodCost { get; }

/// <summary>The number of bones required.</summary>
public int BonesCost { get; }

/// <summary>The amount of energy required.</summary>
public int EnergyCost { get; }

/// <summary>The required gems, including repeated gems of the same type.</summary>
public IReadOnlyList<GemType> GemsCost { get; }

/// <summary>The registered custom cost definitions and their required amounts.</summary>
public IReadOnlyList<(CardCostManager.FullCardCost Definition, int Amount)> CustomCosts { get; }

internal CardCostDisplayInfo(int blood, int bones, int energy, List<GemType> gems,
IReadOnlyList<(CardCostManager.FullCardCost Definition, int Amount)> customCosts)
{
BloodCost = blood;
BonesCost = bones;
EnergyCost = energy;
GemsCost = Array.AsReadOnly(gems.ToArray());
CustomCosts = customCosts;
}
}
29 changes: 28 additions & 1 deletion InscryptionCommunityPatch/Card/CardCostRender.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using GBC;
using HarmonyLib;
using InscryptionAPI.Card;
//using InscryptionAPI.CardCosts;
using InscryptionAPI.CardCosts;
using InscryptionAPI.Helpers;
using UnityEngine;

Expand Down Expand Up @@ -36,6 +36,33 @@ public static Texture2D GetTextureByName(string key)
return texture;
}

/// <summary>
/// Resolves the costs for a custom card displayer or stats layer without selecting how they are drawn.
/// </summary>
/// <param name="cardInfo">The preview definition, for example <see cref="CardRenderInfo.baseInfo"/>.</param>
/// <param name="playableCard">The live card, if available, to use its current costs rather than the preview costs.</param>
public static CardCostDisplayInfo GetDisplayCosts(CardInfo cardInfo, PlayableCard playableCard = null)
{
if (cardInfo == null)
throw new ArgumentNullException(nameof(cardInfo));

int bloodCost = playableCard?.BloodCost() ?? cardInfo.BloodCost;
int bonesCost = playableCard?.BonesCost() ?? cardInfo.BonesCost;
int energyCost = playableCard?.EnergyCost ?? cardInfo.EnergyCost;
List<GemType> gemsCost = playableCard?.GemsCost() ?? cardInfo.GemsCost;
return new CardCostDisplayInfo(bloodCost, bonesCost, energyCost, gemsCost, ReadCustomCosts(cardInfo, playableCard));
}

private static IReadOnlyList<(CardCostManager.FullCardCost Definition, int Amount)> ReadCustomCosts(CardInfo cardInfo, PlayableCard playableCard)
{
IEnumerable<CardCostManager.FullCardCost> definitions = playableCard != null
? playableCard.GetCustomCardCosts().Select(behavior => CardCostManager.AllCustomCosts.Find(cost => cost.CostName == behavior.CostName))
: cardInfo.GetCustomCosts();

return Array.AsReadOnly(definitions.Where(cost => cost != null)
.Select(cost => (cost, playableCard?.GetCustomCost(cost) ?? cardInfo.GetCustomCost(cost))).ToArray());
}

/// <summary>
/// Creates a sprite that combines all of a card's play costs.
/// </summary>
Expand Down
Loading
Loading