-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathui.lua
More file actions
executable file
·518 lines (426 loc) · 22.1 KB
/
ui.lua
File metadata and controls
executable file
·518 lines (426 loc) · 22.1 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
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
-- SPDX-License-Identifier: PolyForm-Noncommercial-1.0.0
-- Copyright (c) 2022-2026 Thomas Floeren
local ADDON_NAME, ns = ...
-- API
local C_PetJournal_GetSummonedPetGUID = _G.C_PetJournal.GetSummonedPetGUID
local C_PetJournal_GetBattlePetLink = _G.C_PetJournal.GetBattlePetLink
local tostring = _G.tostring
local format = _G.format
local print = _G.print
local CHAR_NAME = UnitName 'player'
local MAX_NUM_RECENTS = 20
local function get_link_actpet()
local p = C_PetJournal_GetSummonedPetGUID()
p = p and C_PetJournal_GetBattlePetLink(p)
return p
end
local function get_link_savedpet()
local p = ns.dbc.charFavsEnabled and ns.dbc.recentPets[1] or ns.db.recentPets[1]
p = p and C_PetJournal_GetBattlePetLink(p)
return p
end
--[[===========================================================================
Colors
===========================================================================]]--
local colscheme_green = {
basetext = {
notification = '8FBC8F',
warning = 'FA8072',
},
element = {
addonname = '7CFC00',
quote = '808000',
emphasis = 'ADFF2F',
keyword = '00FA9A',
state = '32CD32',
command = 'FF00FF',
}
}
local function set_colors(scheme)
local prefix = '|r|cff'
local colorstrings = {
bn = prefix .. scheme.basetext.notification,
bw = prefix .. scheme.basetext.warning,
an = prefix .. scheme.element.addonname,
q = prefix .. scheme.element.quote,
e = prefix .. scheme.element.emphasis,
k = prefix .. (scheme.element.keyword or scheme.element.emphasis),
s = prefix .. (scheme.element.state or scheme.element.emphasis),
c = prefix .. (scheme.element.command or scheme.element.emphasis),
}
return colorstrings
end
local CO = set_colors(colscheme_green)
--[[===========================================================================
Messages
===========================================================================]]--
local BLOCK_SEP = strrep('+', 42)
local function chat_user_notification(msg)
print(CO.an .. ADDON_NAME .. ":", msg)
end
-- local function chat_user_notification_block(msg)
-- print('\n' .. CO.an .. BLOCK_SEP .. '\n' .. ADDON_NAME .. ':', msg, '\n' .. CO.an .. BLOCK_SEP , '\n ')
-- end
-- Login msg
function ns.msg_login()
if ns.db.verbosityLevel < 2 then return end
local sep = CO.bn .. ' | '
local petinfo
if ns.db.verbosityLevel > 2 then
local async = false
local ap, sp = get_link_actpet(), get_link_savedpet()
if not ap or not sp or ap ~= sp then async = true end
ap, sp = ap or 'None', sp or 'None'
petinfo = CO.k .. (async and 'Current Pet: ' or 'Pet: ') .. CO.s .. ap .. (async and sep .. CO.k .. 'Saved pet: ' .. CO.s .. sp or '')
end
chat_user_notification(table.concat({CO.k .. 'Auto: ' .. CO.s .. (ns.db.autoEnabled and 'On' or CO.bw .. 'Off'), CO.k .. 'Pet pool: ' .. CO.s .. (ns.db.favsOnly and ns.dbc.charFavsEnabled and 'Char favs' or ns.db.favsOnly and 'Global favs' or 'All pets'), CO.k .. 'Timer: ' .. CO.s .. (ns.db.newPetTimer > 0 and ns.db.newPetTimer/60 .. ' min' or 'Off'), petinfo}, sep))
end
-- TODO: Do we need a warning at 1 selectable pet? Or should this be considered a valid use-case? (User manually summons a pet from Journal, but wants to get back his (only) fav pet when the timer is due.)
-- function ns.msg_low_petpool(nPool)
-- chat_user_notification(CO.bw .. ": " .. (nPool < 1 and "0 (zero) pets" or "Only 1 pet") .. " eligible as random summon! You should either " .. (ns.db.favsOnly and "flag more pets as favorite, or set the random pool to 'All Pets'" or "collect more pets") .. ", or set the random-summon timer to '0'. Please note that certain pets are excluded from random summoning, to not break their usability (for example Guild Herald)." .. ((ns.dbc.charFavsEnabled and ns.db.favsOnly) and "\nNote that you have set this char to use char-specific favorite pets. Maybe switching to global favorites ('/pw c') will help." or ""))
-- end
function ns.msg_no_saved_pet()
if ns.db.verbosityLevel < 0 then return end
chat_user_notification(CO.bw .. 'Cannot restore pet because no Current Pet has been saved yet' .. (ns.dbc.charFavsEnabled and ' for ' .. CO.e .. CHAR_NAME or '') .. CO.bw .. '. This can happen when switching to char-specific favorites for the first time on a toon. - Summoned a random pet instead.')
end
function ns.msg_no_previous_pet()
if ns.db.verbosityLevel < 0 then return end
chat_user_notification(CO.bw .. 'No Previous Pet has been saved yet' .. (ns.dbc.charFavsEnabled and ' for ' .. CO.e .. CHAR_NAME or '') .. CO.bw .. '.')
end
function ns.msg_onlyfavisactive(ap)
if ns.db.verbosityLevel < 1 then return end
chat_user_notification(CO.bn .. 'Your only eligible random pet ' .. (ns.id_to_link(ap) or '???') .. ' is already active.')
end
function ns.msg_removed_invalid_id(counter)
if ns.db.verbosityLevel < 2 then return end
chat_user_notification(format('%s%s orphaned pet ID%s %s been removed from the char favorites.', CO.bn, counter, counter > 1 and 's' or '', counter > 1 and 'have' or 'has'))
end
function ns.msg_saved_pet_unsummonable(reason, number)
if ns.db.verbosityLevel < 1 then return end
chat_user_notification(format('%sThe saved Current Pet is not summonable. Reason: %s(%s) %s%s\n--> Checking other saved pets (char/global pet, previous pet, etc.) now.', CO.bw, CO.e, number or '?', reason or 'unknown', CO.bw))
end
function ns.msg_previous_pet_unsummonable()
if ns.db.verbosityLevel < 1 then return end
chat_user_notification(CO.bw .. 'The saved Previous Pet or other saved pets are not summonable either.\n--> Saving the currently active pet or summoning a new one.')
end
function ns.msg_manual_summon_stopped()
if ns.db.verbosityLevel < 1 then return end
chat_user_notification(CO.bw .. 'You are in combat lockdown or flying; pet summoning aborted.')
end
-- function ns.msg_recents_dupe_removed(idx)
-- if ns.db.verbosityLevel < 3 then return end
-- chat_user_notification(CO.bn .. 'Removed a duplicate from recent pets at idx ' .. idx .. '.')
-- end
-- Summon Target Pet messages
function ns.msg_target_summoned(link)
if ns.db.verbosityLevel < 1 then return end
chat_user_notification(format('%sTarget pet %s summoned.', CO.bn, link))
end
function ns.msg_target_is_same(link) -- Without web link
if ns.db.verbosityLevel < 1 then return end
chat_user_notification(format('%sTarget pet %s is the same pet as you currently have summened.', CO.bn, link))
end
-- function ns.msg_target_is_same(link, name) -- With web link
-- if ns.db.verbosityLevel < 1 then return end
-- chat_user_notification(format('%sTarget pet %s is the same pet as you currently have summened: \nhttps://www.warcraftpets.com/search?q=%s', CO.bn, link, name:gsub("[ ']", {[" "] = "%20", ["'"] = "%27"})))
-- end
function ns.msg_target_not_in_collection(link, name)
if ns.db.verbosityLevel < 1 then return end
chat_user_notification(format('%sUnfortunately, the target pet %s is not in your collection: \nhttps://www.warcraftpets.com/search?q=%s', CO.bn, link, name:gsub("[ ']", {[" "] = "%20", ["'"] = "%27"})))
end
function ns.msg_target_is_not_battlepet()
if ns.db.verbosityLevel < 1 then return end
chat_user_notification(format('%sThe target is not a battle pet!', CO.bn))
end
function ns.msg_target_is_not_companion_battlepet(name)
if ns.db.verbosityLevel < 1 then return end
chat_user_notification(format('%sTarget pet "%s" is a battle pet, but not a companion battle pet. (Not in your collection and unlikely to be collectible at all.): \nhttps://www.wowhead.com/search?q=%s', CO.bn, name, name:gsub("[ ']", {[" "] = "%20", ["'"] = "%27"})))
end
--[[---------------------------------------------------------------------------
The main, success, message when a pet was summoned. Either by restore_pet or
new_pet, or previous_pet or the transitioncheck.
---------------------------------------------------------------------------]]--
-- Called by the new_pet func
function ns.set_sum_msg_to_newpet(np, n)
ns.msg_pet_summoned_content = ns.db.verbosityLevel >= 2 and format('%sSummoned %s pet %s.', CO.bn, n > 1 and 'a new random' or 'your only eligible random', ns.id_to_link(np)) or nil
end
-- Called by the restore_pet func
function ns.set_sum_msg_to_restore_pet(pet)
ns.msg_pet_summoned_content = ns.db.verbosityLevel >= 3 and format('%sRestored your last pet %s.', CO.bn, ns.id_to_link(pet) or '???') or nil
end
-- Called by the previous_pet func
function ns.set_sum_msg_to_previouspet(pet)
ns.msg_pet_summoned_content = ns.db.verbosityLevel >= 2 and format('%sSummoned your previous pet %s.', CO.bn, ns.id_to_link(pet) or '???') or nil
end
-- Called by the transitioncheck func
function ns.set_sum_msg_to_transcheck(pet)
ns.msg_pet_summoned_content = ns.db.verbosityLevel >= 3 and format('%sSummoned your last saved pet %s.', CO.bn, ns.id_to_link(pet) or '???') or nil
end
-- Called by the summon func
function ns.msg_pet_summon_success()
if ns.msg_pet_summoned_content then
chat_user_notification(ns.msg_pet_summoned_content)
end
end
-- Called by the summon func
function ns.msg_pet_summon_failed()
if ns.db.verbosityLevel < 1 then return end
chat_user_notification(CO.bw .. "You don't meet the conditions for summoning a pet right now.")
end
--[[---------------------------------------------------------------------------
Three big messages: Status, Low Pet Pool, and Help
---------------------------------------------------------------------------]]--
function ns.help_display(print_bottomspace)
local header = {
CO.bn .. ' Help: ',
CO.c .. '\n/pw ', 'or ', CO.c .. '/petwalker ', 'supports these commands: ',
}
local body = {
{CO.c .. 'd', ' : ', CO.k .. 'Dismiss ', 'current pet and ', CO.k .. 'disable auto-summoning ', '(new pet / restore).'},
{CO.c .. 'a', ' : ', 'Toggle ', CO.k .. 'auto-summoning ', '(new pet / restore).'},
{CO.c .. 'sr', ' : ', 'Toggle ', CO.k .. 'auto-summoning ', 'also ', CO.k .. 'while mounted for Skyriding: ', CO.s .. 'allowed / not allowed', '.'},
{CO.c .. 'n', ' : ', 'Summon ', CO.k .. 'new pet ', 'from pool.'},
{CO.c .. 'f', ' : ', 'Toggle ', CO.k .. 'pet pool: ', CO.s .. 'Favorites Only', ', or ', CO.s .. 'All Pets', '.'},
{CO.c .. 'c', ' : ', 'Toggle ', CO.k .. 'favorites: ', CO.s .. 'Per-character', ', or ', CO.s .. 'Global Favorites', '.'},
{CO.c .. '<number>', ' : ', 'Set ', CO.k .. 'Summon Timer ', 'in minutes (', CO.c .. '1 ', 'to ', CO.c .. '1440', '; ', CO.c .. '0 ', 'to ', CO.k .. 'disable', ').'},
{CO.c .. 'p', ' : ', 'Cycle through ', CO.k .. 'Previous (recently summoned) Pets', '.'},
{CO.c .. 'p <number>', ' : ', 'Set ', CO.k .. 'number of recorded Previous Pets ', '(', CO.c .. '1 ', 'to ', CO.c .. MAX_NUM_RECENTS, ').'},
{CO.c .. 'v', ' : ', CO.k .. 'Verbosity: ', CO.s .. 'silent ', '(only failures and warnings are printed to chat); ', CO.c .. 'vv ', 'for ', CO.s .. 'medium ', CO.k .. 'verbosity ', '(new summons); ', CO.c .. 'vvv ', 'for ', CO.s .. 'full ', CO.k .. 'verbosity ', '(also restored pets).'},
{CO.c .. 's', ' : ', 'Display current ', CO.k .. 'status/settings.'},
{CO.c .. 'h', ' : ', 'This help text.'},
}
local footer = {
CO.bn .. '\nExamples: ', CO.c .. '/pw a', ' disables auto-summon/restore, or enables it if disabled. ', CO.c .. '/pw 20', ' sets the new-pet summon timer to 20 minutes.',
'\nIn Options > Keybindigs you can directly bind some commands.',
}
local header_text = table.concat(header, CO.bn)
local footer_text = table.concat(footer, CO.bn)
print('\n' .. CO.an .. BLOCK_SEP .. '\n' .. ADDON_NAME .. header_text .. '\n')
for _, v in ipairs(body) do
print(table.concat(v, CO.bn))
end
print(footer_text .. '\n' .. CO.an .. BLOCK_SEP .. (print_bottomspace and '\n ' or ''))
end
function ns.status_display(print_topsep, print_bottomsep)
if not ns.pool_initialized then ns.initialize_pool() end
local header = {
CO.bn .. ' [v', C_AddOns.GetAddOnMetadata(ADDON_NAME, 'Version'), '] Status & Settings:',
}
local body = {
{CO.k ..'Automatic Random-summoning / Restore ', 'is ', CO.s .. (ns.db.autoEnabled and 'enabled' or CO.bw .. 'disabled'), '.'},
{CO.k .. 'Summon Timer ', 'is ', CO.s .. (ns.db.newPetTimer > 0 and (ns.db.newPetTimer/60) .. CO.bn .. ' minutes' or 'disabled'), '. Next random pet in ', CO.e .. ns.remaining_timer_for_display(), '.'},
{CO.k ..'Automatic summoning while mounted for Skyriding ', 'is ', CO.s .. (ns.db.drSummoning and 'allowed' or 'not allowed'), '.'},
{CO.k .. 'History ', 'of Previous Pets: ', CO.s .. ns.db.numRecents - 1, ' (1 to ' .. MAX_NUM_RECENTS .. ').'},
{CO.k .. 'Verbosity ', 'level of messages: ', CO.s .. ns.db.verbosityLevel, ' (of 3).'},
{CO.k .. 'Pet Pool ', 'is set to ', CO.s .. (ns.db.favsOnly and 'Favorites Only' or 'All Pets'), '. Eligible pets: ', CO.e .. #ns.pet_pool, '.'},
{CO.k .. 'Per-character Favorites ', 'are ', CO.s .. (ns.dbc.charFavsEnabled and 'enabled' or 'disabled'), ' for ', CO.e .. CHAR_NAME, '.'},
}
-- Separating this bc it might be a longish list
local charfavlist = {
'\n', ns:list_charfavs(),
}
local header_text = table.concat(header, CO.bn)
local charfavlist_text = table.concat(charfavlist, CO.bn)
local extra_settings = (ns.db.eventAlt and table.concat({CO.k ..'\nAlternative Events ', 'are ', CO.s .. 'enabled ', 'for all chars.'}, CO.bn) or nil)
print((print_topsep and '\n' .. CO.an .. BLOCK_SEP .. '\n' or CO.an) .. ADDON_NAME .. header_text .. '\n')
for _, v in ipairs(body) do
print(table.concat(v, CO.bn))
end
if extra_settings then print(extra_settings) end
print(charfavlist_text)
if print_bottomsep then print(CO.an .. BLOCK_SEP .. '\n ') end
end
function ns.msg_low_petpool(nPool)
if ns.db.verbosityLevel < 0 then return end
local R = CO.bw
local content = {
(nPool < 1 and CO.k .. '0 (zero) ' ..R.. 'pets ' or R.. 'Only ' ..CO.k .. '1 ' ..R.. 'pet '),
'eligible as random summon!',
'\nYou should either ' .. (ns.db.favsOnly and 'flag more pets as favorite, or set the random pool to ' .. CO.s ..'All Pets' or 'collect more pets'), ', or set the random-summon timer to ', CO.s .. '0', '.',
'\nAlso check your ', CO.k .. 'Filter ', 'settings in the ', CO.k .. 'Blizz Pet Journal ', '(not in Rematch!), as they are affecting the pool of available pets!',
'\nSome pets are ', CO.k .. 'faction-restricted ', 'and cannot be summoned on the other faction, so they may not be eligible on your current toon.',
'\nPlease note that certain pets are intentionally ', CO.k .. 'excluded ', 'from random summoning, to not break their usability (for example ',
CO.q .. 'Guild Herald', '). ',
((ns.dbc.charFavsEnabled and ns.db.favsOnly) and '\nYou have set ' .. CO.e .. CHAR_NAME ..R.. ' to use ' .. CO.s .. 'char-specific favorite ' ..R.. 'pets. Maybe switching to ' .. CO.s .. 'global favorites ' ..R.. '(' .. CO.c .. '/pw c' ..R.. ') will help.' or ''),
}
local content = table.concat(content, R)
chat_user_notification(content)
end
--[[===========================================================================
Slash UI
===========================================================================]]--
SLASH_PetWalker1, SLASH_PetWalker2 = '/pw', '/petwalker'
function SlashCmdList.PetWalker(msg)
local args = {}
for arg in msg:gmatch('[^ ]+') do
tinsert(args, arg)
end
if args[1] == 'd' or args[1] == 'dis' then
ns:dismiss_and_disable()
elseif args[1] == 'dd' or args[1] == 'debd' then
ns:debug_display()
elseif args[1] == 'dm' or args[1] == 'debug' then
ns.debugmode_toggle()
elseif args[1] == 'vvv' then
ns.verbosity_full()
elseif args[1] == 'vv' then
ns.verbosity_medium()
elseif args[1] == 'v' then
ns.verbosity_silent()
elseif args[1] == 'v0' then
ns.verbosity_mute()
elseif args[1] == 'a' or args[1] == 'auto' then
ns:auto_toggle()
elseif args[1] == 'n' or args[1] == 'new' then
ns:new_pet(nil, true)
elseif args[1] == 'f' or args[1] == 'fav' then
ns:favs_toggle()
elseif args[1] == 'aev' or args[1] == 'altevents' then -- Probably better to leave this undocumented
ns:event_toggle()
elseif args[1] == 'c' or args[1] == 'char' then
ns.charfavs_slash_toggle()
elseif (args[1] == 'p' or args[1] == 'prev') and tonumber(args[2]) then
ns.set_num_recents(args[2])
elseif args[1] == 'p' or args[1] == 'prev' then
ns.previous_pet()
elseif args[1] == 's' or args[1] == 'status' then
ns.status_display(true, true)
elseif tonumber(args[1]) then
ns:timer_slash_cmd(args[1])
elseif args[1] == 'sr' then
ns.dr_summoning_toggle()
elseif args[1] == 't' or args[1] == 'target' then
ns.summon_targetpet()
elseif args[1] == 'h' or args[1] == 'help' then
ns.help_display(true)
elseif args[1] == nil then
ns.help_display(false)
ns.status_display(false, true)
else
chat_user_notification(format('%sInvalid command or arguments. Enter %s/pw help %sfor a list of commands.', CO.bw, CO.c, CO.bw))
end
end
--[[---------------------------------------------------------------------------
Toggles, Commands
---------------------------------------------------------------------------]]--
function ns:dismiss_and_disable()
local actpet = C_PetJournal_GetSummonedPetGUID()
if actpet then
C_PetJournal.SummonPetByGUID(actpet)
end
ns.db.autoEnabled = false
ns.events:unregister_pw_events()
chat_user_notification(format('%sPet dismissed and auto-summoning %s.', CO.bn, ns.db.autoEnabled and 'enabled' or 'disabled'))
end
function ns.verbosity_full()
ns.db.verbosityLevel = 3
chat_user_notification(CO.bn .. 'Verbosity: full (3).')
end
function ns.verbosity_medium()
ns.db.verbosityLevel = 2
chat_user_notification(CO.bn .. 'Verbosity: medium (2).')
end
function ns.verbosity_silent()
ns.db.verbosityLevel = 1
chat_user_notification(CO.bn .. 'Verbosity: silent (1).')
end
function ns.verbosity_mute()
ns.db.verbosityLevel = 0
chat_user_notification(CO.bn .. 'Verbosity: mute (0).')
end
function ns:auto_toggle()
if ns.db.autoEnabled then
ns.db.autoEnabled = false
ns.events:unregister_pw_events()
else
ns.db.autoEnabled = true
ns.events:register_pw_events()
ns.autoaction()
end
chat_user_notification(format('%sPet auto-summoning %s.', CO.bn, ns.db.autoEnabled and 'enabled' or 'disabled'))
end
function ns:event_toggle()
ns.db.eventAlt = not ns.db.eventAlt
if ns.db.autoEnabled then
ns.events:unregister_summon_events()
ns.events:register_summon_events()
end
chat_user_notification(format('%s%s %s.', CO.bn, ns.db.eventAlt and 'Alternative event(s)' or 'Default event (PLAYER_STARTED_MOVING)', ns.db.autoEnabled and 'registered' or 'selected. Note that auto-summoning is currently disabled; event(s) will be registered when you enable auto-summoning (' .. CO.c .. '/pw a' .. CO.bn .. ')'))
end
function ns:favs_toggle()
ns.db.favsOnly = not ns.db.favsOnly
ns.pool_initialized, ns.pet_verified = false, false
if ns.db.autoEnabled then ns:new_pet() end
chat_user_notification(format('%sPet pool: %s%s.', CO.bn, ns.db.favsOnly and 'favorites' or 'all pets', ns.db.favsOnly and ns.dbc.charFavsEnabled and ' (char-specific)' or ns.db.favsOnly and ' (global)' or ''))
end
function ns.charfavs_slash_toggle() -- for slash command only
ns.dbc.charFavsEnabled = not ns.dbc.charFavsEnabled
ns.pool_initialized, ns.pet_verified = false, false
--[[ Since we are changing from one saved-pet table to another, we prefer to
restore the pet from the new list, rather than doing new_pet like in the favs_toggle. ]]
if ns.db.autoEnabled then
ns.transitioncheck()
else -- Needed for a correct display of char/normal favs in the PJ
ns:cfavs_update()
end
if PetWalkerCharFavsCheckbox then PetWalkerCharFavsCheckbox:SetChecked(ns.dbc.charFavsEnabled) end
chat_user_notification(format('%sCharacter-specific favorites %s for %s%s.', CO.bn, ns.dbc.charFavsEnabled and 'enabled' or 'disabled', CO.e, CHAR_NAME))
end
function ns.dr_summoning_toggle()
ns.db.drSummoning = not ns.db.drSummoning
chat_user_notification(format('%sSummoning while mounted for Skyriding %s.', CO.bn, ns.db.drSummoning and 'enabled' or 'disabled'))
end
function ns.debugmode_toggle() -- for slash command only
ns.db.debugMode = not ns.db.debugMode
chat_user_notification(format('%sDebug mode %s.', CO.bn, ns.db.debugMode and 'enabled' or 'disabled'))
end
local function is_acceptable_timervalue(v)
return (v >= 1 and v <= 1440 or v == 0)
end
function ns:timer_slash_cmd(value)
value = tonumber(value)
if is_acceptable_timervalue(value) or ns.db.debugMode then
ns.db.newPetTimer = value * 60
chat_user_notification(format('%s%s.',CO.bn, ns.db.newPetTimer == 0 and 'Summon timer disabled' or 'Summoning a new pet every ' .. ns.db.newPetTimer/60 .. ' minutes'))
else
chat_user_notification(format('%sNot a valid timer value. Enter a number from %s1%1$s to %2$s1440%1$s for a timer in minutes, or %2$s0%1$s (zero) to %3$sdisable%1$s the timer. \nExamples: %2$s/pw 20%1$s will summon a new pet every 20 minutes, %2$s/pw 0%1$s disables the timer. Note that there is a space between "/pw" and the number.', CO.bw, CO.c, CO.k))
end
end
function ns.set_num_recents(num)
num = max(min(floor(num), MAX_NUM_RECENTS), 1)
ns.db.numRecents = num + 1 -- "current" is idx 1
for _, v in ipairs({ ns.db.recentPets, ns.dbc.recentPets }) do
while #v > ns.db.numRecents do
table.remove(v)
end
end
chat_user_notification(
format('%sPrevious Pets history set to %s.', CO.bn, ns.db.numRecents - 1)
)
end
-- Used for info print
function ns:list_charfavs()
local favlinks, count, name = {}, 0, nil
for id, _ in pairs(ns.dbc.charFavs) do
count = count + 1
name = C_PetJournal_GetBattlePetLink(id)
table.insert(favlinks, name)
end
local favlinks_text = table.concat(favlinks, ' ')
return CO.e .. CHAR_NAME .. CO.bn .. ' has ' .. CO.e .. count .. CO.bn ..
' character-specific favorite pet' .. (count > 1 and 's:\n' or count > 0 and ':\n' or 's.') .. favlinks_text
end
--[[---------------------------------------------------------------------------
For the bindings.xml
---------------------------------------------------------------------------]]--
-- BINDING_HEADER_PETWALKER = "PetWalker "
BINDING_NAME_PETWALKER_TOGGLE_AUTO = 'Toggle Auto-Summoning'
BINDING_NAME_PETWALKER_NEW_PET = 'Summon New Pet'
BINDING_NAME_PETWALKER_PREVIOUS_PET = 'Summon Previous Pet(s)'
BINDING_NAME_PETWALKER_TARGET_PET = 'Summon Same Pet as Target'
BINDING_NAME_PETWALKER_DISMISS_PET = 'Dismiss Pet & Disable Auto-Summoning'
function PetWalker_binding_toggle_autosummon() ns:auto_toggle() end
function PetWalker_binding_new_pet() ns:new_pet(nil, true) end
function PetWalker_binding_previous_pet() ns.previous_pet() end
function PetWalker_binding_target_pet() ns:summon_targetpet() end
function PetWalker_binding_dismiss_and_disable() ns:dismiss_and_disable() end