Skip to content

Commit e1ffb68

Browse files
committed
Refactor per Scott's comments.
Added Predicate in CardUtils for checking non-living traits for a card.
1 parent 5bc3a4d commit e1ffb68

2 files changed

Lines changed: 31 additions & 48 deletions

File tree

Models/NewCard.cs

Lines changed: 26 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,33 @@ public static class NewCard
1313
public static Dictionary<int, IceCubeIdentifier> iceCubeIds = new();
1414
public static Dictionary<int, TailIdentifier> tailIds = new();
1515

16-
public static CardInfo CreateCard(string name, string displayedName, int baseAttack, int baseHealth,
16+
public static void Add(CardInfo card, List<AbilityIdentifier> abilityIdsParam = null,
17+
EvolveIdentifier evolveId = null, IceCubeIdentifier iceCubeId = null, TailIdentifier tailId = null
18+
)
19+
{
20+
NewCard.cards.Add(card);
21+
handleIdentifiers(abilityIdsParam, evolveId, iceCubeId, tailId);
22+
Plugin.Log.LogInfo($"Loaded custom card {card.name}!");
23+
}
24+
25+
26+
// TODO Implement a handler for custom appearanceBehaviour - in particular custom card backs
27+
// TODO Change parameter order, and function setter call order to make more sense
28+
// TODO Rename parameters to be more user friendly
29+
public static void Add(string name, string displayedName, int baseAttack, int baseHealth,
1730
List<CardMetaCategory> metaCategories, CardComplexity cardComplexity, CardTemple temple,
1831
string description = null, bool hideAttackAndHealth = false,
1932
int bloodCost = 0, int bonesCost = 0, int energyCost = 0,
2033
List<GemType> gemsCost = null, SpecialStatIcon specialStatIcon = SpecialStatIcon.None,
2134
List<Tribe> tribes = null, List<Trait> traits = null, List<SpecialTriggeredAbility> specialAbilities = null,
22-
List<Ability> abilities = null, EvolveParams evolveParams = null,
35+
List<Ability> abilities = null, List<AbilityIdentifier> abilityIdsParam = null,
36+
EvolveParams evolveParams = null,
2337
string defaultEvolutionName = null, TailParams tailParams = null, IceCubeParams iceCubeParams = null,
2438
bool flipPortraitForStrafe = false, bool onePerDeck = false,
2539
List<CardAppearanceBehaviour.Appearance> appearanceBehaviour = null, Texture2D defaultTex = null,
2640
Texture2D altTex = null, Texture titleGraphic = null, Texture2D pixelTex = null,
27-
GameObject animatedPortrait = null, List<Texture> decals = null)
41+
GameObject animatedPortrait = null, List<Texture> decals = null, EvolveIdentifier evolveId = null,
42+
IceCubeIdentifier iceCubeId = null, TailIdentifier tailId = null)
2843
{
2944
CardInfo card = ScriptableObject.CreateInstance<CardInfo>();
3045

@@ -119,50 +134,13 @@ public static CardInfo CreateCard(string name, string displayedName, int baseAtt
119134
card.titleGraphic = titleGraphic;
120135
}
121136

122-
return card;
123-
}
124-
125-
public static void AddToPool(CardInfo card, List<AbilityIdentifier> abilityIdsParam = null,
126-
EvolveIdentifier evolveId = null,
127-
IceCubeIdentifier iceCubeId = null, TailIdentifier tailId = null)
128-
{
129-
NewCard.cards.Add(card);
130-
handleIdentifiers(card, abilityIdsParam, evolveId, iceCubeId, tailId);
131-
132-
Plugin.Log.LogInfo($"Loaded custom card {card.name}!");
133-
}
134-
135-
// TODO Implement a handler for custom appearanceBehaviour - in particular custom card backs
136-
// TODO Change parameter order, and function setter call order to make more sense
137-
// TODO Rename parameters to be more user friendly
138-
public static void AddToPool(string name, string displayedName, int baseAttack, int baseHealth,
139-
List<CardMetaCategory> metaCategories, CardComplexity cardComplexity, CardTemple temple,
140-
string description = null, bool hideAttackAndHealth = false,
141-
int bloodCost = 0, int bonesCost = 0, int energyCost = 0,
142-
List<GemType> gemsCost = null, SpecialStatIcon specialStatIcon = SpecialStatIcon.None,
143-
List<Tribe> tribes = null, List<Trait> traits = null, List<SpecialTriggeredAbility> specialAbilities = null,
144-
List<Ability> abilities = null, List<AbilityIdentifier> abilityIdsParam = null,
145-
EvolveParams evolveParams = null,
146-
string defaultEvolutionName = null, TailParams tailParams = null, IceCubeParams iceCubeParams = null,
147-
bool flipPortraitForStrafe = false, bool onePerDeck = false,
148-
List<CardAppearanceBehaviour.Appearance> appearanceBehaviour = null, Texture2D defaultTex = null,
149-
Texture2D altTex = null, Texture titleGraphic = null, Texture2D pixelTex = null,
150-
GameObject animatedPortrait = null, List<Texture> decals = null, EvolveIdentifier evolveId = null,
151-
IceCubeIdentifier iceCubeId = null, TailIdentifier tailId = null)
152-
{
153-
var createdCard = CreateCard(
154-
name, displayedName, baseAttack, baseHealth, metaCategories, cardComplexity, temple, description,
155-
hideAttackAndHealth, bloodCost, bonesCost, energyCost, gemsCost, specialStatIcon, tribes, traits,
156-
specialAbilities, abilities, evolveParams, defaultEvolutionName, tailParams, iceCubeParams,
157-
flipPortraitForStrafe, onePerDeck, appearanceBehaviour,
158-
defaultTex, altTex, titleGraphic, pixelTex, animatedPortrait, decals
159-
);
160-
161-
NewCard.AddToPool(createdCard, abilityIdsParam, evolveId, iceCubeId, tailId);
137+
NewCard.Add(card, abilityIdsParam, evolveId, iceCubeId, tailId);
162138
}
163139

