Skip to content

Commit

Permalink
Merge pull request #88 from LetsTimeIt/attempt-import-fix
Browse files Browse the repository at this point in the history
fix: MDT now attempts to sanitize available routes; in particular, if value is not a table, it chucks the route out entirely
fix: I added four global variables by accident. Removing them.
  • Loading branch information
srenauld authored Jan 3, 2021
2 parents e3b4cde + 17d4509 commit e8c0dc5
Showing 1 changed file with 23 additions and 5 deletions.
28 changes: 23 additions & 5 deletions DungeonTools.lua
Original file line number Diff line number Diff line change
Expand Up @@ -643,16 +643,16 @@ end
local framesInitialized

function MDT:ImportFromLegacyMDT()
mdtDb = LibStub("AceDB-3.0"):New("MythicDungeonToolsDB", defaultSavedVars).global
local mdtDb = LibStub("AceDB-3.0"):New("MythicDungeonToolsDB", defaultSavedVars).global
for dungeonIdx,presets in pairs(mdtDb.presets) do
if not db.presets[dungeonIdx] then
db.presets[dungeonIdx] = {}
end
oldPresetLen = #db.presets[dungeonIdx]
newPresetLen = #presets
local oldPresetLen = #db.presets[dungeonIdx]
local newPresetLen = #presets
-- Quick hack
db.presets[dungeonIdx][newPresetLen] = MDT:DeepCopy(db.presets[dungeonIdx][oldPresetLen])
currentIdx = oldPresetLen
local currentIdx = oldPresetLen
for _,preset in pairs(presets) do
if preset["text"] ~= "Default" and preset["text"] ~= "<New Preset>" then
db.presets[dungeonIdx][currentIdx] = MDT:DeepCopy(preset)
Expand All @@ -669,6 +669,8 @@ function MDT:ShowInterface(force)
if not db.Imported then
MDT:ImportFromLegacyMDT()
end

MDT:SanitizePresets()

if self.main_frame:IsShown() and not force then
MDT:HideInterface()
Expand Down Expand Up @@ -2793,7 +2795,23 @@ function MDT:CreateDungeonSelectDropdown(frame)

MDT:UpdateDungeonDropDown()
end

function MDT:SanitizePresets()
for dungeonIdx,presets in pairs(db.presets) do
local out = {}
local firstIdx = 1
for presetIdx,preset in pairs(presets) do
if MDT:ValidateImportPreset(preset) == false and presetIdx ~= 1 and presetIdx ~= #presets then
if presetIdx == db.currentPreset[dungeonIdx] then
db.currentPreset[dungeonIdx] = 1
end
else
out[firstIdx] = MDT:DeepCopy(preset)
firstIdx = firstIdx + 1
end
end
db.presets[dungeonIdx] = MDT:DeepCopy(out)
end
end
---EnsureDBTables
---Makes sure profiles are valid and have their fields set
function MDT:EnsureDBTables()
Expand Down

0 comments on commit e8c0dc5

Please sign in to comment.