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) -- Note: Do NOT use "getArgs" here; as this is invoked directly from the infobox, we don't want it fetching parent variables local args = frame.args or 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 or location ==  or x ==  or 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 local markers = {} if args["marker"] then markers[#markers+1] = args["marker"] end for i = 1,16,1 do		if args["marker"..i] then markers[#markers+1] = args["marker"..i]		end end 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, markers) end

function p._getMap(location, x, y, z, width, height, gameScale, markers) 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 gameScale = gameScale 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 = gameScale / imageScale local scale = (1/imageScale)*bgScale local imgOffsetX = -(-topLeftCoord[1] + x)*scale + (width*0.5) local imgOffsetY = -(-topLeftCoord[2] + z)*scale + (height*0.5) local map = 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 }   for i,markerStr in ipairs(markers) do    	local t = mw.text.split(markerStr,";") local mrk,coords = t[1], t[2] if mrk == "fairysoul" or mrk == "soul" or mrk == "fairy" then mrk = "" end if mrk == "circle" or mrk == "redcircle" or mrk == "ring" or mrk == "redring" then mrk = "" end local mTag = map:tag("span"):addClass("minimap-marker"):wikitext(mrk) -- If coordinates provide use them; otherwise it defaults to center if coords then coords = mw.text.split(coords, ",") -- get market x/z local mx,mz = coords[1], (#coords > 2 and coords[3] or coords[2]) -- make coordinates relative to center mx = mx - x   		mz = mz - z    		-- get marker offset local mox,moy = mx*scale, mz*scale -- apply to marker mTag:css{ left=mox.."px", top=moy.."px" } end end return map end

return p