Quantcast

Update LibMapData to r66

James Whitehead II [12-03-10 - 11:06]
Update LibMapData to r66
Filename
libs/LibMapData-1.0/library.lua
diff --git a/libs/LibMapData-1.0/library.lua b/libs/LibMapData-1.0/library.lua
index 9a9f682..dddd7d3 100644
--- a/libs/LibMapData-1.0/library.lua
+++ b/libs/LibMapData-1.0/library.lua
@@ -2,7 +2,7 @@
 	Library contains a dataset for Map file names and floors giving the raw map data
 	it also has a few functions to help determine distance and directions.
 --]]
-local MAJOR, MINOR = "LibMapData-1.0", tonumber("64") or 999
+local MAJOR, MINOR = "LibMapData-1.0", tonumber("66") or 999
 assert(LibStub, MAJOR.." requires LibStub")

 local lib = LibStub:NewLibrary(MAJOR, MINOR)
@@ -940,6 +940,18 @@ function lib:GetDungeons(storage)
 	return t
 end

+
+--- API to get the continent for a given map
+-- @param the map file or id to check
+-- @return the in-game continent index
+function lib:GetContinentFromMap(mapfile)
+	if type(mapfile) == "string" then
+		mapfile = idToMap[mapfile]
+	end
+	if mapfile == WORLDMAP_COSMIC_ID then return -1 end
+	return mapData[map].continent
+end
+
 --- API to list zones by continent
 -- @param Continent index
 -- @param (optional) table to store results in
@@ -965,8 +977,8 @@ function lib:IsContinentMap(mapfile)
 	if type(mapfile) == "string" then
 		mapfile = idToMap[mapfile]
 	end
-	if mapfile == -1 then return true end
-	if mapfile == 466 or mapfile == 485 or mapfile == 13 or mapfile == 14 then
+	if mapfile == WORLDMAP_COSMIC_ID then return true end
+	if mapfile == 466 or mapfile == 485 or mapfile == 13 or mapfile == 14 or mapfile == 751 then
 		return true
 	end
 	return false
@@ -1009,7 +1021,7 @@ function lib:Distance(mapfile,floor, srcX,srcY,dstX,dstY)
 	if type(mapfile) == "string" then
 		mapfile = idToMap[mapfile]
 	end
-	if mapfile == -1 then return 0,0,0 end
+	if mapfile == WORLDMAP_COSMIC_ID then return 0,0,0 end
 	local data = mapData[mapfile]
 	local fl = data[floor]
 	if floor and floor <= data['floors'] and floor > 0 then
@@ -1032,7 +1044,7 @@ function lib:ConvertToWorldPoint(mapfile,x,y)
    	if type(mapfile) == "string" then
 		mapfile = idToMap[mapfile]
 	end
-	if mapfile == -1 then return 0 end
+	if mapfile == WORLDMAP_COSMIC_ID then return 0 end
 	local fl = mapData[mapfile]
 	-- Convert to continet data
 	local x1,y1 = self:ConvertToContinent(mapfile,0,x,y)
@@ -1054,6 +1066,10 @@ end
 -- @param y in yards
 -- @return x,y in zone scale
 function lib:ConvertFromContinent(map,floor,x,y)
+	if type(map) == "string" then
+		map = idToMap[map]
+	end
+	if map == WORLDMAP_COSMIC_ID then return 0,0 end
 	local zx1,zy1 = self:GetMapUpperLeft(map,floor)
 	local zx2,zy2 = self:GetMapLowerRight(map,floor)
 	local x,y = (x-zx1)/(zx1-zx2), (y-zy1)/(zy2-zy1)
@@ -1071,6 +1087,10 @@ end
 -- @param y in yards
 -- @return x,y in continent scale
 function lib:ConvertToContinent(map,floor, x,y)
