WoWInterface SVN idExperience

Compare Revisions

  • This comparison shows the changes necessary to convert path
    /
    from Rev 8 to Rev 9
    Reverse comparison

Rev 8 → Rev 9

trunk/Addon.lua
29,69 → 29,44
 
local _G = _G
 
local TL, TC, TR = 'TOPLEFT', 'TOP', 'TOPRIGHT'
local ML, MC, MR = 'LEFT', 'CENTER', 'RIGHT'
local BL, BC, BR = 'BOTTOMLEFT', 'BOTTOM', 'BOTTOMRIGHT'
 
local eventframe = CreateFrame('Frame')
local outputframe = _G.ChatFrame1
local eventframe = CreateFrame('Frame')
 
local ExperienceLeft
local ExperienceGain
local RepetitionsNeeded
local ExperienceRested
local old = UnitXP('player')
local out = ''
 
local getExperienceLeft
local Print
local PLAYER_XP_UPDATE
local PLAYER_LEVEL_UP
local OnEvent
local update
local onevent
local print
 
function getExperienceLeft ()
return UnitXPMax('player') - UnitXP('player')
end
 
function Print ()
function update ()
local xp, max = UnitXP('player'), UnitXPMax('player')
local gained = xp - old
local rested = GetXPExhaustion()
if rested then
outputframe:AddMessage(('%s / %s = %s (%s %s%%)'):format(ExperienceLeft, ExperienceGain, RepetitionsNeeded, rested, math.floor(rested*100/ExperienceLeft)))
old = xp
if rested and rested > 0 then
rested = ' ('..math.ceil(GetXPExhaustion()/(UnitXPMax('player') - UnitXP('player'))*100)..'% rested)'
else
outputframe:AddMessage(ExperienceLeft..' / '..ExperienceGain..' = '..RepetitionsNeeded)
rested = ''
end
out = ('%s / %s = %s%s'):format(max - xp, gained, math.ceil((max - xp) / gained), rested)
print()
end
 
function PLAYER_XP_UPDATE ()
ExperienceGain = ExperienceLeft - getExperienceLeft()
ExperienceLeft = getExperienceLeft()
RepetitionsNeeded = math.ceil(ExperienceLeft / ExperienceGain)
Print()
end
 
function PLAYER_LEVEL_UP ()
ExperienceLeft = getExperienceLeft()
ExperienceGain = 0
RepetitionsNeeded = 0
end
 
function OnEvent (frame, event, ...)
ChatFrame1:AddMessage('DEBUG: '..event)
function onevent (frame, event, ...)
if event == 'PLAYER_XP_UPDATE' then
PLAYER_XP_UPDATE()
elseif event == 'PLAYER_LEVEL_UP' then
PLAYER_LEVEL_UP()
update()
end
end
 
ExperienceLeft = getExperienceLeft()
ExperienceGain = 0
RepetitionsNeeded = 0
function print ()
outputframe:AddMessage(out)
end
 
SlashCmdList['IDEXPERIENCE_PRINTXP'] = Print
SLASH_IDEXPERIENCE_PRINTXP1 = '/xp'
 
eventframe:SetScript('OnEvent', OnEvent)
eventframe:SetScript('OnEvent', onevent)
eventframe:RegisterEvent('PLAYER_XP_UPDATE')
eventframe:RegisterEvent('PLAYER_LEVEL_UP')
 
_G.idExperience = addon
SlashCmdList['IDEXPERIENCE_PRINTXP'] = print
SLASH_IDEXPERIENCE_PRINTXP1 = '/xp'