11using System . Collections . Generic ;
22using System . Linq ;
3+ using System . Reflection ;
34using DiskCardGame ;
45using UnityEngine ;
6+ using static DiskCardGame . CharacterFace ;
7+ using static UnityEngine . Object ;
58
69namespace APIPlugin
710{
@@ -127,6 +130,11 @@ public static void Add(string name, string displayedName, int baseAttack, int ba
127130 // TODO Provide a function to create animated card textures
128131 card . animatedPortrait = animatedPortrait ;
129132 }
133+ else if ( specialAbilities . Contains ( SpecialTriggeredAbility . TalkingCardChooser ) )
134+ {
135+ // TODO: Make talking cards not depend on animated portraits
136+ CreateAnimatedPortrait ( card ) ;
137+ }
130138
131139 if ( decals is not null )
132140 {
@@ -165,7 +173,7 @@ private static void HandleIdentifiers(
165173 foreach ( var id in abilityIdsParam . Where ( id => id . id != 0 ) )
166174 {
167175 card . abilities . Add ( id . id ) ;
168- abilitiesToRemove . Add ( id ) ;
176+ abilitiesToRemove . Add ( id ) ;
169177 }
170178
171179 foreach ( AbilityIdentifier id in abilitiesToRemove )
@@ -180,16 +188,16 @@ private static void HandleIdentifiers(
180188 }
181189
182190 // Handle SpecialAbilityIds
183- List < SpecialAbilityIdentifier > specialAbilitiesToRemove = new List < SpecialAbilityIdentifier > ( ) ;
191+ List < SpecialAbilityIdentifier > specialAbilitiesToRemove = new List < SpecialAbilityIdentifier > ( ) ;
184192 if ( specialAbilitiesIdsParam is not null )
185193 {
186194 foreach ( var id in specialAbilitiesIdsParam . Where ( id => id . id != 0 ) )
187195 {
188196 card . specialAbilities . Add ( id . id ) ;
189- specialAbilitiesToRemove . Add ( id ) ;
197+ specialAbilitiesToRemove . Add ( id ) ;
190198 }
191199
192- foreach ( SpecialAbilityIdentifier id in specialAbilitiesToRemove )
200+ foreach ( SpecialAbilityIdentifier id in specialAbilitiesToRemove )
193201 {
194202 specialAbilitiesIdsParam . Remove ( id ) ;
195203 }
@@ -260,5 +268,38 @@ private static void DetermineAndSetCardArt(
260268 card . pixelPortrait . name = newName ;
261269 }
262270 }
271+
272+ private static void CreateAnimatedPortrait ( CardInfo card )
273+ {
274+ if ( ! card . appearanceBehaviour . Contains ( CardAppearanceBehaviour . Appearance . AnimatedPortrait ) )
275+ {
276+ card . appearanceBehaviour . Add ( CardAppearanceBehaviour . Appearance . AnimatedPortrait ) ;
277+ }
278+ Sprite mainSprite = Sprite . Create ( card . portraitTex . texture , card . portraitTex . rect , new Vector2 ( 0.5f , 0f ) ) ;
279+
280+ Sprite empty = Sprite . Create ( mainSprite . texture , new Rect ( 0 , 0 , 0 , 0 ) , new Vector2 ( 0.5f , 0.5f ) ) ;
281+
282+ GameObject obj = Instantiate ( Resources . Load < GameObject > ( "Prefabs/Cards/AnimatedPortraits/TalkingCardPortrait" ) ) ;
283+ obj . transform . localScale = new Vector3 ( obj . transform . localScale . x * 0.9f , obj . transform . localScale . y * 0.9f , obj . transform . localScale . z * 0.9f ) ;
284+ DontDestroyOnLoad ( obj ) ;
285+
286+ CharacterFace face = obj . GetComponentInChildren < CharacterFace > ( ) ;
287+ List < EmotionSprites > emotes = ( List < EmotionSprites > ) face . GetType ( ) . GetField ( "emotionSprites" , BindingFlags . NonPublic | BindingFlags . Instance ) . GetValue ( face ) ;
288+
289+ emotes . Clear ( ) ;
290+ emotes . Add ( new EmotionSprites ( )
291+ {
292+ emotion = Emotion . Neutral ,
293+ face = mainSprite ,
294+ eyesClosed = empty ,
295+ eyesClosedEmission = empty ,
296+ eyesOpen = empty ,
297+ eyesOpenEmission = empty ,
298+ mouthClosed = empty ,
299+ mouthOpen = empty
300+ } ) ;
301+
302+ card . animatedPortrait = obj ;
303+ }
263304 }
264305}
0 commit comments