1+ using System . Collections . Generic ;
2+ using CardLoaderPlugin . lib ;
3+ using DiskCardGame ;
4+ using UnityEngine ;
5+
6+ namespace APIPlugin
7+ {
8+ public static class NewCard
9+ {
10+ public static List < CardInfo > cards = new List < CardInfo > ( ) ;
11+
12+ public static void Add ( CardInfo card )
13+ {
14+ NewCard . cards . Add ( card ) ;
15+ Plugin . Log . LogInfo ( $ "Loaded custom card { card . name } !") ;
16+ }
17+
18+ // TODO Implement a handler for custom appearanceBehaviour - in particular custom card backs
19+ // TODO Change parameter order, and function setter call order to make more sense
20+ // TODO Rename parameters to be more user friendly
21+ public static void Add ( string name , List < CardMetaCategory > metaCategories , CardComplexity cardComplexity ,
22+ CardTemple temple , string displayedName , int baseAttack , int baseHealth ,
23+ string description = null ,
24+ bool hideAttackAndHealth = false , int cost = 0 , int bonesCost = 0 , int energyCost = 0 ,
25+ List < GemType > gemsCost = null , SpecialStatIcon specialStatIcon = SpecialStatIcon . None ,
26+ List < Tribe > tribes = null , List < Trait > traits = null , List < SpecialTriggeredAbility > specialAbilities = null ,
27+ List < Ability > abilities = null , EvolveParams evolveParams = null ,
28+ string defaultEvolutionName = null , TailParams tailParams = null , IceCubeParams iceCubeParams = null ,
29+ bool flipPortraitForStrafe = false , bool onePerDeck = false ,
30+ List < CardAppearanceBehaviour . Appearance > appearanceBehaviour = null , Texture2D tex = null ,
31+ Texture2D altTex = null , Texture titleGraphic = null , Texture2D pixelTex = null ,
32+ GameObject animatedPortrait = null , List < Texture > decals = null )
33+ {
34+ CardInfo card = ScriptableObject . CreateInstance < CardInfo > ( ) ;
35+
36+ // names / descryptions
37+ card . defaultEvolutionName = defaultEvolutionName ;
38+ card . displayedName = displayedName ;
39+ card . name = name ;
40+
41+ if ( description != "" )
42+ {
43+ card . description = description ;
44+ }
45+
46+ // card info
47+ card . baseAttack = baseAttack ;
48+ card . baseHealth = baseHealth ;
49+ card . cardComplexity = cardComplexity ;
50+ card . flipPortraitForStrafe = flipPortraitForStrafe ;
51+ card . hideAttackAndHealth = hideAttackAndHealth ;
52+ card . metaCategories = metaCategories ;
53+ card . onePerDeck = onePerDeck ;
54+ card . specialStatIcon = specialStatIcon ;
55+ card . temple = temple ;
56+
57+ if ( tribes is not null )
58+ {
59+ card . tribes = tribes ;
60+ }
61+
62+ if ( traits is not null )
63+ {
64+ card . traits = traits ;
65+ }
66+
67+ if ( specialAbilities is not null )
68+ {
69+ card . specialAbilities = specialAbilities ;
70+ }
71+
72+ if ( abilities is not null )
73+ {
74+ card . abilities = abilities ;
75+ }
76+
77+ if ( evolveParams is not null )
78+ {
79+ card . evolveParams = evolveParams ;
80+ }
81+
82+ if ( tailParams is not null )
83+ {
84+ card . tailParams = tailParams ;
85+ }
86+
87+ if ( iceCubeParams is not null )
88+ {
89+ card . iceCubeParams = iceCubeParams ;
90+ }
91+
92+ if ( appearanceBehaviour is not null )
93+ {
94+ card . appearanceBehaviour = appearanceBehaviour ;
95+ }
96+
97+ // costs
98+ card . cost = cost ;
99+ card . bonesCost = bonesCost ;
100+ card . energyCost = energyCost ;
101+
102+ if ( gemsCost is not null )
103+ {
104+ card . gemsCost = gemsCost ;
105+ }
106+
107+ // textures
108+ DetermineAndSetCardArt ( name , card , tex , altTex , pixelTex ) ;
109+
110+ if ( animatedPortrait is not null )
111+ {
112+ // TODO Provide a function to create animated card textures
113+ card . animatedPortrait = animatedPortrait ;
114+ }
115+
116+ if ( decals is not null )
117+ {
118+ // TODO Access and provide default decals
119+ card . decals = decals ;
120+ }
121+
122+ if ( titleGraphic is not null )
123+ {
124+ card . titleGraphic = titleGraphic ;
125+ }
126+
127+ NewCard . cards . Add ( card ) ;
128+ Plugin . Log . LogInfo ( $ "Loaded custom card { name } !") ;
129+ }
130+
131+ private static void DetermineAndSetCardArt (
132+ string name , CardInfo card ,
133+ Texture2D tex , Texture2D altTex , Texture2D pixelTex )
134+ {
135+ var newName = "portrait_" + name ;
136+ if ( tex is not null )
137+ {
138+ tex . name = newName ;
139+ tex . filterMode = FilterMode . Point ;
140+
141+ card . portraitTex = Sprite . Create ( tex , CardUtils . DefaultCardArtRect , CardUtils . DefaultVector2 ) ;
142+ card . portraitTex . name = newName ;
143+ }
144+
145+ if ( altTex is not null )
146+ {
147+ altTex . name = newName ;
148+ altTex . filterMode = FilterMode . Point ;
149+
150+ card . alternatePortrait = Sprite . Create ( altTex , CardUtils . DefaultCardArtRect , CardUtils . DefaultVector2 ) ;
151+ card . alternatePortrait . name = newName ;
152+ }
153+
154+ if ( pixelTex is not null )
155+ {
156+ pixelTex . name = newName ;
157+ pixelTex . filterMode = FilterMode . Point ;
158+
159+ card . pixelPortrait = Sprite . Create ( pixelTex , CardUtils . DefaultCardPixelArtRect , CardUtils . DefaultVector2 ) ;
160+ card . pixelPortrait . name = newName ;
161+ }
162+ }
163+ }
164+ }
0 commit comments