Pet Battle Scripts

Pet Battle Scripts

265k Downloads

rematch: use REMATCH_TEAM_OVERWRITTEN argument saveMode if Gello adds it

bloerwald opened this issue ยท 0 comments

commented

Currently queries UI dialog for it. Gello suggested it to be added as an argument to the event. Use it, if that happens.

diff --git a/Rematch/Addon.lua b/Rematch/Addon.lua
index 6efc310..c0fac1b 100644
--- a/Rematch/Addon.lua
+++ b/Rematch/Addon.lua
@@ -73,5 +73,5 @@ function RematchPlugin:OnEnable()
         end
 
-        Rematch.events:Register(self, 'REMATCH_TEAM_OVERWRITTEN', function(self, overwriteID, teamID)
+        Rematch.events:Register(self, 'REMATCH_TEAM_OVERWRITTEN', function(self, overwriteID, teamID, saveMode)
             -- overwriteID is being overwritten with import, and wont have a script
             if overwriteID and not teamID then
@@ -79,7 +79,8 @@ function RematchPlugin:OnEnable()
             end
 
-            -- Note: Getting the subject from the UI instead of event data is Gello-approved.
-            local subject = Rematch.dialog:GetSubject()
-            if subject and subject.saveMode ~= Rematch.constants.SAVE_MODE_EDIT then
+            -- Note: Getting the subject from the UI instead of event data is Gello-approved. A later version
+            -- added it as an event argument to avoid future breakage.
+            saveMode = saveMode or (Rematch.dialog:GetSubject() and Rematch.dialog:GetSubject().saveMode)
+            if saveMode and saveMode ~= Rematch.constants.SAVE_MODE_EDIT then
                 if teamID and self:GetScript(teamID) then -- team exists, and has script
                     self:CopyScript(teamID, overwriteID)