Module:History
From Vintage Story Wiki
Documentation for this module may be created at Module:History/doc
local p = {}
function newAutotable(dim)
local MT = {};
for i=1, dim do
MT[i] = {__index = function(t, k)
if i < dim then
t[k] = setmetatable({}, MT[i+1])
return t[k];
end
end}
end
return setmetatable({}, MT[1]);
end
function tablelength(T)
local count = 0
for _ in pairs(T) do count = count + 1 end
return count
end
function p.create(f)
local args = require( 'Module:ProcessArgs' ).merge( true )
local header = {
'{|class="wikitable" style="width:90%"',
'!colspan="3"|History',
'|-'
}
local footer = '|}'
local changes = {}
for i,v in pairs(args) do
local version = v:match('(.*);')
local notes
local parent
if version:match('-(.*)') ~= nil then
parent = version:match('(.*)-')
notes = v:match('-(.*)')
else
parent = version
notes = 'base;' .. v:match(';(.*)')
end
if #changes == 0 then
changes[1] = {parent, notes}
else
for i=1, #changes, 1 do
if changes[i][1] == parent then
changes[i][#changes[i] + 1] = notes
end
break
end
changes[i + 1] = {parent, notes}
end
end
local body = table.concat(header, '\n') .. '\n'
for i,t in pairs(changes) do
local verName = t[1]
local subVerName = t[2]:match('(.*);')
local notes = t[2]:match(';(.*)')
body = body .. '|rowspan="' .. (#changes[i] - 1) .. '" style="width: 200px; text-align:center"|\'\'\'[[' .. verName .. ']]\'\'\'\n'
for k = 2, #changes[i], 1 do
local subVer = changes[i][k]:match('(.*);')
local notes = changes[i][k]:match(';(.*)')
if subVer == 'base' then
body = body .. '|colspan="2"|' .. notes .. '\n|-\n'
elseif subVer == 'stable' then
body = body .. '|style="width: 200px; text-align:center"|\'\'\'[['.. verName .. '|' .. subVer .. ']]\'\'\'||' .. notes .. '\n|-\n'
else
body = body .. '|style="width: 200px; text-align:center"|\'\'\'[['.. verName .. '-' .. subVer .. '|' .. subVer .. ']]\'\'\'||' .. notes .. '\n|-\n'
end
end
end
return body .. '\n' .. footer
end
return p