Skip to content

Commit

Permalink
+ New embed version of SynastriaCoreLib
Browse files Browse the repository at this point in the history
- Removed .checkattune functionality (Now uses client functions)
+ Added more settings to reduce clutter!
  • Loading branch information
imevul committed Mar 22, 2024
1 parent b9482e5 commit 7173832
Show file tree
Hide file tree
Showing 7 changed files with 149 additions and 165 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
A simple addon to add some QOL for attunements

Features:
- `.checkattune` info in tooltip
- More detailed attunement information in tooltip

## Dependencies

Expand Down
202 changes: 43 additions & 159 deletions src/AttuneHelper/AttuneHelper.lua
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
local CONST_ADDON_NAME = "AttuneHelper"
AttuneHelper = LibStub("AceAddon-3.0"):NewAddon(CONST_ADDON_NAME, "AceConsole-3.0", "AceHook-3.0")

local cache = {}
local lastId = nil
local queriedItemId = nil
local suppressCounter = 0
local lastCheck = nil
local checkTimeout = 1

local L, db
local ttList = {
["GameTooltip"] = {
Expand All @@ -29,7 +22,8 @@ function AttuneHelper:OnInitialize()
local defaults = {
profile = {
showTooltip = true,
cacheDuration = 1,
showAttuned = true,
showAttunedType = false,
showItemId = false,
showStats = true
}
Expand Down Expand Up @@ -59,20 +53,7 @@ function AttuneHelper:OnInitialize()
end,
order = 1
},

cacheDuration = {
type = "range",
name = L["Cache duration (minutes)"],
min = 1,
max = 60,
step = 1,
get = function() return db.profile.cacheDuration end,
set = function(_, val)
db.profile.cacheDuration = val
end,
order = 2
},


showItemId = {
type = "toggle",
name = L["Show item ID"],
Expand All @@ -82,9 +63,33 @@ function AttuneHelper:OnInitialize()
set = function()
db.profile.showItemId = not db.profile.showItemId
end,
order = 2
},

showAttuned = {
type = "toggle",
name = L["Show attuned"],
get = function()
return db.profile.showAttuned
end,
set = function()
db.profile.showAttuned = not db.profile.showAttuned
end,
order = 3
},

showAttunedType = {
type = "toggle",
name = L["Show attuned type"],
get = function()
return db.profile.showAttunedType
end,
set = function()
db.profile.showAttunedType = not db.profile.showAttunedType
end,
order = 4
},

showStats = {
type = "toggle",
name = L["Show stats"],
Expand All @@ -94,7 +99,7 @@ function AttuneHelper:OnInitialize()
set = function()
db.profile.showStats = not db.profile.showStats
end,
order = 4
order = 5
},
}
}
Expand All @@ -112,117 +117,13 @@ function AttuneHelper:OnInitialize()
end
end

function AttuneHelper.CHAT_MSG_SYSTEM(_, _, message)
local matched = false
local id = tonumber(message:match('Item: [^%(]+ %((%d+)%)'))

-- First message
if id then
lastId = id

if not cache[id] then
cache[id] = {}
end

cache[id].attuned = nil
cache[id].type = nil
cache[id].suffixId = nil
cache[id].timestamp = time()
cache[id].queried = true
matched = true
else
id = tonumber(message:match('You have not attuned with item (%d+).'))
if id then
-- Not attuned
cache[id].attuned = false
suppressCounter = math.min(suppressCounter, 1)
matched = true
else
-- Second message
local attuned = message:match('Attuned: (%w+)')
if lastId and attuned == 'yes' then
cache[lastId].attuned = true
matched = true
else
-- Third message (optional)
local type, suffixId = message:match('Random: ([^%(]+) %((-?%d+)%)')
if lastId and type then
cache[lastId].type = type
cache[lastId].suffixId = tonumber(suffixId)
suppressCounter = math.min(suppressCounter, 1)
matched = true
end
end
end

if queriedItemId and lastId and queriedItemId == lastId then
queriedItemId = nil
end
end

if matched and suppressCounter > 0 then
suppressCounter = suppressCounter - 1
return true
end
end

function AttuneHelper:CheckAttune(itemId)
if type(itemId) ~= "number" then
return
end

if SynastriaCoreLib then
local itemValid = SynastriaCoreLib.CheckItemValid(itemId)
if not (itemValid == -2 or itemValid > 0) then
return
end
end

if not cache[itemId] then
cache[itemId] = {}
cache[itemId].timestamp = 0
end

local currentTime = time()

