WoWInterface SVN idExperience

Compare Revisions

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

Rev 1 → Rev 2

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
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
 
Addon.lua New file
0,0 → 1,83
--[[----------------------------------------------------------------------------
Copyright (c) 2007, Tom Wieland
All rights reserved.
 
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
 
* Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
* Neither the name of idExperience nor the names of its contributors may be
used to endorse or promote products derived from this software without
specific prior written permission.
 
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
------------------------------------------------------------------------------]]
 
local lib = LibStub('idLibrary-1.1')
 
local TL, TC, TR = 'TOPLEFT', 'TOP', 'TOPRIGHT'
local ML, MC, MR = 'LEFT', 'CENTER', 'RIGHT'
local BL, BC, BR = 'BOTTOMLEFT', 'BOTTOM', 'BOTTOMRIGHT'
 
local ExperienceLeft
local ExperienceGain
local RepetitionsNeeded
local ExperienceRested
 
local function getExperienceLeft()
return UnitXPMax('player') - UnitXP('player')
end
 
local function print()
local rested = GetXPExhaustion()
if rested then
UIErrorsFrame:AddMessage(('%s / %s = %s (%s %s%%)'):format(ExperienceLeft, ExperienceGain, RepetitionsNeeded, rested, math.floor(rested*100/ExperienceLeft)))
else
UIErrorsFrame:AddMessage(ExperienceLeft..' / '..ExperienceGain..' = '..RepetitionsNeeded)
end
end
 
local function PLAYER_XP_UPGRADE ()
ExperienceGain = ExperienceLeft - getExperienceLeft()
ExperienceLeft = getExperienceLeft()
RepetitionsNeeded = math.ceil(ExperienceLeft / ExperienceGain)
print()
end
 
local function PLAYER_LEVEL_UP ()
ExperienceLeft = getExperienceLeft()
ExperienceGain = 0
RepetitionsNeeded = 0
end
 
local function initialize(name)
if name ~= 'idExperience' then return end
ExperienceLeft = getExperienceLeft()
ExperienceGain = 0
RepetitionsNeeded = 0
end
 
local function enable()
SlashCmdList['ZEXPERIENCE_PRINTXP'] = print
SLASH_ZEXPERIENCE_PRINTXP1 = '/xp'
end
 
 
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)
idExperience.toc New file
0,0 → 1,9
## Interface: 20300
## Title: Industrial: Experience
## Credits: Industrial
## Notes: Experience and kills left display
 
Libraries\LibStub.lua
Libraries\idLibrary-1.1.lua
 
Addon.lua