+	if type(map) == "string" then
+		map = idToMap[map]
+	end
+	if map == WORLDMAP_COSMIC_ID then return 0,0 end
 	local zx1,zy1 = self:GetMapUpperLeft(map,floor)
 	local zx2,zy2 = self:GetMapLowerRight(map,floor)
 	local x,y =  zx1 + (zx2-zx1)*x,zy1 + (zy2-zy1)*y
@@ -1100,6 +1120,11 @@ function lib:DistanceWithinContinent(srcMap,srcFloor, srcX, srcY, dstMap, dstFlo
 	if type(srcMap) == "string" then
 		srcMap = idToMap[srcMap]
 	end
+
+	if srcMap == WORLDMAP_COSMIC_ID or dstMap == WORLDMAP_COSMIC_ID then
+		return 0,0,0
+	end
+
 	if mapData[srcMap].continent ~= mapData[dstMap].continent then
 		return 0,0,0
 	end
@@ -1123,7 +1148,7 @@ function lib:PointToYards(mapfile,floor, x, y)
 	if type(mapfile) == "string" then
 		mapfile = idToMap[mapfile]
 	end
-	if mapfile == -1 then return 0,0 end
+	if mapfile == WORLDMAP_COSMIC_ID then return 0,0 end
 	local data = mapData[mapfile]
 	local fl = data[floor]
 	if floor and floor <= data['floors'] and floor > 0 then
@@ -1148,7 +1173,7 @@ function lib:YardsToPoint(mapfile,floor,x,y)
 	if type(mapfile) == "string" then
 		mapfile = idToMap[mapfile]
 	end
-	if mapfile == -1 then return 0,0 end
+	if mapfile == WORLDMAP_COSMIC_ID then return 0,0 end
 	local data = mapData[mapfile]
 	local fl = data[floor]
 	if floor and floor <= data['floors'] and floor > 0 then
@@ -1169,7 +1194,7 @@ function lib:MapFloors(mapfile)
 	if type(mapfile) == "string" then
 		mapfile = idToMap[mapfile]
 	end
-	if mapfile == -1 then return 0 end
+	if mapfile == WORLDMAP_COSMIC_ID then return 0 end
 	local fl = mapData[mapfile]['floors']
 	if fl == 1 then
 		fl = 0
@@ -1194,7 +1219,7 @@ function lib:MapLocalize(mapfile)
 	if type(mapfile) == "number" then
 		mapfile = mapData[mapfile]['name']
 	end
-	if mapfile == -1 then return WORLD_MAP end
+	if mapfile == WORLDMAP_COSMIC_ID then return WORLD_MAP end
 	return mapToLocal[mapfile]
 end

@@ -1208,7 +1233,7 @@ function lib:MapArea(mapfile,floor)
 	if type(mapfile) == "string" then
 		mapfile = idToMap[mapfile]
 	end
-	if mapfile == -1 then return 0,0 end
+	if mapfile == WORLDMAP_COSMIC_ID then return 0,0 end
 	local data = mapData[mapfile]
 	local fl = data[floor]
 	if floor and floor <= data['floors'] and floor > 0 then
@@ -1233,7 +1258,7 @@ function lib:GetMapUpperLeft(mapfile, floor)
 	if type(mapfile) == "string" then
 		mapfile = idToMap[mapfile]
 	end
-	if mapfile == -1 then return 0,0 end
+	if mapfile == WORLDMAP_COSMIC_ID then return 0,0 end
 	local data = mapData[mapfile]
 	local fl = data[floor + 1]
 	if floor and floor <= data['floors'] then
@@ -1257,7 +1282,7 @@ function lib:GetMapLowerRight(mapfile, floor)
 	if type(mapfile) == "string" then
 		mapfile = idToMap[mapfile]
 	end
-	if mapfile == -1 then return 0,0 end
+	if mapfile == WORLDMAP_COSMIC_ID then return 0,0 end
 	local data = mapData[mapfile]
 	local fl = data[floor + 1]
 	if floor and floor <= data['floors'] then