revert code style changes in libs

This commit is contained in:
Pinya
2018-07-22 21:19:43 +03:00
parent 0bdcbbca6c
commit 5a9c2e9ade
3 changed files with 76 additions and 56 deletions
+26 -5
View File
@@ -1,15 +1,24 @@
-- LibStub is a simple versioning stub meant for use in Libraries. http://www.wowace.com/wiki/LibStub for more info -- $Id: LibStub.lua 103 2014-10-16 03:02:50Z mikk $
-- LibStub is hereby placed in the Public Domain Credits: Kaelten, Cladhaire, ckknight, Mikk, Ammo, Nevcairiel, joshborke -- LibStub is a simple versioning stub meant for use in Libraries. http://www.wowace.com/addons/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_MAJOR, LIBSTUB_MINOR = "LibStub", 2 -- NEVER MAKE THIS AN SVN REVISION! IT NEEDS TO BE USABLE IN ALL REPOS!
local _G = _G
local find, format = string.find, string.format
local LibStub = _G[LIBSTUB_MAJOR] local LibStub = _G[LIBSTUB_MAJOR]
local find, format = string.find, string.format
-- Check to see is this version of the stub is obsolete
if not LibStub or LibStub.minor < LIBSTUB_MINOR then if not LibStub or LibStub.minor < LIBSTUB_MINOR then
LibStub = LibStub or {libs = {}, minors = {} } LibStub = LibStub or {libs = {}, minors = {} }
_G[LIBSTUB_MAJOR] = LibStub _G[LIBSTUB_MAJOR] = LibStub
LibStub.minor = LIBSTUB_MINOR LibStub.minor = LIBSTUB_MINOR
-- LibStub:NewLibrary(major, minor)
-- major (string) - the major version of the library
-- minor (string or number ) - the minor version of the library
--
-- returns nil if a newer or same version of the lib is already present
-- returns empty library object or old library object if upgrade is needed
function LibStub:NewLibrary(major, minor) function LibStub:NewLibrary(major, minor)
assert(type(major) == "string", "Bad argument #2 to `NewLibrary' (string expected)") assert(type(major) == "string", "Bad argument #2 to `NewLibrary' (string expected)")
local _, _, num = find(minor, "(%d+)") local _, _, num = find(minor, "(%d+)")
@@ -21,6 +30,12 @@ if not LibStub or LibStub.minor < LIBSTUB_MINOR then
return self.libs[major], oldminor return self.libs[major], oldminor
end end
-- LibStub:GetLibrary(major, [silent])
-- major (string) - the major version of the library
-- silent (boolean) - if true, library is optional, silently return nil if its not found
--
-- throws an error if the library can not be found (except silent is set)
-- returns the library object if found
function LibStub:GetLibrary(major, silent) function LibStub:GetLibrary(major, silent)
if not self.libs[major] and not silent then if not self.libs[major] and not silent then
error(format("Cannot find a library instance of %q.", tostring(major)), 2) error(format("Cannot find a library instance of %q.", tostring(major)), 2)
@@ -28,6 +43,12 @@ if not LibStub or LibStub.minor < LIBSTUB_MINOR then
return self.libs[major], self.minors[major] return self.libs[major], self.minors[major]
end end
function LibStub:IterateLibraries() return pairs(self.libs) end -- LibStub:IterateLibraries()
--
-- Returns an iterator for the currently registered libraries
function LibStub:IterateLibraries()
return pairs(self.libs)
end
setmetatable(LibStub, { __call = LibStub.GetLibrary }) setmetatable(LibStub, { __call = LibStub.GetLibrary })
end end
@@ -784,7 +784,6 @@ local hooks = {
-- hook all functions (which are not yet hooked) -- hook all functions (which are not yet hooked)
for _, name in pairs(hooks) do for _, name in pairs(hooks) do
local name = name
if not lib['hooked'][name] then if not lib['hooked'][name] then
lib['hooked'][name] = _G[name] lib['hooked'][name] = _G[name]
_G[name] = function() _G[name] = function()
+50 -50
View File
@@ -1,10 +1,10 @@
local ns = oUF local ns = oUF
local oUF = ns.oUF local oUF = ns.oUF
assert(oUF, "oUF not loaded") assert(oUF, "oUF not loaded");
local cos, sin, sqrt2, max, atan2 = math.cos, math.sin, math.sqrt(2), math.max, math.atan2 local cos, sin, sqrt2, max, atan2 = math.cos, math.sin, math.sqrt(2), math.max, math.atan2;
local getn, tinsert, tremove = table.getn, table.insert, table.remove local getn, tinsert, tremove = table.getn, table.insert, table.remove;
local pi2 = 3.141592653589793 / 2 local pi2 = 3.141592653589793 / 2;
local GetPlayerMapPosition = GetPlayerMapPosition local GetPlayerMapPosition = GetPlayerMapPosition
local UnitInParty = UnitInParty local UnitInParty = UnitInParty
@@ -12,98 +12,98 @@ local UnitInRaid = UnitInRaid
local UnitIsConnected = UnitIsConnected local UnitIsConnected = UnitIsConnected
local UnitIsUnit = UnitIsUnit local UnitIsUnit = UnitIsUnit
local _FRAMES, OnUpdateFrame = {} local _FRAMES, OnUpdateFrame = {};
local function CalculateCorner(r) return .5 + cos(r) / sqrt2, .5 + sin(r) / sqrt2 end local function CalculateCorner(r) return .5 + cos(r) / sqrt2, .5 + sin(r) / sqrt2; end
local function RotateTexture(texture, angle) local function RotateTexture(texture, angle)
local LRx, LRy = CalculateCorner(angle + 0.785398163) local LRx, LRy = CalculateCorner(angle + 0.785398163);
local LLx, LLy = CalculateCorner(angle + 2.35619449) local LLx, LLy = CalculateCorner(angle + 2.35619449);
local ULx, ULy = CalculateCorner(angle + 3.92699082) local ULx, ULy = CalculateCorner(angle + 3.92699082);
local URx, URy = CalculateCorner(angle - 0.785398163) local URx, URy = CalculateCorner(angle - 0.785398163);
texture:SetTexCoord(ULx, ULy, LLx, LLy, URx, URy, LRx, LRy) texture:SetTexCoord(ULx, ULy, LLx, LLy, URx, URy, LRx, LRy);
end end
local GetAngle = function(unit1, unit2) local GetAngle = function(unit1, unit2)
local x1, y1 = GetPlayerMapPosition(unit1) local x1, y1 = GetPlayerMapPosition(unit1);
if x1 <= 0 and y1 <= 0 then return nil end if(x1 <= 0 and y1 <= 0) then return nil; end
local x2, y2 = GetPlayerMapPosition(unit2) local x2, y2 = GetPlayerMapPosition(unit2)
if x2 <= 0 and y2 <= 0 then return nil end if(x2 <= 0 and y2 <= 0) then return nil; end
return -pi2 - GetPlayerFacing() - atan2(y2 - y1, x2 - x1) return -pi2 - GetPlayerFacing() - atan2(y2 - y1, x2 - x1);
end end
local minThrottle = 0.02 local minThrottle = 0.02
local numArrows, inRange, unit, GPS local numArrows, inRange, unit, GPS
local Update = function(self, elapsed) local Update = function(self, elapsed)
if self.elapsed and self.elapsed > (self.throttle or minThrottle) then if(self.elapsed and self.elapsed > (self.throttle or minThrottle)) then
numArrows = 0 numArrows = 0;
for _, object in next, _FRAMES do for _, object in next, _FRAMES do
if object:IsShown() then if(object:IsShown()) then
GPS = object.GPS GPS = object.GPS;
unit = object.unit unit = object.unit;
if unit then if(unit) then
if unit and GPS.outOfRange then if(unit and GPS.outOfRange) then
inRange = CheckInteractDistance(unit, 4) inRange = CheckInteractDistance(unit, 4);
end end
if not unit or not (UnitInParty(unit) or UnitInRaid(unit)) or UnitIsUnit(unit, "player") or not UnitIsConnected(unit) or (GPS.onMouseOver and (GetMouseFocus() ~= object)) or (GPS.outOfRange and inRange) then if(not unit or not (UnitInParty(unit) or UnitInRaid(unit)) or UnitIsUnit(unit, "player") or not UnitIsConnected(unit) or (GPS.onMouseOver and (GetMouseFocus() ~= object)) or (GPS.outOfRange and inRange)) then
GPS:Hide() GPS:Hide()
else else
local angle = GetAngle("player", unit) local angle = GetAngle("player", unit);
if angle == nil then if(angle == nil) then
GPS:Hide() GPS:Hide();
else else
GPS:Show() GPS:Show();
RotateTexture(GPS.Texture, angle) RotateTexture(GPS.Texture, angle);
numArrows = numArrows + 1 numArrows = numArrows + 1;
end end
end end
else else
GPS:Hide() GPS:Hide();
end end
end end
end end
self.elapsed = 0 self.elapsed = 0;
self.throttle = max(minThrottle, 0.005 * numArrows) self.throttle = max(minThrottle, 0.005 * numArrows);
else else
self.elapsed = (self.elapsed or 0) + elapsed self.elapsed = (self.elapsed or 0) + elapsed;
end end
end end
local Enable = function(self) local Enable = function(self)
local GPS = self.GPS local GPS = self.GPS;
if GPS then if(GPS) then
tinsert(_FRAMES, self) tinsert(_FRAMES, self);
if not OnUpdateFrame then if(not OnUpdateFrame) then
OnUpdateFrame = CreateFrame("Frame") OnUpdateFrame = CreateFrame("Frame");
OnUpdateFrame:SetScript("OnUpdate", function() OnUpdateFrame:SetScript("OnUpdate", function()
Update(this, arg1) Update(this, arg1)
end) end);
end end
OnUpdateFrame:Show() OnUpdateFrame:Show();
return true return true;
end end
end end
local Disable = function(self) local Disable = function(self)
local GPS = self.GPS local GPS = self.GPS;
if GPS then if(GPS) then
for k, frame in next, _FRAMES do for k, frame in next, _FRAMES do
if frame == self then if(frame == self) then
tremove(_FRAMES, k) tremove(_FRAMES, k);
GPS:Hide() GPS:Hide();
break break
end end
end end
if getn(_FRAMES) == 0 and OnUpdateFrame then if(getn(_FRAMES) == 0 and OnUpdateFrame) then
OnUpdateFrame:Hide() OnUpdateFrame:Hide();
end end
end end
end end
oUF:AddElement("GPS", function() end, Enable, Disable) oUF:AddElement("GPS", nil, Enable, Disable);