From 5a3f29344b4108076602e30516dca072090c278a Mon Sep 17 00:00:00 2001 From: omicron Date: Fri, 24 Nov 2023 21:26:25 +0100 Subject: [PATCH] Fix compatibility issue with LibSharedMedia It appears LibSharedMedia does not always initialize the media lists from the media tables. To fix this we make sure the media lists match the media tables when the table already exists upon addon initialization. --- src/LibFreeMedia.lua | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/LibFreeMedia.lua b/src/LibFreeMedia.lua index eea021f..8bc0e26 100644 --- a/src/LibFreeMedia.lua +++ b/src/LibFreeMedia.lua @@ -42,6 +42,7 @@ local DEFAULT_MEDIA_TABLE = { } } +-- Build default media lists from the default media table local function MakeDefaultList() local lists = {} for kind, media in pairs(DEFAULT_MEDIA_TABLE) do @@ -66,6 +67,18 @@ do libsm = LibStub:NewLibrary("LibSharedMedia-3.0", 0) libsm.MediaTable = DEFAULT_MEDIA_TABLE libsm.MediaList = DEFAULT_MEDIA_LIST + else + -- Ensure the lists match the tables if we didn't create them + for kind, media in pairs(libsm.MediaTable) do + if libsm.MediaList[kind] == nil then + local mediaList = {} + for identifier, _ in pairs(media) do + table.insert(mediaList, identifier) + end + table.sort(mediaList) + libsm.MediaList[kind] = mediaList + end + end end ---@type table> @@ -94,7 +107,7 @@ local function RegisterOne(kind, identifier, data) end media[identifier] = data - table.insert(lib.mediaList[kind], identifier) + table.insert(mediaList, identifier) return true end