WoWInterface SVN idExperience

Compare Revisions

  • This comparison shows the changes necessary to convert path
    /
    from Rev 3 to Rev 2
    Reverse comparison

Rev 3 → Rev 2

trunk/Libraries/LibStub.lua New file
0,0 → 1,30
-- LibStub is a simple versioning stub meant for use in Libraries. http://www.wowace.com/wiki/LibStub for more info
-- LibStub is hereby placed in the Public Domain Credits: Kaelten, Cladhaire, ckknight, Mikk, Ammo, Nevcairiel, joshborke
local LIBSTUB_MAJOR, LIBSTUB_MINOR = "LibStub", 2 -- NEVER MAKE THIS AN SVN REVISION! IT NEEDS TO BE USABLE IN ALL REPOS!
local LibStub = _G[LIBSTUB_MAJOR]
 
if not LibStub or LibStub.minor < LIBSTUB_MINOR then
LibStub = LibStub or {libs = {}, minors = {} }
_G[LIBSTUB_MAJOR] = LibStub
LibStub.minor = LIBSTUB_MINOR
 
function LibStub:NewLibrary(major, minor)
assert(type(major) == "string", "Bad argument #2 to `NewLibrary' (string expected)")
minor = assert(tonumber(strmatch(minor, "%d+")), "Minor version must either be a number or contain a number.")
 
local oldminor = self.minors[major]
if oldminor and oldminor >= minor then return nil end
self.minors[major], self.libs[major] = minor, self.libs[major] or {}
return self.libs[major], oldminor
end
 
function LibStub:GetLibrary(major, silent)
if not self.libs[major] and not silent then
error(("Cannot find a library instance of %q."):format(tostring(major)), 2)
end
return self.libs[major], self.minors[major]
end
 
function LibStub:IterateLibraries() return pairs(self.libs) end
setmetatable(LibStub, { __call = LibStub.GetLibrary })
end
trunk/Libraries/idLibrary-1.1.lua New file
0,0 → 1,81
local lib, oldminor = LibStub:NewLibrary('idLibrary-1.1', 1)
 
if not lib then return end
 
lib.events = {}
lib.timers = {}
lib.frame = CreateFrame('Frame')
 
lib.frame:SetScript('OnEvent', function (frame, event, ...)
local event = lib.events[event]
if event then
for k,v in pairs(event) do
v(...)
end
end
end)
lib.frame:SetScript('OnUpdate', function (frame, elapsed)
local v
for i = #lib.timers, 1, -1 do
v = lib.timers[i]
if v.time >= v.interval then
v.time = v.time - v.interval
v.func()
else
v.time = v.time + elapsed
end
end
end)
 
-- print
function lib:Print (mixed)
ChatFrame1:AddMessage(tostring(mixed) or 'nil')
end
 
-- events
function lib:RegisterEvent (name, event, func)
self.events[event] = self.events[event] or {}
self.events[event][name] = func
 
self.frame:RegisterEvent(event)
end
 
function lib:UnregisterEvent (name, event)
if self.events[event] then
self.events[event][name] = nil
if #self.events[event] == 0 then
self.events[event] = nil
self.frame:UnregisterEvent(event)
end
end
end
 
-- timers
function lib:RegisterTimer (name, func, interval)
self.timers[name] = {
interval = interval or 1,
time = 0,
func = func
}
end
 
function lib:UnregisterTimer (name)
self.timers[name] = nil
end
 
-- frames
function lib:Move (f, p1, p, p2, x, y)
f:ClearAllPoints()
f:SetPoint(p1, p, p2, x, y)
end
 
function lib:Show (f)
f:SetScript('OnShow', nil)
f:Show()
end
 
function lib:Hide (f)
f:SetScript('OnShow', f.Hide)
f:Hide()
end
 
