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