Module

ServerMap

From Dogcraft Wiki

Revision as of 20:28, 29 October 2024 by Xpmodder (talk | contribs) (fixed some errors. still WIP)

Documentation for this module may be created at Module:ServerMap/doc

-- Copyright (c) 2024, XPModder, Dogcraft.net and contributors
-- 
-- Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"),
-- to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
-- and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
-- 
-- The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
-- 
-- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
-- WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-- 
-- End license text.

-- A module creating a map of the server by utilising images from the Bluemap server plugin

local p = {}
local scale = 0
local xCoord = 0
local zCoord = 0
local world = "sheltie"
local overlay = ""


function generate()

	local output = "<div id=\"outer-map-container\">\n"
	output = output .. "<div class=\"map-grid-container\">\n"
	output = output .. "[https://dogcraft.net/map#" .. world .. ":" .. xCoord .. ":0:" .. zCoord .. ":250:0:0:0:0:perspective Click for full map]\n"
	
	if overlay ~= "" then
		output = output .. "<div class=\"map-overlay-container\">\n" .. overlay .. "\n</div>\n"
	end
	
	local maxWithHeight = scale * 2
	
	for i = 0, maxWithHeight do
		for j = 0, maxWithHeight do
		
			output = output .. "<div class=\"map-grid-child"
			if i == scale then
				if j == scale then
					output = output .. " inner-map-container"
				end
			end
			output = output .. "\" style=\"grid-row: " .. (i + 1) .. "; grid-column: " .. (j + 1) .. ";\">"
			
			output = output .. "https://map.dogcraft.net/maps/" .. world .. "/tiles/1/x" .. (math.floor(xCoord / 500) + (j - scale)) .. "/z" .. (math.floor(zCoord / 500) + (i - scale)) .. ".png\n"
			
			
			if i == scale then
				if j == scale then
					
					local xMod = xCoord % 500
					local left = 0
				
					if xMod < 0 then
						left = (500 + xMod) / 5.01
					else
						left = xMod / 5.01
					end
					
					local zMod = zCoord % 500
					local top = 0
					
					if zMod < 0 then
						top = (500 + zMod) / 5.01
					else
						top = zMod / 5.01
					end
					
					output = output .. "<div id=\"marker-wrapper\" style=\"left: calc(" .. left .. "% - 30px); top: calc(" .. top .. "% - 70px);\">\n"
					output = output .. "<i class=\"fa-solid fa-location-dot\"></i>\n"
					output = output .. "</div>\n"
					
				end
			end
			
			output = output .. "</div>\n"
			
		end
	end
	
	output = output .. "</div>\n"
	output = output .. "</div>\n"
	
	return output
	
end


-- The main function called on #invoke via the template
function p.collapsibleMap(frame)
    local args = {}
    -- get the arguments
    if frame == mw.getCurrentFrame() then
        args = frame:getParent().args
    else
        args = frame.args
    end

    -- validate the arguments and populate the variables with good values
    local scaleParam = args.scale
    if scaleParam == nil then
    	scaleParam = 0
    end
	scale = tonumber(scaleParam)
	
	local x = args.xCoord
	if x == nil then
		x = 0
	end
	xCoord = tonumber(x)
	
	local z = args.zCoord
	if z == nil then
		z = 0
	end
	zCoord = tonumber(z)
	
	local worldParam = args.world
	if worldParam == nil then
		worldParam = "sheltie"
	end
	world = tostring(worldParam)
	world = mw.text.trim(world)
	world = mw.ustring.lower(world)
	
	local overlayParam = args.overlay
	if overlayParam == nil then
		overlayParam = ""
	end
	overlay = tostring(overlayParam)
	
    -- finally generate the map
    return generate()
end

return p
This page was last modified on 29 October 2024, at 20:28. (21 days ago)
Background SRN Opening by Montenator