Quantcast

* Updating Astrolabe

James Whitehead Ii [05-22-07 - 22:53]
* Updating Astrolabe
Filename
Astrolabe/Astrolabe.lua
Astrolabe/AstrolabeMapMonitor.lua
Astrolabe/DongleStub.lua
diff --git a/Astrolabe/Astrolabe.lua b/Astrolabe/Astrolabe.lua
index 4436819..e0b5368 100644
--- a/Astrolabe/Astrolabe.lua
+++ b/Astrolabe/Astrolabe.lua
@@ -1,7 +1,7 @@
 --[[
 Name: Astrolabe
-Revision: $Rev: 626 $
-$Date: 2007-03-30T18:56:21.734670Z $
+Revision: $Rev: 48 $
+$Date: 2007-05-01 19:24:57 -0400 (Tue, 01 May 2007) $
 Author(s): Esamynn (esamynn@wowinterface.com)
 Inspired By: Gatherer by Norganna
              MapLibrary by Kristofer Karlsson (krka@kth.se)
@@ -42,7 +42,7 @@ Note:
 -- DO NOT MAKE CHANGES TO THIS LIBRARY WITHOUT FIRST CHANGING THE LIBRARY_VERSION_MAJOR
 -- STRING (to something unique) OR ELSE YOU MAY BREAK OTHER ADDONS THAT USE THIS LIBRARY!!!
 local LIBRARY_VERSION_MAJOR = "Astrolabe-0.4"
-local LIBRARY_VERSION_MINOR = tonumber(string.match("$Revision: 626 $", "(%d+)") or 1)
+local LIBRARY_VERSION_MINOR = tonumber(string.match("$Revision: 48 $", "(%d+)") or 1)

 if not DongleStub then error(LIBRARY_VERSION_MAJOR .. " requires DongleStub.") end
 if not DongleStub:IsNewerVersion(LIBRARY_VERSION_MAJOR, LIBRARY_VERSION_MINOR) then return end
@@ -329,6 +329,14 @@ end
 -- Minimap Icon Placement
 --------------------------------------------------------------------------------------------------------------

+-- local variables specifically for use in this section
+local minimapRotationEnabled = false;
+local MinimapCompassRing = MiniMapCompassRing;
+local twoPi = math.pi * 2;
+local atan2 = math.atan2;
+local sin = math.sin;
+local cos = math.cos;
+
 local function placeIconOnMinimap( minimap, minimapZoom, mapWidth, mapHeight, icon, dist, xDist, yDist )
 	--TODO: add support for non-circular minimaps
 	local mapDiameter;
@@ -343,6 +351,14 @@ local function placeIconOnMinimap( minimap, minimapZoom, mapWidth, mapHeight, ic
 	local iconDiameter = ((icon:GetWidth() / 2) + 3) * xScale;
 	local iconOnEdge = nil;

+	if ( minimapRotationEnabled ) then
+		-- for the life of me, I cannot figure out why the following
+		-- math works, but it does
+		local dir = atan2(xDist, yDist) + MinimapCompassRing:GetFacing();
+		xDist = dist * sin(dir);
+		yDist = dist * cos(dir);
+	end
+
 	if ( (dist + iconDiameter) > mapRadius ) then
 		-- position along the outside of the Minimap
 		iconOnEdge = true;
@@ -387,6 +403,12 @@ function Astrolabe:PlaceIconOnMinimap( icon, continent, zone, xPos, yPos )
 	iconData.xDist = xDist;
 	iconData.yDist = yDist;

+	if ( GetCVar("rotateMinimap") ~= "0" ) then
+		minimapRotationEnabled = true;
+	else
+		minimapRotationEnabled = false;
+	end
+
 	-- place the icon on the Minimap and :Show() it
 	local map = Minimap
 	placeIconOnMinimap(map, map:GetZoom(), map:GetWidth(), map:GetHeight(), icon, dist, xDist, yDist);
@@ -428,9 +450,15 @@ function Astrolabe:UpdateMinimapIconPositions()
 	local lastPosition = self.LastPlayerPosition;
 	local lC, lZ, lx, ly = unpack(lastPosition);

+	if ( GetCVar("rotateMinimap") ~= "0" ) then
+		minimapRotationEnabled = true;
+	else
+		minimapRotationEnabled = false;
+	end
+
 	if ( lC == C and lZ == Z and lx == x and ly == y ) then
 		-- player has not moved since the last update
-		if ( lastZoom ~= Minimap:GetZoom() or self.ForceNextUpdate ) then
+		if ( lastZoom ~= Minimap:GetZoom() or self.ForceNextUpdate or minimapRotationEnabled ) then
 			local currentZoom = Minimap:GetZoom();
 			lastZoom = currentZoom;
 			local mapWidth = Minimap:GetWidth();
@@ -477,6 +505,12 @@ function Astrolabe:CalculateMinimapIconPositions()
 		return;
 	end

+	if ( GetCVar("rotateMinimap") ~= "0" ) then
+		minimapRotationEnabled = true;
+	else
+		minimapRotationEnabled = false;
+	end
+
 	local currentZoom = Minimap:GetZoom();
 	lastZoom = currentZoom;
 	local Minimap = Minimap;
@@ -513,8 +547,6 @@ function Astrolabe:IsIconOnEdge( icon )
 	return self.IconsOnEdge[icon];
 end

-local twoPi = math.pi * 2;
-local atan2 = math.atan2;
 function Astrolabe:GetDirectionToIcon( icon )
 	local data = self.MinimapIcons[icon];
 	if ( data ) then
diff --git a/Astrolabe/AstrolabeMapMonitor.lua b/Astrolabe/AstrolabeMapMonitor.lua
index c9349c6..ae81c27 100644
--- a/Astrolabe/AstrolabeMapMonitor.lua
+++ b/Astrolabe/AstrolabeMapMonitor.lua
@@ -1,7 +1,7 @@
 --[[
 Name: AstrolabeMapMonitor
-Revision: $Rev: 626 $
-$Date: 2007-03-30T18:56:21.734670Z $
+Revision: $Rev: 44 $
+$Date: 2007-03-30 14:56:21 -0400 (Fri, 30 Mar 2007) $
 Author(s): Esamynn (esamynn@wowinterface.com)
 Inspired By: Gatherer by Norganna
              MapLibrary by Kristofer Karlsson (krka@kth.se)
@@ -43,7 +43,7 @@ Note:
 -- DO NOT MAKE CHANGES TO THIS LIBRARY WITHOUT FIRST CHANGING THE LIBRARY_VERSION_MAJOR
 -- STRING (to something unique) OR ELSE YOU MAY BREAK OTHER ADDONS THAT USE THIS LIBRARY!!!
 local LIBRARY_VERSION_MAJOR = "AstrolabeMapMonitor"
-local LIBRARY_VERSION_MINOR = tonumber(string.match("$Revision: 626 $", "(%d+)") or 1)
+local LIBRARY_VERSION_MINOR = tonumber(string.match("$Revision: 44 $", "(%d+)") or 1)

 if not DongleStub then error(LIBRARY_VERSION_MAJOR .. " requires DongleStub.") end
 if not DongleStub:IsNewerVersion(LIBRARY_VERSION_MAJOR, LIBRARY_VERSION_MINOR) then return end
diff --git a/Astrolabe/DongleStub.lua b/Astrolabe/DongleStub.lua
index 2f14410..b5211a9 100644
--- a/Astrolabe/DongleStub.lua
+++ b/Astrolabe/DongleStub.lua
@@ -3,8 +3,8 @@
   without any conditions, unless such conditions are required by law.
 ---------------------------------------------------------------------------]]

-local major = "DongleStub-Beta0"
-local minor = tonumber(string.match("$Revision: 221 $", "(%d+)") or 1)
+local major = "DongleStub"
+local minor = tonumber(string.match("$Revision: 313 $", "(%d+)") or 1)

 local g = getfenv(0)

@@ -21,10 +21,24 @@ if not g.DongleStub or g.DongleStub:IsNewerVersion(major, minor) then

 	function lib:IsNewerVersion(major, minor)
 		local versionData = self.versions and self.versions[major]
-
+
+		-- If DongleStub versions have differing major version names
+		-- such as DongleStub-Beta0 and DongleStub-1.0-RC2 then a second
+		-- instance will be loaded, with older logic.  This code attempts
+		-- to compensate for that by matching the major version against
+		-- "^DongleStub", and handling the version check correctly.
+
+		if major:match("^DongleStub") then
+			local oldmajor,oldminor = self:GetVersion()
+			if self.versions and self.versions[oldmajor] then
+				return minor > oldminor
+			else
+				return true
+			end
+		end
+
 		if not versionData then return true end
 		local oldmajor,oldminor = versionData.instance:GetVersion()
-
 		return minor > oldminor
 	end

@@ -34,7 +48,19 @@ if not g.DongleStub or g.DongleStub:IsNewerVersion(major, minor) then
 	end

 	function lib:Register(newInstance, activate, deactivate)
+		assert(type(newInstance.GetVersion) == "function",
+			"Attempt to register a library with DongleStub that does not have a 'GetVersion' method.")
+
 		local major,minor = newInstance:GetVersion()
+		assert(type(major) == "string",
+			"Attempt to register a library with DongleStub that does not have a proper major version.")
+		assert(type(minor) == "number",
+			"Attempt to register a library with DongleStub that does not have a proper minor version.")
+
+		-- Generate a log of all library registrations
+		if not self.log then self.log = {} end
+		table.insert(self.log, string.format("Register: %s, %s", major, minor))
+
 		if not self:IsNewerVersion(major, minor) then return false end
 		if not self.versions then self.versions = {} end

@@ -48,6 +74,7 @@ if not g.DongleStub or g.DongleStub:IsNewerVersion(major, minor) then

 			self.versions[major] = versionData
 			if type(activate) == "function" then
+				table.insert(self.log, string.format("Activate: %s, %s", major, minor))
 				activate(newInstance)
 			end
 			return newInstance
@@ -60,11 +87,14 @@ if not g.DongleStub or g.DongleStub:IsNewerVersion(major, minor) then

 		local skipCopy
 		if type(activate) == "function" then
-			 skipCopy = activate(newInstance, oldInstance)
+			table.insert(self.log, string.format("Activate: %s, %s", major, minor))
+			skipCopy = activate(newInstance, oldInstance)
 		end

 		-- Deactivate the old libary if necessary
 		if type(oldDeactivate) == "function" then
+			local major, minor = oldInstance:GetVersion()
+			table.insert(self.log, string.format("Deactivate: %s, %s", major, minor))
 			oldDeactivate(oldInstance, newInstance)
 		end

@@ -78,13 +108,19 @@ if not g.DongleStub or g.DongleStub:IsNewerVersion(major, minor) then
 	function lib:GetVersion() return major,minor end

 	local function Activate(new, old)
+		-- This code ensures that we'll move the versions table even
+		-- if the major version names are different, in the case of
+		-- DongleStub
+		if not old then old = g.DongleStub end
+
 		if old then
 			new.versions = old.versions
+			new.log = old.log
 		end
 		g.DongleStub = new
 	end

 	-- Actually trigger libary activation here
 	local stub = g.DongleStub or lib
-	stub:Register(lib, Activate)
+	lib = stub:Register(lib, Activate)
 end