Skip to content

Commit

Permalink
Added ResourceBank functionality
Browse files Browse the repository at this point in the history
+ Updated ResourceBank LDB feed
+ Improved LDB versioning / object re-loading by doing some shady stuff
  • Loading branch information
imevul committed Jul 5, 2024
1 parent 5dadab2 commit 8a20f0e
Show file tree
Hide file tree
Showing 6 changed files with 95 additions and 41 deletions.
4 changes: 3 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@
"GetItemAffixMask",
"ItemAttuneAffix",
"HasAttunedAnyVariantOfItem",
"GetItemAttuneForge"
"GetItemAttuneForge",
"CastSpellByName",
"OpenPerkMgr"
]
}
10 changes: 10 additions & 0 deletions SynastriaAPI.md
Original file line number Diff line number Diff line change
Expand Up @@ -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!

Expand Down
96 changes: 59 additions & 37 deletions src/SynastriaCoreLib/SynastriaCoreLib-1.0/Modules/LDB.lua
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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

Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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')
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/SynastriaCoreLib/SynastriaCoreLib.toc
Original file line number Diff line number Diff line change
Expand Up @@ -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@
Expand Down

0 comments on commit 8a20f0e

Please sign in to comment.