From 8a20f0e923061315e75f59ca34776839b439db9e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20S=C3=B6derberg?= <591175+imevul@users.noreply.github.com> Date: Fri, 5 Jul 2024 17:50:07 +0200 Subject: [PATCH] Added ResourceBank functionality + Updated ResourceBank LDB feed + Improved LDB versioning / object re-loading by doing some shady stuff --- .vscode/settings.json | 4 +- SynastriaAPI.md | 10 ++ .../SynastriaCoreLib-1.0/Modules/LDB.lua | 96 ++++++++++++------- .../Modules/ResourceBank.lua | 22 ++++- .../SynastriaCoreLib-1.0.lua | 2 +- src/SynastriaCoreLib/SynastriaCoreLib.toc | 2 +- 6 files changed, 95 insertions(+), 41 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index a31bd2e..896d103 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -57,6 +57,8 @@ "GetItemAffixMask", "ItemAttuneAffix", "HasAttunedAnyVariantOfItem", - "GetItemAttuneForge" + "GetItemAttuneForge", + "CastSpellByName", + "OpenPerkMgr" ] } \ No newline at end of file diff --git a/SynastriaAPI.md b/SynastriaAPI.md index dc7f9f1..e20019c 100644 --- a/SynastriaAPI.md +++ b/SynastriaAPI.md @@ -38,6 +38,16 @@ Consider using the helper functions in SynastriaCoreLib that takes care of a lot ### CustomIsClassMask(mask) -> bool ### GetItemTagsCustom(itemId) -> int, ... +### OpenAttuneSummary() +Opens the attunement window. Note that the stats are not refreshed when the window is opened this way! To refresh the attunement stats, you have to use the spell + +### OpenPerkMgr() +Opens the Perk manager window + +### OpenResourceSummary() +Opens the Resource Bank window + + ## Events Important! Before defining any event handler function, you should store any existing reference and make sure you call it first thing in your function. Otherwise, other addons depending on said event will break! diff --git a/src/SynastriaCoreLib/SynastriaCoreLib-1.0/Modules/LDB.lua b/src/SynastriaCoreLib/SynastriaCoreLib-1.0/Modules/LDB.lua index 9ca35dd..9dc263e 100644 --- a/src/SynastriaCoreLib/SynastriaCoreLib-1.0/Modules/LDB.lua +++ b/src/SynastriaCoreLib/SynastriaCoreLib-1.0/Modules/LDB.lua @@ -1,5 +1,5 @@ local _, NS = ... -local MODULE_NAME, MODULE_VERSION = 'LDB', 4 +local MODULE_NAME, MODULE_VERSION = 'LDB', 5 NS.DebugLog(MODULE_NAME, MODULE_VERSION, 'Start') if not NS.loaded then return end @@ -17,6 +17,15 @@ NS.DebugLog(MODULE_NAME, MODULE_VERSION, 'Loaded') local LDB = LibStub('LibDataBroker-1.1') +local function RemoveDataObject(name) + if LDB.proxystorage[name] then + LDB.proxystorage[name] = nil + return true + end + + return false +end + local function GetTopInProgress(maxNum) local ret = {} local count = 0 @@ -46,16 +55,19 @@ local function GetActiveTasks(maxNum) return ret, count end -local function GetResources() +local function GetResources(maxNum) local ret = {} + local total = 0 local count = 0 - local resources = {} + local resources = SynastriaCoreLib.ResourceBank.GetResources() for _, resource in pairs(resources) do - table.insert(ret, { name = resource.name, count = resource.count }) - count = count + resource.count + table.insert(ret, { itemId = resource.itemId, itemName = resource.itemName, itemLink = resource.itemLink, count = resource.count, itemType = resource.itemType, itemSubType = resource.itemSubType }) + total = total + resource.count + count = count + 1 + if maxNum and count >= maxNum then break end end - return ret, count + return ret, total, count end local UPDATEPERIOD, elapsed = 5, 4 @@ -76,55 +88,65 @@ local function updateFeeds(self, elap) end if SynastriaCoreLib.LDB.resourceBankFeed then - local _, count = GetResources() - SynastriaCoreLib.LDB.resourceBankFeed.text = ('Resource Bank: %s'):format(count) + local _, total, count = GetResources() + SynastriaCoreLib.LDB.resourceBankFeed.text = ('Resource Bank: %s'):format(total) end end -if not SynastriaCoreLib.LDB.minimapButton then - SynastriaCoreLib.LDB.minimapButton = LDB:NewDataObject('SCL - SynastriaCoreLib', { - type = 'launcher', - text = 'SynastriaCoreLib', - icon = "Interface\\Icons\\Spell_Nature_StormReach", - }) -end -if not SynastriaCoreLib.LDB.inProgressFeed then - SynastriaCoreLib.LDB.inProgressFeed = LDB:NewDataObject('SCL: In Progress', { type = 'data source', text = 'Attunement', icon = "Interface\\Icons\\Spell_Nature_StormReach", }) - function SynastriaCoreLib.LDB.inProgressFeed:OnTooltipShow() - local inProgressItems, total = GetTopInProgress(10) +RemoveDataObject('SCL - SynastriaCoreLib') +SynastriaCoreLib.LDB.minimapButton = LDB:NewDataObject('SCL - SynastriaCoreLib', { + type = 'launcher', + text = 'SynastriaCoreLib', + icon = "Interface\\Icons\\Inv_Misc_Gem_Pearl_04", +}) - for _, item in ipairs(inProgressItems) do - self:AddDoubleLine(item.left, item.right) - end - self:AddLine(' ') - self:AddDoubleLine('Total:', total) +RemoveDataObject('SCL: In Progress') +SynastriaCoreLib.LDB.inProgressFeed = LDB:NewDataObject('SCL: In Progress', { type = 'data source', text = 'Attunement', icon = "Interface\\Icons\\Spell_Holy_Spellwarding", OnClick = function() OpenAttuneSummary() end }) + +function SynastriaCoreLib.LDB.inProgressFeed:OnTooltipShow() + local inProgressItems, total = GetTopInProgress(10) + + for _, item in ipairs(inProgressItems) do + self:AddDoubleLine(item.left, item.right) end + + self:AddLine(' ') + self:AddDoubleLine('Total:', total) end -if not SynastriaCoreLib.LDB.perkTaskFeed then - SynastriaCoreLib.LDB.perkTaskFeed = LDB:NewDataObject('SCL: Perk Tasks', { type = 'data source', text = 'Perk Tasks', }) - function SynastriaCoreLib.LDB.perkTaskFeed:OnTooltipShow() - local tasks = GetActiveTasks(25) +RemoveDataObject('SCL: Perk Tasks') +SynastriaCoreLib.LDB.perkTaskFeed = LDB:NewDataObject('SCL: Perk Tasks', { type = 'data source', text = 'Perk Tasks', icon = "Interface\\Icons\\Achievement_Quests_Completed_Daily_07", OnClick = function() OpenPerkMgr() end }) - for _, task in ipairs(tasks) do - self:AddDoubleLine(task.left, task.right, 1, 1, 1, 1, 1, 1) - end +function SynastriaCoreLib.LDB.perkTaskFeed:OnTooltipShow() + local tasks = GetActiveTasks(25) + + for _, task in ipairs(tasks) do + self:AddDoubleLine(task.left, task.right, 1, 1, 1, 1, 1, 1) end end -if not SynastriaCoreLib.LDB.resourceBankFeed then - SynastriaCoreLib.LDB.resourceBankFeed = LDB:NewDataObject('SCL: Resource Bank', { type = 'data source', text = 'Resource Bank', }) - function SynastriaCoreLib.LDB.resourceBankFeed:OnTooltipShow() - local resources = GetResources() +RemoveDataObject('SCL: Resource Bank') +SynastriaCoreLib.LDB.resourceBankFeed = LDB:NewDataObject('SCL: Resource Bank', { type = 'data source', text = 'Resource Bank', icon = "Interface\\Icons\\Inv_Misc_Bag_22", OnClick = function() OpenResourceSummary() end }) + +function SynastriaCoreLib.LDB.resourceBankFeed:OnTooltipShow() + local resources = GetResources(25) - for _, item in ipairs(resources) do - self:AddDoubleLine(item.name, item.count, 1, 1, 1, 1, 1, 1) + local category = nil + for _, item in ipairs(resources) do + local newCategory = ('%s - %s'):format(item.itemType, item.itemSubType) + if category ~= newCategory then + if category then + self:AddLine(' ') + end + category = newCategory + self:AddLine(category) end + self:AddDoubleLine(item.itemLink, item.count, 1, 1, 1, 1, 1, 1) end end diff --git a/src/SynastriaCoreLib/SynastriaCoreLib-1.0/Modules/ResourceBank.lua b/src/SynastriaCoreLib/SynastriaCoreLib-1.0/Modules/ResourceBank.lua index 7a3de63..9e4e76e 100644 --- a/src/SynastriaCoreLib/SynastriaCoreLib-1.0/Modules/ResourceBank.lua +++ b/src/SynastriaCoreLib/SynastriaCoreLib-1.0/Modules/ResourceBank.lua @@ -1,5 +1,5 @@ local _, NS = ... -local MODULE_NAME, MODULE_VERSION = 'ResourceBank', 1 +local MODULE_NAME, MODULE_VERSION = 'ResourceBank', 2 NS.DebugLog(MODULE_NAME, MODULE_VERSION, 'Start') if not NS.loaded then return end @@ -14,4 +14,24 @@ SynastriaCoreLib.ResourceBank = SynastriaCoreLib.ResourceBank or {} if not SynastriaCoreLib._RegisterModule(MODULE_NAME, SynastriaCoreLib.ResourceBank, MODULE_VERSION) then return end NS.DebugLog(MODULE_NAME, MODULE_VERSION, 'Loaded') + +function SynastriaCoreLib.ResourceBank.GetResources() + local ret = {} + for itemId, count in SynastriaCoreLib.AllCustomGameData(SynastriaCoreLib.CustomDataTypes.RESOURCE_BANK) do + local itemName, itemLink, _, _, _, itemType, itemSubType = SynastriaCoreLib.GetItemInfoCustom(itemId) + table.insert(ret, { itemId = itemId, itemName = itemName, itemLink = itemLink, count = count, itemType = itemType, itemSubType = itemSubType }) + end + + table.sort(ret, function(a, b) + local aa = ('%s - %s'):format(a.itemType, a.itemSubType):upper() + local bb = ('%s - %s'):format(b.itemType, b.itemSubType):upper() + if aa == bb then + return a.itemName < b.itemName + end + return aa < bb + end) + + return ret +end + NS.DebugLog(MODULE_NAME, MODULE_VERSION, 'Done') diff --git a/src/SynastriaCoreLib/SynastriaCoreLib-1.0/SynastriaCoreLib-1.0.lua b/src/SynastriaCoreLib/SynastriaCoreLib-1.0/SynastriaCoreLib-1.0.lua index a1b71e9..840e277 100644 --- a/src/SynastriaCoreLib/SynastriaCoreLib-1.0/SynastriaCoreLib-1.0.lua +++ b/src/SynastriaCoreLib/SynastriaCoreLib-1.0/SynastriaCoreLib-1.0.lua @@ -1,5 +1,5 @@ local wowAddonName, NS = ... -local SYNASTRIACORELIB_MAJOR, SYNASTRIACORELIB_MINOR = 'SynastriaCoreLib-1.0', 14 +local SYNASTRIACORELIB_MAJOR, SYNASTRIACORELIB_MINOR = 'SynastriaCoreLib-1.0', 15 NS.SYNASTRIACORELIB_MINOR = SYNASTRIACORELIB_MINOR if not SCL then SCL = {} end diff --git a/src/SynastriaCoreLib/SynastriaCoreLib.toc b/src/SynastriaCoreLib/SynastriaCoreLib.toc index bc87111..8e4efc3 100644 --- a/src/SynastriaCoreLib/SynastriaCoreLib.toc +++ b/src/SynastriaCoreLib/SynastriaCoreLib.toc @@ -2,7 +2,7 @@ ## Title: SynastriaCoreLib-1.0 ## Notes: A library of functions from Synastria ## Author: Imevul, meh321 -## Version: 1.0.14-Release +## Version: 1.0.15-Release ## X-Category: Imevul #@no-lib-strip@