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')

function p.test mw.log(p.getMap{ x=-467, z=-19, y=113, location="park", scale=0.2 }) 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] if not mapData then error(string.format("Invalid location %q", location), 2) end 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