Skip to content

Commit a915cf4

Browse files
committed
Moved print related methods to PrintUtils.
Refactored CardUtils method getArtworkFileAsBytes to now dynamically find the name of the art.
1 parent 83170d0 commit a915cf4

2 files changed

Lines changed: 117 additions & 118 deletions

File tree

Utils/CardUtils.cs

Lines changed: 8 additions & 118 deletions
Original file line numberDiff line numberDiff line change
@@ -13,116 +13,13 @@ public static class CardUtils
1313
public static readonly Rect DefaultCardArtRect = new Rect(0.0f, 0.0f, 114.0f, 94.0f);
1414
public static readonly Rect DefaultCardPixelArtRect = new Rect(0.0f, 0.0f, 41.0f, 28.0f);
1515

16-
// Print section
17-
public static void PrintStatIconInfo(StatIconInfo info)
18-
{
19-
Plugin.Log.LogInfo($"\nStatIconInfo");
20-
Plugin.Log.LogInfo($"GBC Description [{info.gbcDescription}]");
21-
Plugin.Log.LogInfo($"Rulebook Name [{info.rulebookName}]");
22-
Plugin.Log.LogInfo($"Rulebook Description [{info.rulebookDescription}]");
23-
Plugin.Log.LogInfo($"Applies to Attack [{info.appliesToAttack}] Health [{info.appliesToAttack}]");
24-
PrintList("MetaCategory", info.metaCategories);
25-
}
26-
27-
public static void PrintAllCardInfo()
28-
{
29-
foreach (var info in CardLoader.AllData)
30-
{
31-
PrintCardInfo(info);
32-
}
33-
}
34-
35-
public static void PrintCardModInfoList(List<CardModificationInfo> mods)
36-
{
37-
if (mods.Count != 0)
38-
{
39-
Plugin.Log.LogInfo("Card Mods Info");
40-
foreach (var mod in mods)
41-
{
42-
PrintCardModInfo(mod);
43-
}
44-
}
45-
}
46-
47-
public static void PrintCardModInfo(CardModificationInfo mod)
48-
{
49-
Plugin.Log.LogInfo($"ID [{mod.singletonId}]");
50-
Plugin.Log.LogInfo($"Gemify? [{mod.gemify}]");
51-
Plugin.Log.LogInfo($"Attack Adjustment [{mod.attackAdjustment}]");
52-
Plugin.Log.LogInfo($"Health Adjustment [{mod.healthAdjustment}]");
53-
Plugin.Log.LogInfo($"Blood Cost Adjustment [{mod.bloodCostAdjustment}]");
54-
Plugin.Log.LogInfo($"Bones Cost Adjustment [{mod.bonesCostAdjustment}]");
55-
Plugin.Log.LogInfo($"Energy Cost Adjustment [{mod.energyCostAdjustment}]");
56-
Plugin.Log.LogInfo($"Non-Copyable? [{mod.nonCopyable}]");
57-
Plugin.Log.LogInfo($"From Card Merge? [{mod.fromCardMerge}]");
58-
Plugin.Log.LogInfo($"From Duplicate Merge? [{mod.fromDuplicateMerge}]");
59-
Plugin.Log.LogInfo($"From Latch? [{mod.fromLatch}]");
60-
Plugin.Log.LogInfo($"From Overclock? [{mod.fromOverclock}]");
61-
Plugin.Log.LogInfo($"From Totem? [{mod.fromTotem}]");
62-
Plugin.Log.LogInfo($"Nullify Gems Cost? [{mod.nullifyGemsCost}]");
63-
Plugin.Log.LogInfo($"Side Deck Mod? [{mod.sideDeckMod}]");
64-
Plugin.Log.LogInfo($"Special Stat Icon [{mod.statIcon}]");
65-
Plugin.Log.LogInfo($"Remove On upkeep? [{mod.RemoveOnUpkeep}]");
66-
67-
PrintList("Abilities", mod.abilities);
68-
PrintList("Negate Abilities", mod.negateAbilities);
69-
PrintList("Special Abilities", mod.specialAbilities);
70-
PrintList("Add Gem Costs", mod.addGemCost);
71-
PrintList("DecalIds", mod.decalIds);
72-
}
73-
74-
public static void PrintList<T>(string title, List<T> items)
75-
{
76-
if (items.Count != 0)
77-
{
78-
Plugin.Log.LogInfo(title);
79-
items.ForEach(item => Plugin.Log.LogInfo($"-> {item}"));
80-
}
81-
}
82-
83-
public static void PrintCardInfo(CardInfo info)
84-
{
85-
Plugin.Log.LogInfo($"===============");
86-
Plugin.Log.LogInfo($"Name [{info.name}]");
87-
Plugin.Log.LogInfo($"Displayed Name [{info.displayedName}]");
88-
Plugin.Log.LogInfo($"Description [{info.description}]");
89-
Plugin.Log.LogInfo($"Attack [{info.baseAttack}] Health [{info.baseHealth}]");
90-
Plugin.Log.LogInfo($"Boon [{info.boon}]");
91-
Plugin.Log.LogInfo($"Bones Cost [{info.bonesCost}]");
92-
Plugin.Log.LogInfo($"Cost [{info.cost}]");
93-
Plugin.Log.LogInfo($"Temple [{info.temple}]");
94-
Plugin.Log.LogInfo($"CardComplexity [{info.cardComplexity}]");
95-
Plugin.Log.LogInfo($"EnergyCost [{info.energyCost}]");
96-
if (info.evolveParams is not null)
97-
Plugin.Log.LogInfo(
98-
$"EvolveParams = Turns to evolve [{info.evolveParams.turnsToEvolve}] Evolves into [{info.evolveParams.evolution.name}]");
99-
Plugin.Log.LogInfo($"Can sacrifice? [{info.Sacrificable}]");
100-
Plugin.Log.LogInfo($"Is Gemified? [{info.Gemified}]");
101-
if (info.iceCubeParams is not null)
102-
Plugin.Log.LogInfo($"IceCubeParams = [{info.iceCubeParams.creatureWithin.name}]");
103-
Plugin.Log.LogInfo($"SpecialStatIcon [{info.specialStatIcon}]");
104-
Plugin.Log.LogInfo($"One per deck? [{info.onePerDeck}]");
105-
// TODO: possible to get an NRE if the power level is not set?
106-
// Plugin.Log.LogInfo($"Power Level [{info.PowerLevel}]");
107-
PrintList("Abilities", info.Abilities);
108-
PrintList("Special Abilities", info.SpecialAbilities);
109-
PrintList("Appearance Behavior", info.appearanceBehaviour);
110-
PrintList("Gems Cost", info.GemsCost);
111-
PrintList("MetaCategory", info.metaCategories);
112-
PrintList("Traits", info.traits);
113-
PrintList("Tribes", info.tribes);
114-
115-
PrintCardModInfoList(info.mods);
116-
117-
Plugin.Log.LogInfo($"===============\n");
118-
}
119-
12016
public static Predicate<CardInfo> IsNonLivingCard = card
12117
=> card.traits.Exists(t => t is Trait.Terrain or Trait.Pelt);
12218