if GetItemAttuneProgress and GetItemAttuneProgress(itemId) ~= nil and cache[itemId].attuned == nil then
if SynastriaCoreLib then
cache[itemId].attuned = SynastriaCoreLib.IsAttuned(itemId)
else
cache[itemId].attuned = GetItemAttuneProgress(itemId) == 100
end

if cache[itemId].queried then
cache[itemId].timestamp = currentTime
end
end

if cache[itemId].queried and not cache[itemId].type then
return
end

if cache[itemId].timestamp < currentTime - db.profile.cacheDuration * 60 then
if lastCheck and lastCheck > currentTime - checkTimeout then
return
end

lastCheck = currentTime
cache[itemId].timestamp = currentTime
queriedItemId = itemId
suppressCounter = 3
SendChatMessage(".checkattune " .. itemId)
end
end

function AttuneHelper:OnEnable()
if db.profile.showTooltip then
self:HookTooltips()
end
end

function AttuneHelper:HookTooltips()
ChatFrame_AddMessageEventFilter("CHAT_MSG_SYSTEM", AttuneHelper.CHAT_MSG_SYSTEM)

for tooltip, scripts in pairs(ttList) do
if _G[tooltip] then
for script, _ in pairs(scripts) do
Expand All @@ -243,8 +144,6 @@ function AttuneHelper:HookTip(tooltip, script)
end

function AttuneHelper:UnhookTooltips()
ChatFrame_RemoveMessageEventFilter("CHAT_MSG_SYSTEM", AttuneHelper.CHAT_MSG_SYSTEM)

for tooltip, scripts in pairs(ttHooks) do
for script, _ in pairs(scripts) do
self:UnhookTip(tooltip, script)
Expand All @@ -263,46 +162,31 @@ function AttuneHelper:UnhookTip(tooltip, script)
end

function AttuneHelper:GetAttunementInfo(itemLink)
local itemId = tonumber(itemLink:match('item:(%d+)'))
if type(itemId) ~= "number" or itemId <= 0 then
return {}
end

local output = {}
local itemInfo = SynastriaCoreLib.GetItemInfo(itemLink)

self:CheckAttune(itemId)

if cache[itemId] then
if cache[itemId].attuned == nil then
output[#output+1] = "Attuned: |cffbbbbbbQuerying...|r"
else
if cache[itemId].attuned then
if itemInfo then
if db.profile.showAttuned then
if itemInfo.attuned then
output[#output+1] = "Attuned: |c0000ff00Yes|r"
else
output[#output+1] = "Attuned: |c00ff0000No|r"
end
end

if cache[itemId].type then
output[#output+1] = "Type: " .. cache[itemId].type .. " (" .. tostring(cache[itemId].suffixId) .. ")"

if db.profile.showStats then
local uniqueId = itemLink:match('item:%d+:[^:]*:[^:]*:[^:]*:[^:]*:[^:]*:[^:]*:([^:]*)')
local linkLevel = itemLink:match('item:%d+:[^:]*:[^:]*:[^:]*:[^:]*:[^:]*:[^:]*:[^:]*:([^:]*)')
local _, link = GetItemInfo('item:' .. tostring(itemId) .. '::::::' .. tostring(cache[itemId].suffixId) .. ':' .. tostring(uniqueId) .. ':' .. tostring(linkLevel))

local stats = {}
GetItemStats(link, stats)

for k, v in pairs(stats) do
if v and v ~= 0 then
local sign = '+'
if v < 0 then
sign = '-'
end
if itemInfo.suffixName then
if db.profile.showAttunedType then
output[#output+1] = "Type: " .. itemInfo.suffixName .. " (" .. itemInfo.suffixId .. ")"
end

output[#output+1] = ' |cffbbbbbb' .. sign .. tostring(v) .. ' ' .. tostring(_G[k]) .. '|r'
if db.profile.showStats and itemInfo.stats then
for _, stat in ipairs(itemInfo.stats) do
local sign = '+'
if stat.value < 0 then
sign = '-'
end

output[#output+1] = ' |cffbbbbbb' .. sign .. tostring(stat.value) .. ' ' .. stat.name .. '|r'
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion src/AttuneHelper/AttuneHelper.toc
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
## Title: AttuneHelper
## Notes: Helps you keep track of attuned items
## Author: Imevul
## Version: 1.0.7-Release
## Version: 1.0.8-Release
## SavedVariables: AttuneHelperDB
## OptionalDeps: Ace3, LinkWrangler, SynastriaCoreLib
## X-Category: Imevul
Expand Down
Loading

0 comments on commit 7173832

Please sign in to comment.