1
0
Fork 0

Validate user added instances before actually adding them.

This commit is contained in:
Andrew Tomaka 2011-09-22 06:37:57 -04:00
parent 7d360afb1c
commit 99b095a519
1 changed files with 47 additions and 1 deletions

View File

@ -15,6 +15,7 @@ local defaults = {
},
sortType = 1,
sortDirection = 1,
-- Change table? ['Baradin Hold'] = { abbreviation = 'BH', enable = true }
instances = {
[Z['Baradin Hold']] = 'BH',
[Z['Firelands']] = 'FL',
@ -77,7 +78,13 @@ local options = {
desc = 'Enter an instance on a seven day lockout that you would like ChoreTracker to track.',
type = 'input',
order = 1,
set = function(info, value) db.profile.instances[value] = '' end,
set = function(info, value)
if core:VerifyInstance(value) then
db.profile.instances[value] = ''
else
print('invalid instance')
end
end,
},
barHeader = {
name = 'Instances',
@ -366,6 +373,45 @@ function core:GetNextVPReset()
end
end
function core:VerifyInstance(instance)
-- User a method similar to GetNextVPReset() to make sure the instance
-- has a lockout on the calendar
local currentCalendarSetting = GetCVar('calendarShowResets')
SetCVar('calendarShowResets', 1)
local _, month, day, year = CalendarGetDate()
local monthOffset = 0
local resetDate = nil
while resetDate == nil do
local todaysEvents = CalendarGetNumDayEvents(monthOffset, day)
for i = 1,todaysEvents do
if todaysEvents == 0 then
break
end
local title,hour,minute = CalendarGetDayEvent(monthOffset, day, i)
if title == instance then
return true
end
end
day = day + 1
if day > 31 then
if monthOffset == 1 then break end
day = 1
monthOffset = 1
end
end
-- Reset the calendar to the original settings
SetCVar('calendarShowResets', currentCalendarSetting)
return false
end
function core:DrawTooltip()
-- UpdateChores before we show the tooltip to make sure we have the most recent data
core:UpdateChores()