123-
public static string cleanCardName(string name)
19+
public static string CleanCardName(string name)
12420
{
125-
// for card names that for some reason equal to 'Card (Sparrow)' instead of just 'Sparrow'
21+
// When calling PlayableCard.name, it will look like 'Card (Sparrow)' instead of just 'Sparrow'
22+
// For some reason CardInfo.name is not available to call
12623
if (name.StartsWith("Card "))
12724
{
12825
string[] nameSplit = name.Split('('); // [Card (, name_of_card)]
@@ -198,24 +95,17 @@ public static string cleanCardName(string name)
19895
CardAppearanceBehaviour.Appearance.DynamicPortrait
19996
};
20097

201-
public static byte[] getArtworkFileAsBytes(BaseUnityPlugin plugin, string path)
98+
public static byte[] ReadArtworkFileAsBytes(string nameOfCardArt)
20299
{
203-
if (!path.StartsWith("Artwork/"))
204-
{
205-
path = String.Join("Artwork/", path);
206-
}
207-
208-
return File.ReadAllBytes(Path.Combine(
209-
plugin.Info.Location.Replace("CardLoaderMod.dll", ""),
210-
path
211-
)
212-
);
100+
return File.ReadAllBytes(
101+
Directory.GetFiles(Paths.PluginPath, nameOfCardArt, SearchOption.AllDirectories)[0]
102+
);
213103
}
214104

215105
public static Texture2D getAndloadImageAsTexture(string pathCardArt)
216106
{
217107
Texture2D texture = new Texture2D(2, 2);
218-
byte[] imgBytes = File.ReadAllBytes(pathCardArt);
108+
byte[] imgBytes = ReadArtworkFileAsBytes(pathCardArt);
219109
bool isLoaded = texture.LoadImage(imgBytes);
220110
return texture;
221111
}

Utils/PrintUtils.cs

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
using System.Collections.Generic;
2+
using DiskCardGame;
3+
4+
namespace APIPlugin
5+
{
6+
public class PrintUtils
7+
{
8+
// Print section
9+
public static void PrintStatIconInfo(StatIconInfo info)
10+
{
11+
Plugin.Log.LogInfo($"\nStatIconInfo");
12+
Plugin.Log.LogInfo($"GBC Description [{info.gbcDescription}]");
13+
Plugin.Log.LogInfo($"Rulebook Name [{info.rulebookName}]");
14+
Plugin.Log.LogInfo($"Rulebook Description [{info.rulebookDescription}]");
15+
Plugin.Log.LogInfo($"Applies to Attack [{info.appliesToAttack}] Health [{info.appliesToAttack}]");
16+
PrintList("MetaCategory", info.metaCategories);
17+
}
18+
19+
public static void PrintAllCardInfo()
20+
{
21+
foreach (var info in CardLoader.AllData)
22+
{
23+
PrintCardInfo(info);
24+
}
25+
}
26+
27+
public static void PrintCardModInfoList(List<CardModificationInfo> mods)
28+
{
29+
if (mods.Count == 0) return;
30+
31+
Plugin.Log.LogInfo("Card Mods Info");
32+
foreach (var mod in mods)
33+
{
34+
PrintCardModInfo(mod);
35+
}
36+
}
37+
38+
public static void PrintCardModInfo(CardModificationInfo mod)
39+
{
40+
Plugin.Log.LogInfo($"ID [{mod.singletonId}]");
41+
Plugin.Log.LogInfo($"Gemify? [{mod.gemify}]");
42+
Plugin.Log.LogInfo($"Attack Adjustment [{mod.attackAdjustment}]");
43+
Plugin.Log.LogInfo($"Health Adjustment [{mod.healthAdjustment}]");
44+
Plugin.Log.LogInfo($"Blood Cost Adjustment [{mod.bloodCostAdjustment}]");
45+
Plugin.Log.LogInfo($"Bones Cost Adjustment [{mod.bonesCostAdjustment}]");
46+
Plugin.Log.LogInfo($"Energy Cost Adjustment [{mod.energyCostAdjustment}]");
47+
Plugin.Log.LogInfo($"Non-Copyable? [{mod.nonCopyable}]");
48+
Plugin.Log.LogInfo($"From Card Merge? [{mod.fromCardMerge}]");
49+
Plugin.Log.LogInfo($"From Duplicate Merge? [{mod.fromDuplicateMerge}]");
50+
Plugin.Log.LogInfo($"From Latch? [{mod.fromLatch}]");
51+
Plugin.Log.LogInfo($"From Overclock? [{mod.fromOverclock}]");
52+
Plugin.Log.LogInfo($"From Totem? [{mod.fromTotem}]");
53+
Plugin.Log.LogInfo($"Nullify Gems Cost? [{mod.nullifyGemsCost}]");
54+
Plugin.Log.LogInfo($"Side Deck Mod? [{mod.sideDeckMod}]");
55+
Plugin.Log.LogInfo($"Special Stat Icon [{mod.statIcon}]");
56+
Plugin.Log.LogInfo($"Remove On upkeep? [{mod.RemoveOnUpkeep}]");
57+
58+
PrintList("Abilities", mod.abilities);
59+
PrintList("Negate Abilities", mod.negateAbilities);
60+
PrintList("Special Abilities", mod.specialAbilities);
61+
PrintList("Add Gem Costs", mod.addGemCost);
62+
PrintList("DecalIds", mod.decalIds);
63+
}
64+
65+
public static void PrintList<T>(string title, List<T> items)
66+
{
67+
if (items.Count == 0) return;
68+
Plugin.Log.LogInfo(title);
69+
items.ForEach(item => Plugin.Log.LogInfo($"-> {item}"));
70+
}
71+
72+
public static void PrintCardInfo(CardInfo info)
73+
{
74+
Plugin.Log.LogInfo($"===============");
75+
Plugin.Log.LogInfo($"Name [{info.name}]");
76+
Plugin.Log.LogInfo($"Displayed Name [{info.displayedName}]");
77+
Plugin.Log.LogInfo($"Description [{info.description}]");
78+
Plugin.Log.LogInfo($"Attack [{info.baseAttack}] Health [{info.baseHealth}]");
79+
Plugin.Log.LogInfo($"Boon [{info.boon}]");
80+
Plugin.Log.LogInfo($"Bones Cost [{info.bonesCost}]");
81+
Plugin.Log.LogInfo($"Cost [{info.cost}]");
82+
Plugin.Log.LogInfo($"Temple [{info.temple}]");
83+
Plugin.Log.LogInfo($"CardComplexity [{info.cardComplexity}]");
84+
Plugin.Log.LogInfo($"EnergyCost [{info.energyCost}]");
85+
if (info.evolveParams is not null)
86+
Plugin.Log.LogInfo(
87+
$"EvolveParams = Turns to evolve [{info.evolveParams.turnsToEvolve}] Evolves into [{info.evolveParams.evolution.name}]");
88+
Plugin.Log.LogInfo($"Can sacrifice? [{info.Sacrificable}]");
89+
Plugin.Log.LogInfo($"Is Gemified? [{info.Gemified}]");
90+
if (info.iceCubeParams is not null)
91+
Plugin.Log.LogInfo($"IceCubeParams = [{info.iceCubeParams.creatureWithin.name}]");
92+
Plugin.Log.LogInfo($"SpecialStatIcon [{info.specialStatIcon}]");
93+
Plugin.Log.LogInfo($"One per deck? [{info.onePerDeck}]");
94+
// TODO: possible to get an NRE if the power level is not set?
95+
// Plugin.Log.LogInfo($"Power Level [{info.PowerLevel}]");
96+
PrintList("Abilities", info.Abilities);
97+
PrintList("Special Abilities", info.SpecialAbilities);
98+
PrintList("Appearance Behavior", info.appearanceBehaviour);
99+
PrintList("Gems Cost", info.GemsCost);
100+
PrintList("MetaCategory", info.metaCategories);
101+
PrintList("Traits", info.traits);
102+
PrintList("Tribes", info.tribes);
103+
104+
PrintCardModInfoList(info.mods);
105+
106+
Plugin.Log.LogInfo($"===============\n");
107+
}
108+
}
109+
}

0 commit comments

Comments
 (0)