Skip to content

Commit d007dbd

Browse files
authored
Merge pull request #337 from Chaosyr/StarterDeckExtensions
Implement Starter Deck Extensions
2 parents a795eb8 + 6924bbb commit d007dbd

6 files changed

Lines changed: 128 additions & 2 deletions

File tree

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
# 2.24.1
2+
* Added Extensions for setting the IconTexture of a Starter Deck.
3+
* Added 2 Alternate Constructors for making a StarterDeck with a Display Name different from its Internal Name.
4+
* Added Getters and Setters for Starter Deck Unlock Level.
5+
16
# 2.24.0
27
- Fixed Part2CardCostRender.UpdatePlayableCardCost not being invoked
38
- Fixed Part2CardCostRender.UpdateVanillaPlayableCardCost not being invoked
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
using DiskCardGame;
2+
using InscryptionAPI.Helpers;
3+
using UnityEngine;
4+
5+
namespace InscryptionAPI.Ascension;
6+
7+
public static partial class StarterDeckExtensions
8+
{
9+
private static Sprite GetPortrait(Texture2D portrait, TextureHelper.SpriteType spriteType, FilterMode? filterMode = null)
10+
{
11+
return portrait.ConvertTexture(spriteType, filterMode ?? FilterMode.Point);
12+
}
13+
14+
/// <summary>
15+
/// Sets the Unlock Level of a Starter Deck.
16+
/// </summary>
17+
/// <param name="info">The StarterDeckInfo of the Deck.</param>
18+
/// <param name="unlockLevel">The Unlock Level to set the Starter Deck with.</param>
19+
public static void SetUnlockLevel(this StarterDeckInfo info, int unlockLevel)
20+
{
21+
StarterDeckManager.FullStarterDeck fullStarterDeck = StarterDeckManager.AllDecks.FirstOrDefault(x => x.Info == info);
22+
if (fullStarterDeck != null)
23+
{
24+
fullStarterDeck.UnlockLevel = unlockLevel;
25+
}
26+
}
27+
28+
/// <summary>
29+
/// Gets the Unlock Level associated with a Starter deck.
30+
/// </summary>
31+
/// <param name="info">The StarterDeckInfo of the Deck.</param>
32+
/// <returns>Returns the Unlock Level, if it fails it will return <see cref="int.MaxValue"/>.</returns>
33+
public static int GetUnlockLevel(this StarterDeckInfo info)
34+
{
35+
StarterDeckManager.FullStarterDeck fullStarterDeck = StarterDeckManager.AllDecks.FirstOrDefault(x => x.Info == info);
36+
if (fullStarterDeck != null)
37+
{
38+
return fullStarterDeck.UnlockLevel;
39+
}
40+
return int.MaxValue;
41+
}
42+
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
using DiskCardGame;
2+
using InscryptionAPI.Helpers;
3+
using UnityEngine;
4+
5+
namespace InscryptionAPI.Ascension;
6+
7+
public static partial class StarterDeckExtensions
8+
{
9+
#region iconTexture
10+
/// <summary>
11+
/// Sets the icon texture for the starter deck.
12+
/// </summary>
13+
/// <param name="info">StarterDeckInfo to access.</param>
14+
/// <param name="pathToArt">The path to the .png file containing the artwork (relative to the Plugins directory).</param>
15+
/// <returns>The same StarterDeckInfo so a chain can continue.</returns>
16+
public static StarterDeckInfo SetIconTexture(this StarterDeckInfo info, string pathToArt)
17+
{
18+
try
19+
{
20+
return info.SetIconTexture(TextureHelper.GetImageAsTexture(pathToArt));
21+
}
22+
catch (FileNotFoundException fnfe)
23+
{
24+
throw new ArgumentException($"Image file not found for card \"{info.name}\"!", fnfe);
25+
}
26+
}
27+
28+
/// <summary>
29+
/// Sets the icon texture for the starter deck.
30+
/// </summary>
31+
/// <param name="info">StarterDeckInfo to access.</param>
32+
/// <param name="portrait">The texture containing the emission.</param>
33+
/// <param name="filterMode">The filter mode for the texture, or null if no change.</param>
34+
/// <returns>The same StarterDeckInfo so a chain can continue.</returns>
35+
public static StarterDeckInfo SetIconTexture(this StarterDeckInfo info, Texture2D portrait, FilterMode? filterMode = null)
36+
{
37+
return info.SetIconTexture(GetPortrait(portrait, TextureHelper.SpriteType.CardPortrait, filterMode));
38+
}
39+
40+
/// <summary>
41+
/// Sets the icon texture for the starter deck.
42+
/// </summary>
43+
/// <param name="info">StarterDeckInfo to access.</param>
44+
/// <param name="sprite">The sprite containing the emission.</param>
45+
/// <returns>The same StarterDeckInfo so a chain can continue.</returns>
46+
public static StarterDeckInfo SetIconTexture(this StarterDeckInfo info, Sprite sprite)
47+
{
48+
if (info.iconSprite == null)
49+
throw new InvalidOperationException($"Cannot set emissive portrait before setting normal portrait!");
50+
51+
info.iconSprite.RegisterEmissionForSprite(sprite);
52+
53+
return info;
54+
}
55+
#endregion
56+
}

InscryptionAPI/Ascension/StarterDeckManager.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,12 +149,35 @@ public static FullStarterDeck New(string pluginGuid, string title, Texture2D ico
149149

150150
return fsd;
151151
}
152+
153+
public static FullStarterDeck New(string pluginGuid, string name, string title, Texture2D iconTexture, string[] cardNames, int unlockLevel = 0)
154+
{
155+
StarterDeckInfo info = ScriptableObject.CreateInstance<StarterDeckInfo>();
156+
info.title = title;
157+
info.iconSprite = TextureHelper.ConvertTexture(iconTexture, TextureHelper.SpriteType.StarterDeckIcon);
158+
info.name = pluginGuid + "_" + name;
159+
160+
FullStarterDeck fsd = new();
161+
fsd.Info = info;
162+
fsd.UnlockLevel = unlockLevel;
163+
fsd.CardNames = cardNames.ToList();
164+
165+
NewDecks.Add(fsd);
166+
167+
return fsd;
168+
}
152169

153170
public static FullStarterDeck New(string pluginGuid, string title, string pathToIconTexture, string[] cardNames, int unlockLevel = 0)
154171
{
155172
Texture2D texture = TextureHelper.GetImageAsTexture(pathToIconTexture);
156173
return New(pluginGuid, title, texture, cardNames, unlockLevel);
157174
}
175+
176+
public static FullStarterDeck New(string pluginGuid, string name, string title, string pathToIconTexture, string[] cardNames, int unlockLevel = 0)
177+
{
178+
Texture2D texture = TextureHelper.GetImageAsTexture(pathToIconTexture);
179+
return New(pluginGuid, name, title, texture, cardNames, unlockLevel);
180+
}
158181

159182
[HarmonyPatch(typeof(AscensionUnlockSchedule), "StarterDeckIsUnlockedForLevel")]
160183
[HarmonyPrefix]

InscryptionAPI/InscryptionAPI.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
<DebugType>full</DebugType>
1111
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
1212
<EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild>
13-
<Version>2.24.0</Version>
13+
<Version>2.24.1</Version>
1414
</PropertyGroup>
1515

1616
<PropertyGroup>

InscryptionAPI/InscryptionAPIPlugin.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public class InscryptionAPIPlugin : BaseUnityPlugin
3131
{
3232
public const string ModGUID = "cyantist.inscryption.api";
3333
public const string ModName = "InscryptionAPI";
34-
public const string ModVer = "2.24.0";
34+
public const string ModVer = "2.24.1";
3535

3636
public static string Directory = "";
3737

0 commit comments

Comments
 (0)