-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathApi.lua
More file actions
454 lines (395 loc) · 11.7 KB
/
Api.lua
File metadata and controls
454 lines (395 loc) · 11.7 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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
-- Api.lua
-- @Author : Dencer (tdaddon@163.com)
-- @Link : https://dengsir.github.io
-- @Date : 2/9/2020, 1:02:09 PM
--
---@class ns
local ns = select(2, ...)
local ripairs = ipairs_reverse
ns.BUILD = tonumber(GetBuildInfo():match('^(%d+)%.'))
ns.LEFT_MOUSE_BUTTON = [[|TInterface\TutorialFrame\UI-Tutorial-Frame:12:12:0:0:512:512:10:65:228:283|t]]
ns.RIGHT_MOUSE_BUTTON = [[|TInterface\TutorialFrame\UI-Tutorial-Frame:12:12:0:0:512:512:10:65:330:385|t]]
ns.MAX_LEVEL = MAX_PLAYER_LEVEL_TABLE[LE_EXPANSION_LEVEL_CURRENT]
ns.DROPDOWN_SEPARATOR = {
text = '',
hasArrow = false,
dist = 0,
isTitle = true,
isUninteractable = true,
notCheckable = true,
iconOnly = true,
icon = [[Interface\Common\UI-TooltipDivider-Transparent]],
tCoordLeft = 0,
tCoordRight = 1,
tCoordTop = 0,
tCoordBottom = 1,
tSizeX = 0,
tSizeY = 8,
tFitDropDownSizeX = true,
iconInfo = {
tCoordLeft = 0,
tCoordRight = 1,
tCoordTop = 0,
tCoordBottom = 1,
tSizeX = 0,
tSizeY = 8,
tFitDropDownSizeX = true,
},
}
ns.NUM_GLYPH_SLOTS = NUM_GLYPH_SLOTS or ns.BUILD >= 5 and 9 or ns.BUILD >= 3 and 6 or 0
local tonumber = tonumber
local format = string.format
local UnitFullName = UnitFullName
local function memorize(func)
return setmetatable({}, {
__index = function(t, k)
if not k then
return
end
local v = func(k)
t[k] = v
return v
end,
__call = function(t, key)
return t[key]
end,
})
end
ns.memorize = memorize
function ns.strcolor(str, r, g, b)
return format('|cff%02x%02x%02x%s|r', r * 255, g * 255, b * 255, str)
end
function ns.ItemLinkToId(link)
return link and (tonumber(link) or tonumber(link:match('item:(%d+)')))
end
ns.GetClassFileName = memorize(function(classId)
if not classId then
return
end
local classInfo = C_CreatureInfo.GetClassInfo(classId)
return classInfo and classInfo.classFile
end)
ns.GetClassLocale = memorize(function(classId)
if not classId then
return
end
local classInfo = C_CreatureInfo.GetClassInfo(classId)
return classInfo and classInfo.className
end)
ns.GetRaceFileName = memorize(function(raceId)
if not raceId then
return
end
local raceInfo = C_CreatureInfo.GetRaceInfo(raceId)
return raceInfo and raceInfo.clientFileString
end)
ns.GetRaceLocale = memorize(function(raceId)
if not raceId then
return
end
local raceInfo = C_CreatureInfo.GetRaceInfo(raceId)
return raceInfo and raceInfo.raceName
end)
local function NormalizedRealmName(realm)
return realm:gsub('[%s-]+', '')
end
function ns.GetNormalizedRealmName()
local realm = GetNormalizedRealmName()
if not realm or realm == '' then
realm = NormalizedRealmName(GetRealmName())
end
return realm
end
function ns.GetFullName(name, realm)
if not name then
return
end
if name:find('-', nil, true) then
return name
end
if not realm or realm == '' then
realm = ns.GetNormalizedRealmName()
end
return name .. '-' .. realm
end
---@return string
function ns.UnitName(unit)
return ns.GetFullName(UnitFullName(unit))
end
local IsOurRealm = ns.memorize(function(realm)
local realms = GetAutoCompleteRealms()
for _, v in ipairs(realms) do
if v == realm then
return true
end
end
return realm == ns.GetNormalizedRealmName()
end)
function ns.IsPlayerInOurRealm(name)
return IsOurRealm(select(2, strsplit('-', name, 2)))
end
function ns.FixInspectItemTooltip(tip, slot, item)
local id = ns.ItemLinkToId(item)
if not id then
return
end
tip = LibStub('LibTooltipExtra-1.0'):New(tip)
ns.FixItemSets(tip, id)
if ns.BUILD == 1 then
ns.FixRune(tip, slot, id)
end
if ns.BUILD >= 2 then
ns.FixMetaGem(tip, item)
end
tip:Show()
end
local function FillGem(out, ...)
for i = 1, select('#', ...) do
local itemId = tonumber((select(i, ...)))
if itemId then
tinsert(out, itemId)
end
end
return out
end
local cache = {}
function ns.GetItemGems(link, out)
return FillGem(out or wipe(cache), link:match('item:%d+:?[-%d]*:?(%d*):?(%d*):?(%d*):?(%d*)'))
end
function ns.GetItemGem(link, index)
return tonumber(select(index, link:match('item:%d+:?[-%d]*:?(%d*):?(%d*):?(%d*):?(%d*)')) or nil)
end
function ns.GetGlyphIdBySpellId(spellId)
local d = ns.SpellGlyphes[spellId]
return d and d.glyphId
end
function ns.GetGlyphIcon(glyphId)
local d = ns.Glyphes[glyphId]
return d and d.icon
end
function ns.GetGlyphInfo(glyphId)
local d = ns.Glyphes[glyphId]
if not d then
return
end
return nil, d.spellId, d.icon
end
function ns.ResolveTalent(class, data)
local talent = ns.Talent:New(class, data)
return talent:ToString()
end
local function FlagTest(value, flag)
return bit.band(value, bit.lshift(1, flag)) > 0
end
function ns.GetItemEnchantInfo(link)
if not link then
return
end
local enchantId = tonumber(link:match('item:%d+:(%d*)'))
if enchantId then
local itemId, _, _, _, _, classId, subClassId = GetItemInfoInstant(link)
local invType = C_Item.GetItemInventoryTypeByID(itemId)
local data = ns.ItemEnchants[enchantId]
if not data then
return
end
for _, v in ripairs(data) do
if v.classId == classId and (not v.subClassMask or FlagTest(v.subClassMask, subClassId)) and
(not v.invTypeMask or FlagTest(v.invTypeMask, invType)) then
return v
end
end
end
end
local GLYPH_SLOTS = {
[1] = {id = 21, level = 15},
[2] = {id = 22, level = 15},
[3] = {id = 23, level = 50},
[4] = {id = 24, level = 30},
[5] = {id = 25, level = 70},
[6] = {id = 26, level = 80},
}
function ns.GetGlyphSlotRequireLevel(slot)
local d = GLYPH_SLOTS[slot]
return d and d.level
end
function ns.GetGlyphSlotId(slot)
local d = GLYPH_SLOTS[slot]
return d and d.id
end
local CAN_ENCHANT_EQUIP_LOCS = {
INVTYPE_HEAD = true,
INVTYPE_SHOULDER = true,
INVTYPE_BODY = true,
INVTYPE_CHEST = true,
INVTYPE_LEGS = true,
INVTYPE_FEET = true,
INVTYPE_WRIST = true,
INVTYPE_HAND = true,
INVTYPE_WEAPON = true,
INVTYPE_SHIELD = true,
INVTYPE_RANGED = true,
INVTYPE_CLOAK = true,
INVTYPE_2HWEAPON = true,
INVTYPE_ROBE = true,
INVTYPE_WEAPONMAINHAND = true,
INVTYPE_WEAPONOFFHAND = true,
}
local CAN_ENCHANT_RANGED = {
[Enum.ItemWeaponSubclass.Bows] = true,
[Enum.ItemWeaponSubclass.Guns] = true,
[Enum.ItemWeaponSubclass.Crossbow] = true,
}
function ns.IsSpellKnown(spellId)
return IsSpellKnown(spellId) or IsSpellKnownOrOverridesKnown(spellId) or IsPlayerSpell(spellId) or
DoesSpellExist(GetSpellInfo(spellId))
end
if ns.BUILD >= 5 then
ns.GetNumTalentGroups = function(isInspect)
return GetNumSpecGroups(isInspect or false)
end
ns.GetActiveTalentGroup = function(isInspect)
return C_SpecializationInfo.GetActiveSpecGroup(isInspect or false)
end
else
ns.GetNumTalentGroups = function(isInspect)
return GetNumTalentGroups and GetNumTalentGroups(isInspect) or 1
end
ns.GetActiveTalentGroup = function(isInspect)
return GetActiveTalentGroup and GetActiveTalentGroup(isInspect) or 1
end
end
function ns.IsCanEnchant(item, inspect)
local itemEquipLoc, _, classId, subClassId = select(4, GetItemInfoInstant(item))
if itemEquipLoc == 'INVTYPE_RANGEDRIGHT' or itemEquipLoc == 'INVTYPE_RANGED' then
if classId ~= Enum.ItemClass.Weapon or not CAN_ENCHANT_RANGED[subClassId] then
return false
end
if ns.db.profile.showRangedEnchantOnlyHunter then
local class
if inspect then
class = ns.Inspect:GetUnitClassFileName()
else
class = UnitClassBase('player')
end
return class == 'HUNTER'
end
return true
elseif itemEquipLoc == 'INVTYPE_FINGER' then
return not inspect and ns.IsSpellKnown(7411) -- 附魔
end
return CAN_ENCHANT_EQUIP_LOCS[itemEquipLoc]
end
if ns.BUILD >= 2 then
function ns.IsCanSocket(item, inspect)
local itemEquipLoc = select(4, GetItemInfoInstant(item))
if itemEquipLoc == 'INVTYPE_WAIST' then
elseif itemEquipLoc == 'INVTYPE_WRIST' or itemEquipLoc == 'INVTYPE_HAND' then
if inspect or not ns.IsSpellKnown(2018) then -- 锻造
return false
end
else
return false
end
local numSockets = ns.GetNumItemSockets(item)
return not ns.GetItemGem(item, numSockets + 1)
end
else
function ns.IsCanSocket()
return false
end
end
function ns.GetNumItemSockets(item)
local itemId = ns.ItemLinkToId(item)
local data = ns.ItemGemOrder[itemId]
return data and #data or 0
end
function ns.GetItemSocket(item, index)
local itemId = ns.ItemLinkToId(item)
local data = ns.ItemGemOrder[itemId]
if data then
return data[index]
end
end
function ns.GetSocketColor(socketType)
if socketType == 2 then -- 红孔
return 1, 0.2, 0.2
elseif socketType == 4 then -- 蓝孔
return 0.2, 0.8, 0.8
elseif socketType == 3 then -- 黄孔
return 0.8, 0.8, 0
elseif socketType == 1 then -- 多彩
return 1, 1, 1
else
return 0.7, 0.7, 0.7
end
end
ns.GetTalentTabInfo = function(...)
local id, name, description, icon, pointsSpent, background, previewPointsSpent, isUnlocked = GetTalentTabInfo(...)
return name, icon, pointsSpent, background
end
do
local menu
function ns.CallMenu(anchor, menuList)
if not menu then
menu = CreateFrame('Frame', 'tdInspectDropdown', UIParent, 'UIDropDownMenuTemplate')
end
menu.displayMode = 'MENU'
menu.initialize = EasyMenu_Initialize
menu.relativeTo = anchor
CloseDropDownMenus()
ToggleDropDownMenu(1, nil, menu, anchor, 0, 0, menuList)
end
function ns.CloseMenu(anchor)
if not menu then
return
end
if not DropDownList1:IsShown() then
return
end
if menu ~= UIDROPDOWNMENU_OPEN_MENU then
return
end
if menu.relativeTo == anchor then
CloseDropDownMenus()
return true
end
end
end
function ns.CopyDefaults(dest, src)
dest = dest or {}
for k, v in pairs(src) do
if type(v) == 'table' then
dest[k] = ns.CopyDefaults(dest[k], v)
elseif dest[k] == nil then
dest[k] = v
end
end
return dest
end
function ns.ShowBlizzardInventoryItem(unit, id)
if not unit then
return
end
local link = GetInventoryItemLink(unit, id)
if not link then
return
end
local ok = GameTooltip:SetInventoryItem(unit, id)
if not ok then
return
end
ns.FixInspectItemTooltip(GameTooltip, id, link)
return true
end
local CUSTOM_ITEM_QUALITY_COLORS = {}
CUSTOM_ITEM_QUALITY_COLORS[0] = {r = 0.72, g = 0.72, b = 0.72}
CUSTOM_ITEM_QUALITY_COLORS[1] = {r = 1.0, g = 1.0, b = 1.0}
CUSTOM_ITEM_QUALITY_COLORS[2] = {r = 0.3, g = 1.0, b = 0.38}
CUSTOM_ITEM_QUALITY_COLORS[3] = {r = 0.4, g = 0.71, b = 1.0}
CUSTOM_ITEM_QUALITY_COLORS[4] = {r = 0.97, g = 0.63, b = 0.83}
CUSTOM_ITEM_QUALITY_COLORS[5] = {r = 1, g = 0.602, b = 0.2}
CUSTOM_ITEM_QUALITY_COLORS[6] = {r = 0.94, g = 0.87, b = 0.67}
CUSTOM_ITEM_QUALITY_COLORS[7] = {r = 0.2, g = 0.84, b = 1.0}
CUSTOM_ITEM_QUALITY_COLORS[8] = {r = 0.2, g = 0.84, b = 1.0}
ns.CUSTOM_ITEM_QUALITY_COLORS = CUSTOM_ITEM_QUALITY_COLORS