p = {}
p.structure = function(f)
local args = f.args or f
if f == mw.getCurrentFrame() and args[1] == nil then
args = f:getParent().args
end
args = require("Модуль:ProcessArgs").norm(args)
local i = #args
local dub = {}
for v in mw.text.gsplit( args.dub or '', '%s*;%s*' ) do
h = mw.text.split( v, '%s*,%s*' )[2]
dub[mw.text.split( v, '%s*,%s*' )[1]] = h
i = i + h - 1
end
local result = {}
table.insert(result, '<table cellpadding="2" cellspacing="0" style="line-height: 36px; padding-right: 20px; padding-bottom: 20px">')
local border = 0
local invSlot = require("Модуль:Инвентарный слот").slot
for index, arg in ipairs(args) do
local k = 1
if dub[index] ~= nil then
k = math.max(dub[index],1)
end
if k == 1 then
table.insert(result, '<tr><td></td></tr><tr><td style="padding-right: 10px">Слой ' .. dub[index] .. '</td><td>')
else
table.insert(result, '<tr><td></td></tr><tr><td style="padding-right: 10px">Слои ' .. i-k+1 .. '-' .. i .. '</td><td>')
end
local sloy = {}
sloy = mw.text.split(arg,',')
local mass = {}
local massb = {}
local colmax = 0
for row = 1, #sloy do
local line = sloy[row]
local s = mw.ustring.gsub(line, '%^', '')
colmax = math.max(colmax, mw.ustring.len(s) )
mass[row] = {}
massb[row] = {}
for i2 = 1, mw.ustring.len(line) do
local argChar = mw.ustring.sub(line, i2, i2)
if argChar == '^' then
border = border + 1
else
table.insert(mass[row],argChar)
if border ~= 0 then
massb[row][#mass[row]] = border
border = 0
end
end
end
end
for i2 = 1, colmax + #sloy - 1 do
for n = 1, i2 do
if mass[n] ~= nil then
if i2+1-n <= colmax then
argChar = mass[n][i2+1-n]
if argChar == nil then argChar = '-' end
if argChar ~= '-' then
table.insert(result, '<span style="position: absolute; margin-left: -20px; margin-top: 10px; z-index: -1">[[Файл:Сетка изометрия.png|link=]]</span>')
end
local slotArgs = {}
if args["M" .. argChar] then
slotArgs["мод"] = args["Мод"]
end
slotArgs[1] = (args["M" .. argChar] or '') .. (args[argChar] or '')
slotArgs["класс"] = "invslot-plain"
if massb[n][i2+1-n] ~= nil then
slotArgs["стиль"] = "outline: 2px solid " .. ({"red", "blue", "green"})[massb[n][i2+1-n]]
end
table.insert(result, invSlot(slotArgs))
table.insert(result, "<br>")
end
end
end
table.insert(result, '</td><td>')
end
table.insert(result, "</td></tr>\n")
i = i - k
end
table.insert(result, "</table>")
return table.concat(result)
end
return p
Advertisement
Модуль:Сетка/Структура2
Advertisement