164-
private static void handleIdentifiers(CardInfo card, List<AbilityIdentifier> abilityIdsParam = null,
165-
EvolveIdentifier evolveId = null, IceCubeIdentifier iceCubeId = null, TailIdentifier tailId = null)
140+
private static void handleIdentifiers(
141+
List<AbilityIdentifier> abilityIdsParam = null, EvolveIdentifier evolveId = null,
142+
IceCubeIdentifier iceCubeId = null, TailIdentifier tailId = null
143+
)
166144
{
167145
// Handle AbilityIdentifier
168146

@@ -218,9 +196,10 @@ private static void DetermineAndSetCardArt(
218196
pixelTex.name = newName;
219197
pixelTex.filterMode = FilterMode.Point;
220198

221-
card.pixelPortrait = Sprite.Create(pixelTex, CardUtils.DefaultCardPixelArtRect, CardUtils.DefaultVector2);
199+
card.pixelPortrait =
200+
Sprite.Create(pixelTex, CardUtils.DefaultCardPixelArtRect, CardUtils.DefaultVector2);
222201
card.pixelPortrait.name = newName;
223202
}
224203
}
225204
}
226-
}
205+
}

Utils/CardUtils.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public static void PrintCardModInfoList(List<CardModificationInfo> mods)
4646

4747
public static void PrintCardModInfo(CardModificationInfo mod)
4848
{
49-
Plugin.Log.LogInfo($"\nID [{mod.singletonId}]");
49+
Plugin.Log.LogInfo($"ID [{mod.singletonId}]");
5050
Plugin.Log.LogInfo($"Gemify? [{mod.gemify}]");
5151
Plugin.Log.LogInfo($"Attack Adjustment [{mod.attackAdjustment}]");
5252
Plugin.Log.LogInfo($"Health Adjustment [{mod.healthAdjustment}]");
@@ -117,8 +117,12 @@ public static void PrintCardInfo(CardInfo info)
117117
Plugin.Log.LogInfo($"===============\n");
118118
}
119119

120+
public static Predicate<CardInfo> IsNonLivingCard = card
121+
=> card.traits.Exists(t => t is Trait.Terrain or Trait.Pelt);
122+
120123
public static string cleanCardName(string name)
121124
{
125+
// for card names that for some reason equal to 'Card (Sparrow)' instead of just 'Sparrow'
122126
if (name.StartsWith("Card "))
123127
{
124128
string[] nameSplit = name.Split('('); // [Card (, name_of_card)]

0 commit comments

Comments
 (0)