Skip to content
Merged
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
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# 2.24.1
* Added Extensions for setting the IconTexture of a Starter Deck.
* Added 2 Alternate Constructors for making a StarterDeck with a Display Name different from its Internal Name.
* Added Getters and Setters for Starter Deck Unlock Level.

# 2.24.0
- Fixed Part2CardCostRender.UpdatePlayableCardCost not being invoked
- Fixed Part2CardCostRender.UpdateVanillaPlayableCardCost not being invoked
Expand Down
42 changes: 42 additions & 0 deletions InscryptionAPI/Ascension/StarterDeckExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
using DiskCardGame;
using InscryptionAPI.Helpers;
using UnityEngine;

namespace InscryptionAPI.Ascension;

public static partial class StarterDeckExtensions
{
private static Sprite GetPortrait(Texture2D portrait, TextureHelper.SpriteType spriteType, FilterMode? filterMode = null)
{
return portrait.ConvertTexture(spriteType, filterMode ?? FilterMode.Point);
}

/// <summary>
/// Sets the Unlock Level of a Starter Deck.
/// </summary>
/// <param name="info">The StarterDeckInfo of the Deck.</param>
/// <param name="unlockLevel">The Unlock Level to set the Starter Deck with.</param>
public static void SetUnlockLevel(this StarterDeckInfo info, int unlockLevel)
{
StarterDeckManager.FullStarterDeck fullStarterDeck = StarterDeckManager.AllDecks.FirstOrDefault(x => x.Info == info);
if (fullStarterDeck != null)
{
fullStarterDeck.UnlockLevel = unlockLevel;
}
}

/// <summary>
/// Gets the Unlock Level associated with a Starter deck.
/// </summary>
/// <param name="info">The StarterDeckInfo of the Deck.</param>
/// <returns>Returns the Unlock Level, if it fails it will return <see cref="int.MaxValue"/>.</returns>
public static int GetUnlockLevel(this StarterDeckInfo info)
{
StarterDeckManager.FullStarterDeck fullStarterDeck = StarterDeckManager.AllDecks.FirstOrDefault(x => x.Info == info);
if (fullStarterDeck != null)
{
return fullStarterDeck.UnlockLevel;
}
return int.MaxValue;
}
}
56 changes: 56 additions & 0 deletions InscryptionAPI/Ascension/StarterDeckExtensionsPortraits.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
using DiskCardGame;
using InscryptionAPI.Helpers;
using UnityEngine;

namespace InscryptionAPI.Ascension;

public static partial class StarterDeckExtensions
{
#region iconTexture
/// <summary>
/// Sets the icon texture for the starter deck.
/// </summary>
/// <param name="info">StarterDeckInfo to access.</param>
/// <param name="pathToArt">The path to the .png file containing the artwork (relative to the Plugins directory).</param>
/// <returns>The same StarterDeckInfo so a chain can continue.</returns>
public static StarterDeckInfo SetIconTexture(this StarterDeckInfo info, string pathToArt)
{
try
{
return info.SetIconTexture(TextureHelper.GetImageAsTexture(pathToArt));
}
catch (FileNotFoundException fnfe)
{
throw new ArgumentException($"Image file not found for card \"{info.name}\"!", fnfe);
}
}

/// <summary>
/// Sets the icon texture for the starter deck.
/// </summary>
/// <param name="info">StarterDeckInfo to access.</param>
/// <param name="portrait">The texture containing the emission.</param>
/// <param name="filterMode">The filter mode for the texture, or null if no change.</param>
/// <returns>The same StarterDeckInfo so a chain can continue.</returns>
public static StarterDeckInfo SetIconTexture(this StarterDeckInfo info, Texture2D portrait, FilterMode? filterMode = null)
{
return info.SetIconTexture(GetPortrait(portrait, TextureHelper.SpriteType.CardPortrait, filterMode));
}

/// <summary>
/// Sets the icon texture for the starter deck.
/// </summary>
/// <param name="info">StarterDeckInfo to access.</param>
/// <param name="sprite">The sprite containing the emission.</param>
/// <returns>The same StarterDeckInfo so a chain can continue.</returns>
public static StarterDeckInfo SetIconTexture(this StarterDeckInfo info, Sprite sprite)
{
if (info.iconSprite == null)
throw new InvalidOperationException($"Cannot set emissive portrait before setting normal portrait!");

info.iconSprite.RegisterEmissionForSprite(sprite);

return info;
}
#endregion
}
23 changes: 23 additions & 0 deletions InscryptionAPI/Ascension/StarterDeckManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -149,12 +149,35 @@ public static FullStarterDeck New(string pluginGuid, string title, Texture2D ico

return fsd;
}

public static FullStarterDeck New(string pluginGuid, string name, string title, Texture2D iconTexture, string[] cardNames, int unlockLevel = 0)
{
StarterDeckInfo info = ScriptableObject.CreateInstance<StarterDeckInfo>();
info.title = title;
info.iconSprite = TextureHelper.ConvertTexture(iconTexture, TextureHelper.SpriteType.StarterDeckIcon);
info.name = pluginGuid + "_" + name;

FullStarterDeck fsd = new();
fsd.Info = info;
fsd.UnlockLevel = unlockLevel;
fsd.CardNames = cardNames.ToList();

NewDecks.Add(fsd);

return fsd;
}

public static FullStarterDeck New(string pluginGuid, string title, string pathToIconTexture, string[] cardNames, int unlockLevel = 0)
{
Texture2D texture = TextureHelper.GetImageAsTexture(pathToIconTexture);
return New(pluginGuid, title, texture, cardNames, unlockLevel);
}

public static FullStarterDeck New(string pluginGuid, string name, string title, string pathToIconTexture, string[] cardNames, int unlockLevel = 0)
{
Texture2D texture = TextureHelper.GetImageAsTexture(pathToIconTexture);
return New(pluginGuid, name, title, texture, cardNames, unlockLevel);
}

[HarmonyPatch(typeof(AscensionUnlockSchedule), "StarterDeckIsUnlockedForLevel")]
[HarmonyPrefix]
Expand Down
2 changes: 1 addition & 1 deletion InscryptionAPI/InscryptionAPI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<DebugType>full</DebugType>
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
<EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild>
<Version>2.24.0</Version>
<Version>2.24.1</Version>
</PropertyGroup>

<PropertyGroup>
Expand Down
2 changes: 1 addition & 1 deletion InscryptionAPI/InscryptionAPIPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public class InscryptionAPIPlugin : BaseUnityPlugin
{
public const string ModGUID = "cyantist.inscryption.api";
public const string ModName = "InscryptionAPI";
public const string ModVer = "2.24.0";
public const string ModVer = "2.24.1";

public static string Directory = "";

Expand Down
Loading