trunk/Addon.lua
1,5 → 1,5
--[[----------------------------------------------------------------------------
Copyright (c) 2008, Tom Wieland
Copyright (c) 2007, Tom Wieland
All rights reserved.
 
Redistribution and use in source and binary forms, with or without
27,8 → 27,7
POSSIBILITY OF SUCH DAMAGE.
------------------------------------------------------------------------------]]
 
local _G = _G
local frame = CreateFrame('Frame')
local lib = LibStub('idLibrary-1.1')
 
local TL, TC, TR = 'TOPLEFT', 'TOP', 'TOPRIGHT'
local ML, MC, MR = 'LEFT', 'CENTER', 'RIGHT'
39,20 → 38,20
local RepetitionsNeeded
local ExperienceRested
 
local function getExperienceLeft ()
local function getExperienceLeft()
return UnitXPMax('player') - UnitXP('player')
end
 
local function print ()
local function print()
local rested = GetXPExhaustion()
if rested then
ChatFrame1:AddMessage(('%s / %s = %s (%s %s%%)'):format(ExperienceLeft, ExperienceGain, RepetitionsNeeded, rested, math.floor(rested*100/ExperienceLeft)))
UIErrorsFrame:AddMessage(('%s / %s = %s (%s %s%%)'):format(ExperienceLeft, ExperienceGain, RepetitionsNeeded, rested, math.floor(rested*100/ExperienceLeft)))
else
ChatFrame1:AddMessage(ExperienceLeft..' / '..ExperienceGain..' = '..RepetitionsNeeded)
UIErrorsFrame:AddMessage(ExperienceLeft..' / '..ExperienceGain..' = '..RepetitionsNeeded)
end
end
 
local function PLAYER_XP_UPDATE ()
local function PLAYER_XP_UPGRADE ()
ExperienceGain = ExperienceLeft - getExperienceLeft()
ExperienceLeft = getExperienceLeft()
RepetitionsNeeded = math.ceil(ExperienceLeft / ExperienceGain)
65,33 → 64,20
RepetitionsNeeded = 0
end
 
local function ADDON_LOADED (name)
local function initialize(name)
if name ~= 'idExperience' then return end
ExperienceLeft = getExperienceLeft()
ExperienceGain = 0
RepetitionsNeeded = 0
end
 
local function PLAYER_LOGIN ()
local function enable()
SlashCmdList['ZEXPERIENCE_PRINTXP'] = print
SLASH_ZEXPERIENCE_PRINTXP1 = '/xp'
end
 
local function OnEvent (frame, event, ...)
if event == 'ADDON_LOADED' then
ADDON_LOADED(...)
elseif event == 'PLAYER_LOGIN' then
PLAYER_LOGIN(...)
elseif event == 'PLAYER_XP_UPDATE' then
PLAYER_XP_UPDATE(...)
elseif event == 'PLAYER_LEVEL_UP' then
PLAYER_LEVEL_UP(...)
end
end
 
frame:SetScript('OnEvent', OnEvent)
frame:RegisterEvent('ADDON_LOADED')
frame:RegisterEvent('PLAYER_LOGIN')
frame:RegisterEvent('PLAYER_XP_UPDATE')
frame:RegisterEvent('PLAYER_LEVEL_UP')
 
lib:RegisterEvent('idExperience-Initialize', 'ADDON_LOADED', initialize)
lib:RegisterEvent('idExperience-Enable', 'PLAYER_LOGIN', enable)
lib:RegisterEvent('idExperience', 'PLAYER_XP_UPDATE', PLAYER_XP_UPDATE)
lib:RegisterEvent('idExperience', 'PLAYER_LEVEL_UP', PLAYER_LEVEL_UP)
trunk/idExperience.toc
1,4 → 1,9
## Interface: 20401
## Notes: Experience and kills left display
 
Addon.lua
## Interface: 20300
## Title: Industrial: Experience
## Credits: Industrial
## Notes: Experience and kills left display
 
Libraries\LibStub.lua
Libraries\idLibrary-1.1.lua
 
Addon.lua