vanilla-wow-addons – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | office | 1 | -- FishingBuddy |
2 | -- |
||
3 | -- Everything you wanted support for in your fishing endeavors |
||
4 | |||
5 | local gotSetupDone = false; |
||
6 | local playerName; |
||
7 | local realmName; |
||
8 | |||
9 | local DEFAULT_MINIMAP_POSITION = 256; |
||
10 | |||
11 | FishingBuddy.IsLoaded = function() |
||
12 | return gotSetupDone; |
||
13 | end |
||
14 | |||
15 | -- if the old information is still there, then we might not have per |
||
16 | -- character saved info, so let's save it away just in case. It'll go |
||
17 | -- away the second time we load the add-on |
||
18 | FishingBuddy.SavePlayerInfo = function() |
||
19 | if ( FishingBuddy_Info[realmName] and |
||
20 | FishingBuddy_Info[realmName]["Settings"] and |
||
21 | FishingBuddy_Info[realmName]["Settings"][playerName] ) then |
||
22 | local tabs = { "Settings", "Outfit", "WasWearing" }; |
||
23 | for _,tab in tabs do |
||
24 | for k,v in FishingBuddy_Player[tab] do |
||
25 | FishingBuddy_Info[realmName][tab][playerName][k] = v; |
||
26 | end |
||
27 | end |
||
28 | end |
||
29 | end |
||
30 | |||
31 | local Setup = {}; |
||
32 | Setup.CheckPlayerInfo = function() |
||
33 | local tabs = { "Settings", "Outfit", "WasWearing" }; |
||
34 | if ( not FishingBuddy_Player ) then |
||
35 | FishingBuddy_Player = {}; |
||
36 | for _,tab in tabs do |
||
37 | FishingBuddy_Player[tab] = { }; |
||
38 | end |
||
39 | if ( FishingBuddy_Info[realmName] and |
||
40 | FishingBuddy_Info[realmName]["Settings"] and |
||
41 | FishingBuddy_Info[realmName]["Settings"][playerName] ) then |
||
42 | for _,tab in tabs do |
||
43 | if ( FishingBuddy_Info[realmName][tab] and |
||
44 | FishingBuddy_Info[realmName][tab][playerName] ) then |
||
45 | for k,v in FishingBuddy_Info[realmName][tab][playerName] do |
||
46 | FishingBuddy_Player[tab][k] = v; |
||
47 | end |
||
48 | end |
||
49 | end |
||
50 | end |
||
51 | elseif ( FishingBuddy_Info[realmName] and |
||
52 | FishingBuddy_Info[realmName]["Settings"] ) then |
||
53 | -- the saved information is there, kill the old stuff |
||
54 | for _,tab in tabs do |
||
55 | if ( FishingBuddy_Info[realmName][tab] ) then |
||
56 | FishingBuddy_Info[realmName][tab][playerName] = nil; |
||
57 | -- Duh, table.getn doesn't work because there |
||
58 | -- aren't any integer keys in this table |
||
59 | if ( next(FishingBuddy_Info[realmName][tab]) == nil ) then |
||
60 | FishingBuddy_Info[realmName][tab] = nil; |
||
61 | end |
||
62 | end |
||
63 | end |
||
64 | if ( next(FishingBuddy_Info[realmName]) == nil ) then |
||
65 | FishingBuddy_Info[realmName] = nil; |
||
66 | end |
||
67 | end |
||
68 | end |
||
69 | |||
70 | Setup.CheckPlayerSetting = function(setting, defaultvalue) |
||
71 | if ( not FishingBuddy_Player["Settings"] ) then |
||
72 | FishingBuddy_Player["Settings"] = { }; |
||
73 | end |
||
74 | if ( not FishingBuddy_Player["Settings"][setting] ) then |
||
75 | FishingBuddy_Player["Settings"][setting] = defaultvalue; |
||
76 | end |
||
77 | end |
||
78 | |||
79 | Setup.CheckGlobalSetting = function(setting, defaultvalue) |
||
80 | if ( not FishingBuddy_Info[setting] ) then |
||
81 | if ( not defaultvalue ) then |
||
82 | FishingBuddy_Info[setting] = {}; |
||
83 | else |
||
84 | FishingBuddy_Info[setting] = defaultvalue; |
||
85 | end |
||
86 | end |
||
87 | end |
||
88 | |||
89 | Setup.CheckRealm = function() |
||
90 | local tabs = { "Settings", "Outfit", "WasWearing" }; |
||
91 | for _,tab in tabs do |
||
92 | if ( FishingBuddy_Info[tab] ) then |
||
93 | local old = FishingBuddy_Info[tab][playerName]; |
||
94 | if ( old ) then |
||
95 | if ( not FishingBuddy_Info[realmName] ) then |
||
96 | FishingBuddy_Info[realmName] = { }; |
||
97 | for _,tab in tabs do |
||
98 | FishingBuddy_Info[realmName][tab] = { }; |
||
99 | end |
||
100 | end |
||
101 | |||
102 | FishingBuddy_Info[realmName][tab][playerName] = { }; |
||
103 | for k, v in old do |
||
104 | FishingBuddy_Info[realmName][tab][playerName][k] = v; |
||
105 | end |
||
106 | FishingBuddy_Info[tab][playerName] = nil; |
||
107 | end |
||
108 | |||
109 | -- clean out cruft, if we have some |
||
110 | FishingBuddy_Info[tab][UNKNOWNOBJECT] = nil; |
||
111 | FishingBuddy_Info[tab][UKNOWNBEING] = nil; |
||
112 | |||
113 | -- Duh, table.getn doesn't work because there |
||
114 | -- aren't any integer keys in this table |
||
115 | if ( next(FishingBuddy_Info[tab]) == nil ) then |
||
116 | FishingBuddy_Info[tab] = nil; |
||
117 | end |
||
118 | end |
||
119 | end |
||
120 | end |
||
121 | |||
122 | Setup.UpdateFishingDB1 = function() |
||
123 | local version = FishingBuddy_Info["Version"]; |
||
124 | if ( not version ) then |
||
125 | version = 7700; -- be really old |
||
126 | end |
||
127 | |||
128 | if ( FishingBuddy_Info["FishingHoles"] ) then |
||
129 | if ( version < 8300 ) then |
||
130 | -- handle a beta bug where we missed that GetSubZoneText() returns "" and not nil |
||
131 | for zone in FishingBuddy_Info["FishingHoles"] do |
||
132 | if ( FishingBuddy_Info["FishingHoles"][zone][""] ) then |
||
133 | if ( not FishingBuddy_Info["FishingHoles"][zone][zone] ) then |
||
134 | FishingBuddy_Info["FishingHoles"][zone][zone] = { }; |
||
135 | end |
||
136 | for k,v in FishingBuddy_Info["FishingHoles"][zone][""] do |
||
137 | FishingBuddy_Info["FishingHoles"][zone][zone][k] = v; |
||
138 | end |
||
139 | FishingBuddy_Info["FishingHoles"][zone][""] = nil; |
||
140 | end |
||
141 | end |
||
142 | end |
||
143 | |||
144 | if ( version < 8503 ) then |
||
145 | local fh = FishingBuddy_Info["FishingHoles"]; |
||
146 | local ff = FishingBuddy_Info["Fishies"]; |
||
147 | for zone in fh do |
||
148 | for subzone in fh[zone] do |
||
149 | local crap = {}; |
||
150 | for fishie in fh[zone][subzone] do |
||
151 | if ( type(fishie) == "string" ) then |
||
152 | tinsert(crap, fishie); |
||
153 | end |
||
154 | end |
||
155 | for _,fishie in crap do |
||
156 | if ( ff[fishie] ) then |
||
157 | local item = ff[fishie].item; |
||
158 | if ( item ) then |
||
159 | local _,_,id = string.find(item, "^(%d+):"); |
||
160 | id = id + 0; |
||
161 | fh[zone][subzone][id] = fh[zone][subzone][fishie]; |
||
162 | fh[zone][subzone][fishie] = nil; |
||
163 | end |
||
164 | end |
||
165 | end |
||
166 | end |
||
167 | end |
||
168 | local fishes = {}; |
||
169 | for fishie in ff do |
||
170 | if ( type(fishie) == "string" ) then |
||
171 | tinsert(fishes, fishie); |
||
172 | end |
||
173 | end |
||
174 | for _,fishie in fishes do |
||
175 | local item = ff[fishie].item; |
||
176 | if ( item ) then |
||
177 | local _,_,id = string.find(item, "^(%d+):"); |
||
178 | id = id + 0; |
||
179 | ff[id] = {}; |
||
180 | ff[id].name = fishie; |
||
181 | for k,v in ff[fishie] do |
||
182 | if ( k ~= "item" ) then |
||
183 | ff[id][k] = v; |
||
184 | end |
||
185 | end |
||
186 | ff[fishie] = nil; |
||
187 | end |
||
188 | end |
||
189 | -- tracking information |
||
190 | local ft = FishingBuddy_Info["FishTracking"]; |
||
191 | for how in ft do |
||
192 | local fishes = {}; |
||
193 | for item in ft[how] do |
||
194 | if ( type(item) == "string" ) then |
||
195 | tinsert(fishes, item); |
||
196 | end |
||
197 | end |
||
198 | for _,item in fishes do |
||
199 | local _,_,id = string.find(item, "^(%d+):"); |
||
200 | id = tonumber(id); |
||
201 | ft[how][id] = {}; |
||
202 | for k,v in ft[how][item] do |
||
203 | ft[how][id][k] = v; |
||
204 | end |
||
205 | if ( ft[how][id].count ) then |
||
206 | ft[how][id].data = {}; |
||
207 | for k,v in ft[how][id].count do |
||
208 | ft[how][id].data[k] = v; |
||
209 | end |
||
210 | ft[how][id].count = nil; |
||
211 | end |
||
212 | end |
||
213 | for _,item in fishes do |
||
214 | ft[how][item] = nil; |
||
215 | end |
||
216 | end |
||
217 | end |
||
218 | end |
||
219 | |||
220 | if ( version < 8504 ) then |
||
221 | -- Let's not store default colors for things |
||
222 | local ff = FishingBuddy_Info["Fishies"]; |
||
223 | if ( ff ) then |
||
224 | for id in ff do |
||
225 | if ( ff[id].color and ff[id].color == "ffffffff" ) then |
||
226 | ff[id].color = nil; |
||
227 | end |
||
228 | end |
||
229 | end |
||
230 | end |
||
231 | |||
232 | if ( version < 8509 and FishingBuddy_Info["FishTracking"] ) then |
||
233 | local ft = FishingBuddy_Info["FishTracking"]["WEEKLY"]; |
||
234 | for id,what in ft do |
||
235 | if ( not ft[id].data[52] ) then |
||
236 | ft[id].data[52] = 0; |
||
237 | table.setn(ft[id].data, 53); |
||
238 | end |
||
239 | end |
||
240 | end |
||
241 | |||
242 | if ( not FishingBuddy_Info["Locations"] ) then |
||
243 | return; |
||
244 | end |
||
245 | |||
246 | -- Duh, table.getn doesn't work because there aren't any integer |
||
247 | -- keys in this table |
||
248 | if ( next(FishingBuddy_Info["Locations"]) == nil ) then |
||
249 | FishingBuddy_Info["Locations"] = nil; |
||
250 | return; |
||
251 | end |
||
252 | |||
253 | FishingBuddy_Info["FishingHoles"] = { }; |
||
254 | FishingBuddy_Info["FishingHoles"][FishingBuddy.UNKNOWN] = { }; |
||
255 | for zone in FishingBuddy_Info["Locations"] do |
||
256 | FishingBuddy_Info["FishingHoles"][FishingBuddy.UNKNOWN][zone] = { }; |
||
257 | local tab = FishingBuddy_Info["FishingHoles"][FishingBuddy.UNKNOWN][zone]; |
||
258 | for k,v in FishingBuddy_Info["Locations"][zone] do |
||
259 | tab[k] = v; |
||
260 | end |
||
261 | end |
||
262 | FishingBuddy_Info["Locations"] = nil; |
||
263 | end |
||
264 | |||
265 | Setup.UpdateFishingDB2 = function() |
||
266 | local version = FishingBuddy_Info["Version"]; |
||
267 | if ( not version ) then |
||
268 | version = 7700; -- be really old |
||
269 | end |
||
270 | |||
271 | -- track the weekly fish that got missed at the end of the year |
||
272 | if ( version < 8509 ) then |
||
273 | local ft = FishingBuddy_Info["FishTracking"]["WEEKLY"]; |
||
274 | for id,what in ft do |
||
275 | if ( FishingBuddy.ByFishie[id] ) then |
||
276 | local total = 0; |
||
277 | for subzone,count in FishingBuddy.ByFishie[id] do |
||
278 | total = total + count; |
||
279 | end |
||
280 | local tracked = 0; |
||
281 | local limit = table.getn(what.data)-1; |
||
282 | for i=0,limit do |
||
283 | tracked = tracked + what.data[i]; |
||
284 | end |
||
285 | local diff = total - tracked; |
||
286 | if ( diff > 0 ) then |
||
287 | ft[id].data[52] = ft[id].data[52] + diff; |
||
288 | end |
||
289 | end |
||
290 | end |
||
291 | end |
||
292 | |||
293 | FishingBuddy_Info["Version"] = FishingBuddy.CURRENTVERSION; |
||
294 | end |
||
295 | |||
296 | -- Based on code in QuickMountEquip |
||
297 | Setup.HookFunction = function(func, newfunc) |
||
298 | local oldValue = getglobal(func); |
||
299 | if ( oldValue ~= getglobal(newfunc) ) then |
||
300 | setglobal(func, getglobal(newfunc)); |
||
301 | return true; |
||
302 | end |
||
303 | return false; |
||
304 | end |
||
305 | |||
306 | -- set up alternate view of fish data. do this as startup to |
||
307 | -- lower overall dynamic hit when loading the window |
||
308 | Setup.SetupByFishie = function() |
||
309 | if ( not FishingBuddy.ByFishie ) then |
||
310 | local fh = FishingBuddy_Info["FishingHoles"]; |
||
311 | local ff = FishingBuddy_Info["Fishies"]; |
||
312 | FishingBuddy.ByFishie = { }; |
||
313 | FishingBuddy.SortedFishies = { }; |
||
314 | for zone in fh do |
||
315 | for subzone in fh[zone] do |
||
316 | for id in fh[zone][subzone] do |
||
317 | local quantity = fh[zone][subzone][id]; |
||
318 | if ( not FishingBuddy.ByFishie[id] ) then |
||
319 | FishingBuddy.ByFishie[id] = { }; |
||
320 | tinsert(FishingBuddy.SortedFishies, |
||
321 | { text = ff[id].name, id = id }); |
||
322 | end |
||
323 | if ( not FishingBuddy.ByFishie[id][subzone] ) then |
||
324 | FishingBuddy.ByFishie[id][subzone] = quantity; |
||
325 | else |
||
326 | FishingBuddy.ByFishie[id][subzone] = FishingBuddy.ByFishie[id][subzone] + quantity; |
||
327 | end |
||
328 | end |
||
329 | end |
||
330 | end |
||
331 | FishingBuddy.FishSort(FishingBuddy.SortedFishies, true); |
||
332 | end |
||
333 | end |
||
334 | |||
335 | Setup.InitSortHelpers = function() |
||
336 | local fh = FishingBuddy_Info["FishingHoles"]; |
||
337 | FishingBuddy.SortedZones = {}; |
||
338 | FishingBuddy.SortedByZone = {}; |
||
339 | FishingBuddy.SortedSubZones = {}; |
||
340 | for zone in fh do |
||
341 | tinsert(FishingBuddy.SortedZones, zone); |
||
342 | FishingBuddy.SortedByZone[zone] = {}; |
||
343 | for subzone in fh[zone] do |
||
344 | tinsert(FishingBuddy.SortedByZone[zone], subzone); |
||
345 | tinsert(FishingBuddy.SortedSubZones, subzone); |
||
346 | end |
||
347 | table.sort(FishingBuddy.SortedByZone[zone]); |
||
348 | end |
||
349 | table.sort(FishingBuddy.SortedZones); |
||
350 | table.sort(FishingBuddy.SortedSubZones); |
||
351 | end |
||
352 | |||
353 | Setup.EnhanceSoundDefaults = function() |
||
354 | Setup.CheckPlayerSetting("EnhanceSoundSoundVolume", 1.0); |
||
355 | Setup.CheckPlayerSetting("EnhanceSoundMusicVolume", 0.0); |
||
356 | Setup.CheckPlayerSetting("EnhanceSoundAmbienceVolume", 0.0); |
||
357 | end |
||
358 | |||
359 | Setup.InitSettings = function() |
||
360 | if( not FishingBuddy_Info ) then |
||
361 | FishingBuddy_Info = { }; |
||
362 | end |
||
363 | -- global stuff |
||
364 | Setup.UpdateFishingDB1(); |
||
365 | Setup.CheckRealm(); |
||
366 | |||
367 | Setup.CheckGlobalSetting("ImppDBLoaded", 0); |
||
368 | Setup.CheckGlobalSetting("FishInfo2", 0); |
||
369 | Setup.CheckGlobalSetting("DataFish", 0); |
||
370 | Setup.CheckGlobalSetting("FishingHoles"); |
||
371 | Setup.CheckGlobalSetting("FishingSkill"); |
||
372 | Setup.CheckGlobalSetting("Fishies"); |
||
373 | |||
374 | Setup.CheckPlayerInfo(); |
||
375 | |||
376 | -- per user stuff |
||
377 | for _,option in FishingBuddy.OPTIONS do |
||
378 | local setting = option.default; |
||
379 | if ( option.check and option.checkfail ) then |
||
380 | if ( not option.check() ) then |
||
381 | setting = option.checkfail; |
||
382 | end |
||
383 | end |
||
384 | Setup.CheckPlayerSetting(option.name, setting); |
||
385 | end |
||
386 | |||
387 | -- setting not on option pane (or not checkboxes) |
||
388 | Setup.CheckPlayerSetting("ShowLocationZones", 1); |
||
389 | Setup.CheckPlayerSetting("GroupByLocation", 1); |
||
390 | |||
391 | -- titan panel support |
||
392 | Setup.CheckPlayerSetting("TitanClickToSwitch", 1); |
||
393 | -- InfoBar support |
||
394 | Setup.CheckPlayerSetting("InfoBarClickToSwitch", 1); |
||
395 | -- minimap button support |
||
396 | Setup.CheckPlayerSetting("MinimapClickToSwitch", 1); |
||
397 | Setup.CheckPlayerSetting("MinimapButtonPosition", DEFAULT_MINIMAP_POSITION); |
||
398 | |||
399 | -- Option key casting |
||
400 | Setup.CheckPlayerSetting("EasyCastKeys", FishingBuddy.KEYS_NONE); |
||
401 | Setup.CheckPlayerSetting("SuitUpKeys", FishingBuddy.KEYS_NONE); |
||
402 | |||
403 | Setup.EnhanceSoundDefaults(); |
||
404 | |||
405 | if ( FishingBuddy.InitTracking ) then |
||
406 | FishingBuddy.InitTracking(); |
||
407 | end |
||
408 | Setup.SetupByFishie(); |
||
409 | Setup.UpdateFishingDB2(); |
||
410 | Setup.InitSortHelpers(); |
||
411 | end |
||
412 | |||
413 | Setup.RegisterMyAddOn = function() |
||
414 | -- Register the addon in myAddOns |
||
415 | if (myAddOnsFrame_Register) then |
||
416 | local details = { |
||
417 | name = FishingBuddy.ID, |
||
418 | description = FishingBuddy.DESCRIPTION, |
||
419 | version = FishingBuddy.VERSION, |
||
420 | releaseDate = 'July 21, 2005', |
||
421 | author = 'Sutorix', |
||
422 | email = 'Windrunner', |
||
423 | category = MYADDONS_CATEGORY_PROFESSIONS, |
||
424 | frame = "FishingBuddy", |
||
425 | optionsframe = "FishingBuddyFrame", |
||
426 | }; |
||
427 | local help = ""; |
||
428 | for _,line in FishingBuddy.HELPMSG do |
||
429 | if ( type(line) == "table" ) then |
||
430 | for _,l in line do |
||
431 | help = help.."\n"..l; |
||
432 | end |
||
433 | else |
||
434 | help = help.."\n"..line; |
||
435 | end |
||
436 | end |
||
437 | myAddOnsFrame_Register(details, { help }); |
||
438 | end |
||
439 | end |
||
440 | |||
441 | Setup.RegisterHandlers = function() |
||
442 | temp = ToggleMinimap; |
||
443 | if ( Setup.HookFunction("ToggleMinimap", "FishingBuddy_ToggleMinimap") ) then |
||
444 | FishingBuddy.SavedToggleMinimap = temp; |
||
445 | end |
||
446 | FishingBuddy.TrapWorldMouse() |
||
447 | end |
||
448 | |||
449 | FishingBuddy.Initialize = function() |
||
450 | -- Set everything up, then dump the code we don't need anymore |
||
451 | playerName, realmName = FishingBuddy.SetupNameInfo(); |
||
452 | if ( Setup ) then |
||
453 | if ( GetBuildInfo ) then |
||
454 | local version, buildnum, builddate = GetBuildInfo(); |
||
455 | else |
||
456 | FishingBuddy.Is10900 = true; |
||
457 | end |
||
458 | Setup.RegisterHandlers(); |
||
459 | Setup.InitSettings(); |
||
460 | -- register with myAddOn |
||
461 | Setup.RegisterMyAddOn(); |
||
462 | |||
463 | gotSetupDone = true; |
||
464 | FishingBuddy.WatchUpdate(); |
||
465 | -- we don't need these functions anymore, gc 'em |
||
466 | Setup = nil; |
||
467 | end |
||
468 | end |