Module:Minimap

-- local p = {}

local getArgs = require('Module:Arguments').getArgs require('Module:LibraryUtil')

-- mw.loadData to be more efficient local maps = mw.loadData('Module:Minimap/Data') local aliases = mw.loadData('Module:Minimap/Aliases')

-- returns blank if not valid; fails silently function p.getMinimapForInfobox(frame) local args = getArgs(frame) local location = args[1] or args["location"] local x = args["x"] local y = args["y"] or 71 local z = args["z"] if not location or not x or not z then return "" end location = location:gsub("%[*", ""):gsub("%]*", "") location = location:lower location = aliases[location] or location if not maps[location] then return "" end return p._getMap(location, x, y, z, 272, 272) end

function p.getMap(frame) local args = getArgs(frame) local location = args["location"] or args[1] local x = args["x"] local y = args["y"] or 71 local z = args["z"] local width = args["width"] or args["size"] or 150 local height = args["height"] or args["size"] or 150 local scale = args["scale"] -- true in-game scale - will default to image scale assertTrue(location, "location must be specified", 0) assertTrue(x, "x must be specified", 0) assertTrue(z, "z must be specified", 0) return p._getMap(location, x, y, z, width, height, scale) end

function p._getMap(location, x, y, z, width, height, scale) location = location:lower location = aliases[location] or location local mapData = maps[location] -- Check for errors assertTrue(mapData, 'Invalid location %q', 2, location) local imageScale = mapData.imageScale local topLeftCoord = mapData.topLeftCoord local imageDimensions = mapData.imageDimensions scale = scale or imageScale -- true in-game scale -- How much to scale actual image on the page based on "true scale" desired, and the images default world scale local bgScale = scale / imageScale local originOffset = { -topLeftCoord[1]/imageScale, -topLeftCoord[2]/imageScale } local imgOffsetX = -(originOffset[1] + (x/imageScale))*bgScale + (width*0.5) local imgOffsetY = -(originOffset[2] + (z/imageScale))*bgScale + (height*0.5) return mw.html.create('div') :addClass("hsw-minimap") :addClass(mapData.imageClass) :css({   		width=width.."px",    		height=height.."px",    		["background-position"]= imgOffsetX.."px "..imgOffsetY.."px",    		["background-size"]= (imageDimensions[1]*bgScale).."px",--leaving off the height has it auto scale    	}) end

return p