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 {
@@ -160,7 +168,7 @@ private static void HandleIdentifiers(
160168 foreach ( var id in abilityIdsParam . Where ( id => id . id != 0 ) )
161169 {
162170 card . abilities . Add ( id . id ) ;
163- abilitiesToRemove . Add ( id ) ;
171+ abilitiesToRemove . Add ( id ) ;
164172 }
165173
166174 foreach ( AbilityIdentifier id in abilitiesToRemove )
@@ -175,16 +183,16 @@ private static void HandleIdentifiers(
175183 }
176184
177185 // Handle SpecialAbilityIds
178- List < SpecialAbilityIdentifier > specialAbilitiesToRemove = new List < SpecialAbilityIdentifier > ( ) ;
186+ List < SpecialAbilityIdentifier > specialAbilitiesToRemove = new List < SpecialAbilityIdentifier > ( ) ;
179187 if ( specialAbilitiesIdsParam is not null )
180188 {
181189 foreach ( var id in specialAbilitiesIdsParam . Where ( id => id . id != 0 ) )
182190 {
183191 card . specialAbilities . Add ( id . id ) ;
184- specialAbilitiesToRemove . Add ( id ) ;
192+ specialAbilitiesToRemove . Add ( id ) ;
185193 }
186194
187- foreach ( SpecialAbilityIdentifier id in specialAbilitiesToRemove )
195+ foreach ( SpecialAbilityIdentifier id in specialAbilitiesToRemove )
188196 {
189197 specialAbilitiesIdsParam . Remove ( id ) ;
190198 }
@@ -255,5 +263,38 @@ private static void DetermineAndSetCardArt(
255263 card . pixelPortrait . name = newName ;
256264 }
257265 }
266+
267+ private static void CreateAnimatedPortrait ( CardInfo card )
268+ {
269+ if ( ! card . appearanceBehaviour . Contains ( CardAppearanceBehaviour . Appearance . AnimatedPortrait ) )
270+ {
271+ card . appearanceBehaviour . Add ( CardAppearanceBehaviour . Appearance . AnimatedPortrait ) ;
272+ }
273+ Sprite mainSprite = Sprite . Create ( card . portraitTex . texture , card . portraitTex . rect , new Vector2 ( 0.5f , 0f ) ) ;
274+
275+ Sprite empty = Sprite . Create ( mainSprite . texture , new Rect ( 0 , 0 , 0 , 0 ) , new Vector2 ( 0.5f , 0.5f ) ) ;
276+
277+ GameObject obj = Instantiate ( Resources . Load < GameObject > ( "Prefabs/Cards/AnimatedPortraits/TalkingCardPortrait" ) ) ;
278+ obj . transform . localScale = new Vector3 ( obj . transform . localScale . x * 0.9f , obj . transform . localScale . y * 0.9f , obj . transform . localScale . z * 0.9f ) ;
279+ DontDestroyOnLoad ( obj ) ;
280+
281+ CharacterFace face = obj . GetComponentInChildren < CharacterFace > ( ) ;
282+ List < EmotionSprites > emotes = ( List < EmotionSprites > ) face . GetType ( ) . GetField ( "emotionSprites" , BindingFlags . NonPublic | BindingFlags . Instance ) . GetValue ( face ) ;
283+
284+ emotes . Clear ( ) ;
285+ emotes . Add ( new EmotionSprites ( )
286+ {
287+ emotion = Emotion . Neutral ,
288+ face = mainSprite ,
289+ eyesClosed = empty ,
290+ eyesClosedEmission = empty ,
291+ eyesOpen = empty ,
292+ eyesOpenEmission = empty ,
293+ mouthClosed = empty ,
294+ mouthOpen = empty
295+ } ) ;
296+
297+ card . animatedPortrait = obj ;
298+ }
258299 }
259300}
0 commit comments