-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSpellExport.lua
173 lines (152 loc) · 4.46 KB
/
SpellExport.lua
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
-- luacheck: globals SpellExportDB
local tinsert, tconcat, tsort = table.insert, table.concat, table.sort
local max = math.max
local GetSpellInfo, GetSpellDescription = GetSpellInfo, GetSpellDescription
local GetTime = GetTime
local NewTicker = C_Timer.NewTicker
local CTimerAfter = C_Timer.After
local spellData = {}
local tryAgainSpells = {}
local updateTicker, retryTimer = nil, nil
local eventFrame = CreateFrame("Frame")
local lastSpellUpdate = 0
local function p(...)
print("|cffffaa00SpellExport|r:", ...)
end
local function formatValue(v)
if not v then return "" end
if type(v) == "number" then return v end
return ("~~%s~~"):format(v)
end
local function clearSavedVariables()
SpellExportDB = nil
p("SavedVariables cleared.")
end
local function saveSpellData(id, isRetry)
if not DoesSpellExist(id) then
tryAgainSpells[id] = nil
return true
end
local name, rank, icon, castTime, minRange, maxRange, spellId = GetSpellInfo(id)
if not spellId then
tryAgainSpells[id] = nil
return true
end
local desc = GetSpellDescription(id)
if name ~= "" and (desc ~= "" or isRetry) then
tryAgainSpells[spellId] = nil
spellData[spellId] = {
formatValue(name),
formatValue(rank),
formatValue(icon),
formatValue(castTime),
formatValue(minRange),
formatValue(maxRange),
formatValue(desc),
}
return true
else
local count = (tryAgainSpells[spellId] or 0) + 1
if count >= 3 and isRetry then
print(("Giving up after %d"):format(count), " | name:", name, " | desc:", desc, " | spellId:", spellId, " | isRetry:", isRetry)
tryAgainSpells[spellId] = nil
else
tryAgainSpells[spellId] = count
end
end
end
local function retrySpellIds()
if GetTime()-lastSpellUpdate < 0.2 then
p("Still receiving spell name updates, please wait before retrying.")
return
end
local count = 0
for id,_ in pairs(tryAgainSpells) do
count = count + 1
if count < 1001 then
saveSpellData(id, true)
end
end
p(count >= 1000 and ("Retried 1000/%d spells"):format(count) or ("Retried %d spells"):format(count))
if count > 0 then
CTimerAfter(0.5, retrySpellIds)
else
PlaySound(73280, "MASTER") -- UI_ORDERHALL_TALENT_READY_TOAST
end
end
local requestSpellIds
local function checkForLastSpellUpdate()
if GetTime()-lastSpellUpdate > 0.15 then
p("|cff00ff00Requesting new spells")
requestSpellIds()
end
end
local lastId = 1
function requestSpellIds()
local failedCount = 0
p(("|cffffaa00Starting with spell id %d"):format(lastId))
for i=lastId,500000 do
if not saveSpellData(i) then
failedCount = failedCount + 1
if failedCount > 1000 then
if not updateTicker then
updateTicker = NewTicker(0.2, checkForLastSpellUpdate)
end
lastId = i
p(("|cffffff00Stopped requesting after %d fails at spell id %d"):format(1000, lastId))
break
end
end
if i == 500000 then
if updateTicker then
updateTicker:Cancel()
updateTicker = nil
end
p("Done")
PlaySound(73280, "MASTER") -- UI_ORDERHALL_TALENT_READY_TOAST
retrySpellIds()
end
end
end
local function exportSpellDataTable()
clearSavedVariables()
local tbl, idTbl, count, lastSpellId = {}, {}, 0, 0
for spellId, data in pairs(spellData) do
tinsert(idTbl, spellId)
count = count + 1
lastSpellId = max(lastSpellId, spellId)
end
tsort(idTbl)
for _, spellId in pairs(idTbl) do
tinsert(tbl, spellId..","..tconcat(spellData[spellId], ","))
end
SpellExportDB = tbl
local wowVersion, buildNr = GetBuildInfo()
local isPtr = IsTestBuild() and "PTR" or "live"
p(("Exported |cff00aaff%d|r spells, with |cff00aaff%d|r being the last spell id. Build info: |cff00aaff%s %d (%s)|r"):format(count, lastSpellId, wowVersion, buildNr, isPtr))
end
eventFrame:RegisterEvent("SPELL_TEXT_UPDATE")
local function eventHandler(self, event, eventId, eventName, ...)
if event == "SPELL_TEXT_UPDATE" then
lastSpellUpdate = GetTime()
saveSpellData(eventId)
end
end
eventFrame:SetScript("OnEvent", eventHandler)
local function slashCmdHandler(msg)
if msg == "request" then
requestSpellIds()
elseif msg == "retry" then
retrySpellIds()
elseif msg == "export" then
exportSpellDataTable()
elseif msg == "clear" then
clearSavedVariables()
else
p("Usage: /spellexport < request | retry | export | clear >")
end
end
SlashCmdList['SPELLEXPORT_SLASHCMD'] = slashCmdHandler
SLASH_SPELLEXPORT_SLASHCMD1 = '/spellexport'
SLASH_SPELLEXPORT_SLASHCMD2 = '/se'
-- grep "\"" SpellExport.lua | sed -e 's/^\s\"//g' | sed -e "s/\", -- \[.*$//g" | sed -e 's/\\"/""/g' | sed -e 's/~~/\"/g' > SpellData.csv