Bladeren bron

Add events for the extended card format

Bepis 6 jaren geleden
bovenliggende
commit
6764c2ff6e
2 gewijzigde bestanden met toevoegingen van 25 en 2 verwijderingen
  1. 21 2
      Plugins/ExtensibleSaveFormat/ExtensibleSaveFormat.cs
  2. 4 0
      Plugins/ExtensibleSaveFormat/Hooks.cs

+ 21 - 2
Plugins/ExtensibleSaveFormat/ExtensibleSaveFormat.cs

@@ -14,14 +14,33 @@ namespace ExtensibleSaveFormat
 
         public override Version Version => new Version("1.0");
 
+        void Awake()
+        {
+            Hooks.InstallHooks();
+        }
 
         internal static Dictionary<ChaFile, Dictionary<string, object>> internalDictionary = new Dictionary<ChaFile, Dictionary<string, object>>();
 
-        public ExtensibleSaveFormat()
+        #region Events
+
+        public delegate void CardEventHandler(ChaFile file);
+
+        public static event CardEventHandler CardBeingSaved;
+
+        public static event CardEventHandler CardBeingLoaded;
+
+        internal static void writeEvent(ChaFile file)
         {
-            Hooks.InstallHooks();
+            CardBeingSaved?.Invoke(file);
+        }
+
+        internal static void readEvent(ChaFile file)
+        {
+            CardBeingLoaded?.Invoke(file);
         }
 
+        #endregion
+
 
         public static bool TryGetExtendedFormat(ChaFile file, out Dictionary<string, object> extendedFormatData)
         {

+ 4 - 0
Plugins/ExtensibleSaveFormat/Hooks.cs

@@ -35,6 +35,8 @@ namespace ExtensibleSaveFormat
             if (!__result)
                 return;
 
+            ExtensibleSaveFormat.writeEvent(__instance);
+
             if (!ExtensibleSaveFormat.TryGetExtendedFormat(__instance, out Dictionary<string, object> extendedData))
                 return;
 
@@ -66,6 +68,8 @@ namespace ExtensibleSaveFormat
 
             //initialize a new dictionary since it doesn't exist
             ExtensibleSaveFormat.internalDictionary[__instance] = new Dictionary<string, object>();
+
+            ExtensibleSaveFormat.readEvent(__instance);
         }
     }
 }