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 mt_2D = {
local changes = {}
    __index =
      function(t, k)
        local inner = {}
        rawset(t, k, inner)
        return inner
      end
}
local versions = setmetatable({}, mt_2D)
for i,v in pairs(args) do
for i,v in pairs(args) do
local version = string.match(v, '(.*);')
local version = v:match('(.*);')
local parent = string.match(version, '(.*)-')
local notes
local child = string.match(version, '-(.*)')
local parent
local note = string.match(v , ';(.*)')
if version:match('-(.*)') ~= nil then
versions[parent][child] = note
    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 ver in versions do
for i,t in pairs(changes) do
body = body .. '|[[' .. tostring(ver) .. ']]'
    local verName = t[1]
for child in ver do
    local subVerName = t[2]:match('(.*);')
body = body .. '||[[' .. tostring(child) .. ']]'
    local notes = t[2]:match(';(.*)')
for note in child do
body = body .. '|rowspan="' .. (#changes[i] - 1) .. '" style="width: 200px; text-align:center"|\'\'\'[[' .. verName .. ']]\'\'\'\n'
body = body .. '||' .. note
for k = 2, #changes[i], 1 do
end
    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