Skip to content

Commit

Permalink
Use fancy new metatable from Dashi
Browse files Browse the repository at this point in the history
  • Loading branch information
p3lim committed Jan 10, 2025
1 parent 41a7dca commit 5cf0f29
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 22 deletions.
1 change: 0 additions & 1 deletion .luacheckrc
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ read_globals = {
'HideUIPanel',
'ShowUIPanel',
'Mixin',
'tContains',

-- GlobalStrings
'DUNGEON_FLOOR_BLACKROCKDEPTHS2',
Expand Down
2 changes: 1 addition & 1 deletion providers/cosmic.lua
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ function cosmicArrowsProvider:OnAdded(...)
MapCanvasDataProviderMixin.OnAdded(self, ...) -- super

-- create buffer
addon.activeCosmicWorlds = {}
addon.activeCosmicWorlds = addon:T()
end

function cosmicArrowsProvider:OnRelease(hadPins)
Expand Down
28 changes: 8 additions & 20 deletions utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ local _, addon = ...

local COSMIC_MAP_ID = 946

local activeMaps = {}
local activeMaps = addon:T()
function addon:FlagMap(mapID)
if not tContains(activeMaps, mapID) then
table.insert(activeMaps, mapID)
if not activeMaps:contains(mapID) then
activeMaps:insert(mapID)
end
end

Expand Down Expand Up @@ -35,18 +35,6 @@ do
end
end

local function mergeTables(t1, t2)
-- recurse through tables and merge them
for k, v in next, t2 do
if type(t1[k] or false) == 'table' then
mergeTables(t1[k], t2[k])
else
t1[k] = v
end
end
return t1
end

function addon:GetCommonMap()
-- returns the common parent map for the maps provided
-- this logic is a bit wasteful with tables, but it's never called in combat and takes less
Expand All @@ -58,10 +46,10 @@ do

-- build a table of map ancestries, where the outermost table is the Cosmic map, and the
-- innermost table is each map in the provided table
local ancestry = {}
local ancestry = addon:T()
for _, mapID in next, activeMaps do
-- merge this map ancestry with all others
ancestry = mergeTables(ancestry, getMapAncestry(mapID))
ancestry:merge(getMapAncestry(mapID))
end

-- iterate through the full ancestry table until we find a parent map that has either
Expand All @@ -74,7 +62,7 @@ do

if ancestry[COSMIC_MAP_ID] and addon.activeCosmicWorlds then
for mapID in next, ancestry[COSMIC_MAP_ID] do
table.insert(addon.activeCosmicWorlds, mapID)
addon.activeCosmicWorlds:insert(mapID)
end
end

Expand All @@ -83,9 +71,9 @@ do
end

WorldMapFrame:HookScript('OnHide', function()
table.wipe(activeMaps)
activeMaps:wipe()

if addon.activeCosmicWorlds then
table.wipe(addon.activeCosmicWorlds)
addon.activeCosmicWorlds:wipe()
end
end)

0 comments on commit 5cf0f29

Please sign in to comment.