1
0
Fork 0

Change database format substantially.

This commit is contained in:
Andrew Tomaka 2011-09-01 03:16:53 -04:00
parent b2d276948b
commit 6e1c9641aa

View file

@ -11,97 +11,54 @@ local trackedInstances = {
} }
local defaults = { local defaults = {
global = { global = {}
classes = {},
valorPoints = {},
lockouts = {},
}
} }
local classColors = {} local classColors = {}
local flagColors = {} local flagColors = {}
local function anchor_OnEnter(self)
self.db = LibStub('AceDB-3.0'):New('ChoreTrackerDB', defaults, 'Default')
local columnCount = 2
for instance,abbreviation in pairs(trackedInstances) do
columnCount = columnCount + 1
end
self.tooltip = LibQTip:Acquire('ChoreTrackerTooltip', columnCount, 'LEFT', 'CENTER', 'RIGHT')
--create the tooltip header
self.tooltip:AddHeader('')
local valorPointColumn = self.tooltip:AddColumn('LEFT')
self.tooltip:SetCell(1, 1, '')
self.tooltip:SetCell(1, 2, 'VP')
local nextColumn = 3
for instance,abbreviation in pairs(trackedInstances) do
self.tooltip:SetCell(1, nextColumn, abbreviation, nil, 'LEFT')
nextColumn = nextColumn + 1
end
--go through all stored raiders
for character,instancesTable in pairs(self.db.global.lockouts) do
local characterLine = self.tooltip:AddLine('')
local class = self.db.global.classes[character]
self.tooltip:SetCell(characterLine, 1, character, classColors[class], 'LEFT')
local valorPointColor,valorPoints
if self.db.global.valorPoints[character] == nil then
valorPoints = 0
else
valorPoints = self.db.global.valorPoints[character].points
end
if valorPoints == 980 then
valorPointColor = flagColors['red']
else
valorPointColor = flagColors['green']
end
self.tooltip:SetCell(characterLine, 2, valorPoints, valorPointColor, 'LEFT')
local nextColumn = 3
for instance,abbreviation in pairs(trackedInstances) do
if self.db.global.lockouts[character][instance] ~= nil then
self.tooltip:SetCell(characterLine, nextColumn, self.db.global.lockouts[character][instance].defeatedBosses, flagColors['red'], 'LEFT')
else
self.tooltip:SetCell(characterLine, nextColumn, '0', flagColors['green'], 'LEFT')
end
nextColumn = nextColumn + 1
end
end
self.tooltip:SmartAnchorTo(self)
self.tooltip:Show()
end
local function anchor_OnLeave(self)
LibQTip:Release(self.tooltip)
self.tooltip = nil
end
function core:OnInitialize() function core:OnInitialize()
--prepare the database if necessary
self.db = LibStub('AceDB-3.0'):New('ChoreTrackerDB', defaults, 'Default') self.db = LibStub('AceDB-3.0'):New('ChoreTrackerDB', defaults, 'Default')
local ChoresDisplay = CreateFrame('Frame', 'ChoreTrackerFrame', UIParent) local level = UnitLevel('player')
ChoresDisplay:SetPoint('TOPLEFT') local realm = GetRealmName()
ChoresDisplay.background = ChoresDisplay:CreateTexture(nil, 'BACKGROUND') local name = UnitName('player')
ChoresDisplay.background:SetAllPoints(true) if self.db.global[realm] == nil then
ChoresDisplay.background:SetTexture(1, 0.5, 0, 0.5) self.db.global[realm] = {}
ChoresDisplay:SetHeight(50) end
ChoresDisplay:SetWidth(50)
ChoresDisplay:Show()
ChoresDisplay:EnableMouse(true) if self.db.global[realm][name] == nil and level == 85 then
ChoresDisplay:SetMovable(true) self.db.global[realm][name] = {}
ChoresDisplay:RegisterForDrag('LeftButton')
local class = UnitClass('player')
class = class:lower()
if class == 'deathknight' then
class = 'death knight'
end
self.db.global[realm][name].class = class
self.db.global[realm][name].valorPoints = {
valorPoints = 0,
resetTime = 0,
}
self.db.global[realm][name].lockouts = {}
end
end
function core:OnEnable()
LibQTip = LibStub('LibQTip-1.0')
self:RegisterChatCommand('ct', 'ViewChores');
ChoresDisplay:SetScript('OnDragStart', ChoresDisplay.StartMoving) local level = UnitLevel('player')
ChoresDisplay:SetScript('OnDragStop', ChoresDisplay.StopMovingOrSizing) if level == 85 then
ChoresDisplay:SetScript('OnHide', ChoresDisplay.StopMovingOrSizing) self:RegisterEvent('UPDATE_INSTANCE_INFO', 'UpdateChores')
ChoresDisplay:SetScript('OnEnter', anchor_OnEnter) self:RegisterEvent('CALENDAR_UPDATE_EVENT_LIST', 'UpdateChores')
ChoresDisplay:SetScript('OnLeave', anchor_OnLeave) end
LoadAddOn("Blizzard_Calendar")
core:CreateChoreFrame()
for class,color in pairs(RAID_CLASS_COLORS) do for class,color in pairs(RAID_CLASS_COLORS) do
class = class:lower() class = class:lower()
@ -121,86 +78,73 @@ function core:OnInitialize()
flagColors['red'] = CreateFont('FlagFontRed') flagColors['red'] = CreateFont('FlagFontRed')
flagColors['red']:CopyFontObject(GameTooltipText) flagColors['red']:CopyFontObject(GameTooltipText)
flagColors['red']:SetTextColor(255, 0, 0) flagColors['red']:SetTextColor(255, 0, 0)
end
function core:OnEnable()
LibQTip = LibStub('LibQTip-1.0')
local name = UnitName('player')
if self.db.global.lockouts[name] == nil then
self.db.global.lockouts[name] = {}
end
if self.db.global.valorPoints[name] == nil then
self.db.global.valorPoints[name] = {}
end
self:RegisterChatCommand('ct', 'ViewChores'); --reset data if necessary
self:RegisterEvent('UPDATE_INSTANCE_INFO', 'UpdateChores') core:ResetInstances()
self:RegisterEvent('CALENDAR_UPDATE_EVENT_LIST', 'UpdateChores') core:ResetValorPoints()
LoadAddOn("Blizzard_Calendar")
end end
function core:ViewChores() function core:ViewChores()
end end
function core:UpdateChores() function core:UpdateChores()
local level = UnitLevel('player')
--reset data if necessary --reset data if necessary
core:ResetInstances() core:ResetInstances()
core:ResetValorPoints() core:ResetValorPoints()
if(level == 85) then
local _,_,_,earnedThisWeek = GetCurrencyInfo(396)
local name = UnitName('player')
--set class if not already set
local class = UnitClass('player')
self.db.global.classes[name] = class:lower()
local vpReset = core:GetNextVPReset()
--store Valor Points
if vpReset ~= nil then
self.db.global.valorPoints[name] = {}
self.db.global.valorPoints[name].points = earnedThisWeek
self.db.global.valorPoints[name].resetTime = vpReset
end
--store Saved Instances local _,_,_,earnedThisWeek = GetCurrencyInfo(396)
local savedInstances = GetNumSavedInstances() local realm = GetRealmName()
for i = 1, savedInstances do local name = UnitName('player')
local instanceName, _, instanceReset, _, _, _, _, _, _, _, _, defeatedBosses = GetSavedInstanceInfo(i)
local vpReset = core:GetNextVPReset()
if trackedInstances[instanceName] ~= nil then
if instanceReset > 0 then --store Valor Points
self.db.global.lockouts[name][instanceName] = {} if vpReset ~= nil then
self.db.global.lockouts[name][instanceName].defeatedBosses = defeatedBosses self.db.global[realm][name].valorPoints = {}
self.db.global.lockouts[name][instanceName].resetTime = time() + instanceReset self.db.global[realm][name].valorPoints.points = earnedThisWeek
else self.db.global[realm][name].valorPoints.resetTime = vpReset
self.db.global.lockouts[name][instanceName] = nil end
end
--store Saved Instances
local savedInstances = GetNumSavedInstances()
for i = 1, savedInstances do
local instanceName, _, instanceReset, _, _, _, _, _, _, _, _, defeatedBosses = GetSavedInstanceInfo(i)
if trackedInstances[instanceName] ~= nil then
if instanceReset > 0 then
self.db.global[realm][name].lockouts[instanceName] = {}
self.db.global[realm][name].lockouts[instanceName].defeatedBosses = defeatedBosses
self.db.global[realm][name].lockouts[instanceName].resetTime = time() + instanceReset
else
self.db.global[realm][name].lockouts[instanceName] = nil
end end
end end
end end
end end
function core:ResetInstances() function core:ResetInstances()
for k,v in pairs(self.db.global.lockouts) do for realm,realmTable in pairs(self.db.global) do
for x,y in pairs(self.db.global.lockouts[k]) do for name in pairs(realmTable) do
if y.resetTime < time() then for instance,instanceTable in pairs(self.db.global[realm][name].lockouts) do
self.db.global.lockouts[k][x] = nil if instanceTable.resetTime < time() then
self.db.global[realm][name].lockouts[instance] = nil
end
end end
end end
end end
end end
function core:ResetValorPoints() function core:ResetValorPoints()
for k,v in pairs(self.db.global.valorPoints) do for realm,realmTable in pairs(self.db.global) do
if v.resetTime ~= nil then for name in pairs(realmTable) do
if v.resetTime < time() then if self.db.global[realm][name].valorPoints.resetTime < time() then
self.db.global.valorPoints[k] = nil self.db.global[realm][name].valorPoints = {
valorPoints = 0,
resetTime = 0,
}
end end
end end
end end
@ -257,4 +201,82 @@ function core:GetNextVPReset()
else else
return nil return nil
end end
end
local function anchor_OnEnter(self)
self.db = LibStub('AceDB-3.0'):New('ChoreTrackerDB', defaults, 'Default')
local columnCount = 2
for instance,abbreviation in pairs(trackedInstances) do
columnCount = columnCount + 1
end
self.tooltip = LibQTip:Acquire('ChoreTrackerTooltip', columnCount, 'LEFT', 'CENTER', 'RIGHT')
--create the tooltip header
self.tooltip:AddHeader('')
local valorPointColumn = self.tooltip:AddColumn('LEFT')
self.tooltip:SetCell(1, 1, '')
self.tooltip:SetCell(1, 2, 'VP')
local nextColumn = 3
for instance,abbreviation in pairs(trackedInstances) do
self.tooltip:SetCell(1, nextColumn, abbreviation, nil, 'LEFT')
nextColumn = nextColumn + 1
end
for realm in pairs(self.db.global) do
for name in pairs(self.db.global[realm]) do
local characterLine = self.tooltip:AddLine('')
local class = self.db.global[realm][name].class
self.tooltip:SetCell(characterLine, 1, name, classColors[class], 'LEFT')
local valorPoints, valorPointColor
valorPoints = self.db.global[realm][name].valorPoints.points
if valorPoints == 980 then
valorPointColor = flagColors['red']
else
valorPointColor = flagColors['green']
end
self.tooltip:SetCell(characterLine, 2, valorPoints, valorPointColor, 'LEFT')
local nextColumn = 3
for instance,abbreviation in pairs(trackedInstances) do
if self.db.global[realm][name].lockouts[instance] ~= nil then
local defeatedBosses = self.db.global[realm][name].lockouts[instance].defeatedBosses
self.tooltip:SetCell(characterLine, nextColumn, defeatedBosses, flagColors['red'], 'LEFT')
else
self.tooltip:SetCell(characterLine, nextColumn, '0', flagColors['green'], 'LEFT')
end
nextColumn = nextColumn + 1
end
end
end
self.tooltip:SmartAnchorTo(self)
self.tooltip:Show()
end
local function anchor_OnLeave(self)
LibQTip:Release(self.tooltip)
self.tooltip = nil
end
function core:CreateChoreFrame()
local ChoresDisplay = CreateFrame('Frame', 'ChoreTrackerFrame', UIParent)
ChoresDisplay:SetPoint('TOPLEFT')
ChoresDisplay.background = ChoresDisplay:CreateTexture(nil, 'BACKGROUND')
ChoresDisplay.background:SetAllPoints(true)
ChoresDisplay.background:SetTexture(1, 0.5, 0, 0.5)
ChoresDisplay:SetHeight(50)
ChoresDisplay:SetWidth(50)
ChoresDisplay:Show()
ChoresDisplay:EnableMouse(true)
ChoresDisplay:SetMovable(true)
ChoresDisplay:RegisterForDrag('LeftButton')
ChoresDisplay:SetScript('OnDragStart', ChoresDisplay.StartMoving)
ChoresDisplay:SetScript('OnDragStop', ChoresDisplay.StopMovingOrSizing)
ChoresDisplay:SetScript('OnHide', ChoresDisplay.StopMovingOrSizing)
ChoresDisplay:SetScript('OnEnter', anchor_OnEnter)
ChoresDisplay:SetScript('OnLeave', anchor_OnLeave)
end end