Module:History: Difference between revisions
From Vintage Story Wiki
mNo edit summary |
mNo edit summary |
||
(14 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
local p = {} | 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) | function p.create(f) | ||
Line 5: | Line 25: | ||
local header = { | local header = { | ||
'{|class="wikitable"', | '{|class="wikitable" style="width:90%"', | ||
'!colspan="3"|History', | '!colspan="3"|History', | ||
'|-' | '|-' | ||
Line 11: | Line 31: | ||
local footer = '|}' | local footer = '|}' | ||
local | local changes = {} | ||
for i,v in pairs(args) do | for i,v in pairs(args) do | ||
local version = | local version = v:match('(.*);') | ||
local parent = | 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 | end | ||
local body = header .. '\n' | local body = table.concat(header, '\n') .. '\n' | ||
for | for i,t in pairs(changes) do | ||
body = body .. '|[[' .. | local verName = t[1] | ||
for | 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 | ||
end | end |
Latest revision as of 20:30, 27 August 2022
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