diff --git a/CHANGELOG.md b/CHANGELOG.md index d72b91d0..d4bddb22 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/InscryptionAPI/Ascension/StarterDeckExtensions.cs b/InscryptionAPI/Ascension/StarterDeckExtensions.cs new file mode 100644 index 00000000..92baaa61 --- /dev/null +++ b/InscryptionAPI/Ascension/StarterDeckExtensions.cs @@ -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); + } + + /// + /// Sets the Unlock Level of a Starter Deck. + /// + /// The StarterDeckInfo of the Deck. + /// The Unlock Level to set the Starter Deck with. + 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; + } + } + + /// + /// Gets the Unlock Level associated with a Starter deck. + /// + /// The StarterDeckInfo of the Deck. + /// Returns the Unlock Level, if it fails it will return . + 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; + } +} \ No newline at end of file diff --git a/InscryptionAPI/Ascension/StarterDeckExtensionsPortraits.cs b/InscryptionAPI/Ascension/StarterDeckExtensionsPortraits.cs new file mode 100644 index 00000000..14889232 --- /dev/null +++ b/InscryptionAPI/Ascension/StarterDeckExtensionsPortraits.cs @@ -0,0 +1,56 @@ +using DiskCardGame; +using InscryptionAPI.Helpers; +using UnityEngine; + +namespace InscryptionAPI.Ascension; + +public static partial class StarterDeckExtensions +{ + #region iconTexture + /// + /// Sets the icon texture for the starter deck. + /// + /// StarterDeckInfo to access. + /// The path to the .png file containing the artwork (relative to the Plugins directory). + /// The same StarterDeckInfo so a chain can continue. + 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); + } + } + + /// + /// Sets the icon texture for the starter deck. + /// + /// StarterDeckInfo to access. + /// The texture containing the emission. + /// The filter mode for the texture, or null if no change. + /// The same StarterDeckInfo so a chain can continue. + public static StarterDeckInfo SetIconTexture(this StarterDeckInfo info, Texture2D portrait, FilterMode? filterMode = null) + { + return info.SetIconTexture(GetPortrait(portrait, TextureHelper.SpriteType.CardPortrait, filterMode)); + } + + /// + /// Sets the icon texture for the starter deck. + /// + /// StarterDeckInfo to access. + /// The sprite containing the emission. + /// The same StarterDeckInfo so a chain can continue. + 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 +} diff --git a/InscryptionAPI/Ascension/StarterDeckManager.cs b/InscryptionAPI/Ascension/StarterDeckManager.cs index 4765ef10..2b5e3680 100644 --- a/InscryptionAPI/Ascension/StarterDeckManager.cs +++ b/InscryptionAPI/Ascension/StarterDeckManager.cs @@ -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(); + 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] diff --git a/InscryptionAPI/InscryptionAPI.csproj b/InscryptionAPI/InscryptionAPI.csproj index bfc82bfc..27de0776 100644 --- a/InscryptionAPI/InscryptionAPI.csproj +++ b/InscryptionAPI/InscryptionAPI.csproj @@ -10,7 +10,7 @@ full false true - 2.24.0 + 2.24.1 diff --git a/InscryptionAPI/InscryptionAPIPlugin.cs b/InscryptionAPI/InscryptionAPIPlugin.cs index ee92caf1..fc46d62d 100644 --- a/InscryptionAPI/InscryptionAPIPlugin.cs +++ b/InscryptionAPI/InscryptionAPIPlugin.cs @@ -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 = "";