public
Description: WoW Addon - Adds notes to item tooltips
Homepage: http://www.tekkub.net
Clone URL: git://github.com/tekkub/engravings.git
Click here to lend your support to: engravings and make a donation at www.pledgie.com !
tekkub (author)
Sun Oct 11 18:55:17 -0700 2009
commit  36406aa0c401314beb27df6765c03e38216af80d
tree    e60490be101528752ea2d566b916534015020c82
parent  52bf5146551e24c6bdfd0e5e07d2435309dfb2b8 parent  03d1f75464881d0f6dbe7c9475641e8b20000a03
engravings / Engravings.lua
100644 139 lines (124 sloc) 3.879 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
Engravings = {}
local sources = Engravings
local origs = {}
local R, G, B = 1, 136/255, 0
local db, dbpc, sortedtitles
 
local function initdb()
EngravingsDB2, EngravingsDBPC = EngravingsDB2 or {}, EngravingsDBPC or {}
for title in pairs(sources) do if title:match("^Wowhead score") and EngravingsDB2[title] then EngravingsDBPC[title], EngravingsDB2[title] = EngravingsDB2[title], nil end end
return EngravingsDB2, EngravingsDBPC
end
Engravings.initdb = initdb
 
local function OnTooltipSetItem(frame, ...)
if not db then db, dbpc = initdb() end
if not sortedtitles then
sortedtitles = {}
for title,data in pairs(sources) do table.insert(sortedtitles, title) end
table.sort(sortedtitles, function(a,b) return string.lower(a) < string.lower(b) end)
end
 
local name, link = frame:GetItem()
if link then
local id = tonumber(link:match("item:(%d+):"))
for i,title in pairs(sortedtitles) do
local data = sources[title]
if not (db[title] or dbpc[title]) and data[id] then frame:AddDoubleLine(type(title) == "string" and title or "", data[id], R, G, B, R, G, B) end
end
end
if origs[frame] then return origs[frame](frame, ...) end
end
 
 
for _,frame in pairs{GameTooltip, ItemRefTooltip, ShoppingTooltip1, ShoppingTooltip2} do
origs[frame] = frame:GetScript("OnTooltipSetItem")
frame:SetScript("OnTooltipSetItem", OnTooltipSetItem)
end
 
 
---------------------------------
-- Wowhead generator --
---------------------------------
 
local slotids = {
INVTYPE_HEAD = 1,
INVTYPE_NECK = 2,
INVTYPE_SHOULDER = 3,
INVTYPE_BODY = 4,
INVTYPE_CHEST = 5,
INVTYPE_ROBE = 5,
INVTYPE_WAIST = 6,
INVTYPE_LEGS = 7,
INVTYPE_FEET = 8,
INVTYPE_WRIST = 9,
INVTYPE_HAND = 10,
INVTYPE_FINGER = 11,
INVTYPE_TRINKET = 13,
INVTYPE_CLOAK = 15,
INVTYPE_WEAPON = 17,
INVTYPE_SHIELD = 17,
INVTYPE_2HWEAPON = 16,
INVTYPE_WEAPONMAINHAND = 16,
INVTYPE_WEAPONOFFHAND = 17,
INVTYPE_HOLDABLE = 17,
INVTYPE_RANGED = 18,
INVTYPE_THROWN = 18,
INVTYPE_RANGEDRIGHT = 18,
INVTYPE_RELIC = 18,
}
local slots = setmetatable({}, {__index = function(t,i)
local _, _, _, _, _, _, _, _, slotname = GetItemInfo(i)
local slotid = slotids[slotname]
t[i] = slotid
return slotid
end})
local temp = {}
local setitems = setmetatable({}, {__index = function(t,i)
local v = {}
t[i] = v
return v
end})
local itemsets = {}
ENGRAVINGS_ITEMSETS = itemsets
 
local f = CreateFrame("Frame")
f:SetScript("OnEvent", function()
wipe(setitems)
wipe(itemsets)
local temp2 = {}
for i=1,GetNumEquipmentSets() do
local setname, tex = GetEquipmentSetInfo(i)
GetEquipmentSetItemIDs(setname, temp2)
for i,id in pairs(temp2) do
table.insert(setitems[i], id)
itemsets[id] = (itemsets[id] and (itemsets[id]..", ") or "").."|T"..tex..":18|t"..setname
end
end
end)
f:RegisterEvent("EQUIPMENT_SETS_CHANGED")
if IsLoggedIn() then f:GetScript("OnEvent")() else f:RegisterEvent("PLAYER_LOGIN") end
 
function EngravingsGenerateWowheadSet(spec, data)
local values = setmetatable({}, {
__index = function(t,i)
local v = data:match("\n"..i.." ([^\n]+)\n")
if v then t[i] = v; return v
else t[i] = 0; return 0 end
end
})
 
local lastid, lastbest
Engravings["Wowhead score ("..spec.."):"] = setmetatable({}, {
__index = function(t,i)
local v = values[i]
if not v or v == 0 then t[i] = false; return end
 
if lastid ~= i then
local slotid = slots[i]
local items = slotid and GetInventoryItemsForSlot(slotid, wipe(temp))
local best = true
if slotid then
for _,id in pairs(setitems[slotid]) do
if id ~= i and tonumber(values[id]) > tonumber(v) then best = false end
end
end
if best and items then
for _,id in pairs(items) do
if id ~= i and tonumber(values[id]) > tonumber(v) then best = false end
end
end
lastid, lastbest = i, best
end
 
return (lastbest and "|cff80ff80" or "")..v
end
})
end