1+ using System . Collections . ObjectModel ;
12using System . Diagnostics . CodeAnalysis ;
23using DiskCardGame ;
34using HarmonyLib ;
4- using Mono . Collections . Generic ;
55using Sirenix . Serialization . Utilities ;
66using UnityEngine ;
77
@@ -11,43 +11,28 @@ namespace InscryptionAPI.Card;
1111public static class CardManager
1212{
1313 public static readonly ReadOnlyCollection < CardInfo > BaseGameCards = new ( Resources . LoadAll < CardInfo > ( "Data/Cards" ) ) ;
14- private static readonly List < CardInfo > NewCards = new ( ) ;
15-
16- private static long _counter = 0 ;
17- private static long _lastBuilt = - 1 ;
14+ private static readonly ObservableCollection < CardInfo > NewCards = new ( ) ;
1815
19- public static event Action < List < CardInfo > > ModifyCardList ;
20-
21- private static List < CardInfo > _allCards ;
16+ public static event Func < List < CardInfo > , List < CardInfo > > ModifyCardList ;
2217
23- public static List < CardInfo > AllCards
18+ static CardManager ( )
2419 {
25- get
20+ AllCards = BaseGameCards . ToList ( ) ;
21+ NewCards . CollectionChanged += static ( _ , _ ) =>
2622 {
27- if ( _counter != _lastBuilt )
28- {
29- _lastBuilt = _counter ;
30- _allCards = BaseGameCards . Append ( NewCards ) . ToList ( ) ;
31- ModifyCardList ? . Invoke ( _allCards ) ;
32- }
33- return _allCards ;
34- }
23+ var cards = BaseGameCards . Append ( NewCards ) . ToList ( ) ;
24+ AllCards = ModifyCardList ? . Invoke ( cards ) ?? cards ;
25+ } ;
3526 }
3627
37- public static void Add ( CardInfo newCard )
38- {
39- NewCards . Add ( newCard ) ;
40- ++ _counter ;
41- }
42- public static void Remove ( CardInfo card )
43- {
44- NewCards . Remove ( card ) ;
45- ++ _counter ;
46- }
28+ public static List < CardInfo > AllCards { get ; private set ; }
29+
30+ public static void Add ( CardInfo newCard ) => NewCards . Add ( newCard ) ;
31+ public static void Remove ( CardInfo card ) => NewCards . Remove ( card ) ;
4732
4833 [ HarmonyPrefix ]
4934 [ HarmonyPatch ( typeof ( ScriptableObjectLoader < UnityObject > ) , nameof ( ScriptableObjectLoader < UnityObject > . LoadData ) ) ]
50- [ SuppressMessage ( "Member Access" , "Publicizer001" ) ]
35+ [ SuppressMessage ( "Member Access" , "Publicizer001" , Justification = "Need to set internal list of cards" ) ]
5136 private static void CardLoadPrefix ( )
5237 {
5338 ScriptableObjectLoader < CardInfo > . allData = AllCards ;
0 commit comments