Module:RotaenoMap
可在Module:RotaenoMap/doc创建此模块的帮助文档
local p = {} local getArgs = require('Module:Arguments').getArgs; local function len_t(t) local leng=0 for k, v in pairs(t) do leng=leng+1 end return leng; end function p._main(args) --期望参数是:(x,y,z,类型,里程数,注解) if len_t(args) % 6 ~= 0 then error("args的长度不能整除6") end local pos_length = len_t(args) / 6 --给定pos的个数 local pos_data = {} local pos_max = { ["x_max"] = 0, ["x_min"] = 0, ["y_max"] = 0, ["y_min"] = 0 } for i=1,pos_length do local x = (tonumber(args[6*i - 5]) + tonumber(args[6*i - 4])) * 129.903 local y = ((-tonumber(args[6*i - 5]) + tonumber(args[6*i - 4])) *75) + (tonumber(args[6*i - 3]) * 150) if x > pos_max["x_max"] then pos_max["x_max"] = x elseif x < pos_max["x_min"] then pos_max["x_min"] = x end if y > pos_max["y_max"] then pos_max["y_max"] = y elseif y<pos_max["y_min"] then pos_max["y_min"] = y end table.insert(pos_data,{ ["left"] = x, ["top"] = y, ["req"] = args[6*i - 1], ["ref"] = args[6*i], --.."x,y,z:"..args[5*i-4]..args[5*i-3]..args[5*i-2].."<br>left:"..x..",top:"..y -- 调试用 ["type"] = args[6*i-2] }) end local outer_wrapper = mw.html.create("div") outer_wrapper:cssText("overflow:auto;position:relative;width:100%;maxheight:60vh") local wrapper_div = mw.html.create("div") outer_wrapper:node(wrapper_div) wrapper_div:cssText("overflow:auto;position:relative;min-width:100%") wrapper_div:css("width", pos_max["x_max"] - pos_max["x_min"] + 100 .. "px") wrapper_div:css("height", pos_max["y_max"] - pos_max["y_min"] + 100 .."px") for k,v in pairs(pos_data) do local inner_div = mw.html.create("div") inner_div :addClass("content") :css("min-width", "10em") :wikitext("'''"..v["req"] .. "公里".."'''") :tag("br"):done() :wikitext(v["ref"]) local outer_div = mw.html.create("div") local border_color = "#6d6d6d" local step_type = v["type"] if step_type == "chal" then border_color = "#ff7d7d" elseif step_type == "game" then border_color = "#f58d45" elseif step_type == "cond" then border_color = "#9d10d4" end outer_div:addClass("step") :css("background-image",'radial-gradient(ellipse 50% 50%, #fff 0%,#fff 80%, '..border_color.. ' 80%)') :cssText("border-radius: 50%/50%;position:absolute") :css('left', tostring(v["left"] + 44 - pos_max["x_min"]).. "px") -- 44=100-56(step的半径) :css('top',tostring(v["top"] + 73 -pos_max["y_min"]) .. 'px') -- 74 = 100-27 参见css outer_div:node(inner_div) wrapper_div:node(outer_div) end return tostring(outer_wrapper) end function p.main(frame) local args = getArgs(frame) return p._main(args) end return p