Module:Sandbox/History

local p = {} local tableHead local mode = nil local currentVersion = nil local currentConsoleVersions = { xbox360 = nil, xbone = nil, ps = nil, wiiu = nil, switch = nil } local consoleRowspanIndexes local consoleRowspans local rowspanIndex local rowspans local versionLink = require( 'Module:Version link' ).main

local editionAlias={ ['java pre-classic'] = "java pre-Classic", ['java classic'] = "java Classic", ['java indev'] = "java Indev", ['java infdev'] = "java Infdev", ['java alpha'] = "java Alpha", ['java edition alpha'] = "java Alpha", ['java beta'] = "java Beta", ['java edition beta'] = "java Beta", je = "java", java = "java", ['java edition'] = "java", ['java edition upcoming'] = "java upcoming", ['java upcoming'] = "java upcoming", ['upcoming java'] = "java upcoming", ['upcoming java edition'] = "java upcoming", ['pe alpha'] = "pocket Alpha", ['pocket alpha'] = "pocket Alpha", ['pocket edition alpha'] = "pocket Alpha", pe = "pocket", pocket = "pocket", ['pocket edition'] = "pocket", ce = "console", lce = "console", console = "console", ['legacy console'] = "console", ['console edition'] = "console", ['legacy console edition'] = "console", be = "bedrock", bedrock = "bedrock", ['bedrock edition'] = "bedrock", ['be upcoming'] = "bedrock upcoming", ['bedrock upcoming'] = "bedrock upcoming", ['bedrock edition upcoming'] = "bedrock upcoming", ['upcoming bedrock'] = "bedrock upcoming", ['upcoming bedrock edition'] = "bedrock upcoming", ['3ds'] = "new3ds", new3ds = "new3ds", ['new 3ds'] = "new3ds", realms = "realms", pi = "pi", ['raspberry pi'] = "pi", edu = "minecraftedu", minecraftedu = "minecraftedu", education = "education", ['education edition'] = "education", ['education upcoming'] = "education upcoming", ['education edition upcoming'] = "education upcoming", ['upcoming education'] = "education upcoming", ['upcoming education edition'] = "education upcoming", ps4 = "ps4", playstation4 = "ps4", ['playstation 4'] = "ps4", earth = "earth", ['minecraft earth'] = "earth", dungeons = "dungeons", ['minecraft dungeons'] = "dungeons", legends = "legends", ['minecraft legends'] = "legends", china = "china", bs = "bedrock server", bds = "bedrock server", ['bedrock server'] = "bedrock server", ['bedrock dedicated server'] = "bedrock server", ['?'] = "unknown", unknown = "unknown" }

local headerText={ ['java pre-Classic']   = 'Java Edition pre-Classic', ['java Classic']       = 'Java Edition Classic', ['java Indev']         = 'Java Edition Indev', ['java Infdev']        = 'Java Edition Infdev', ['java Alpha']         = 'Java Edition Alpha', ['java Beta']          = 'Java Edition Beta', ['java']               = "Java Edition", ['java upcoming']      = 'Upcoming Java Edition', ['pocket Alpha']       = 'Pocket Edition Alpha', ['pocket']             = "Pocket Edition", ['bedrock']            = "Bedrock Edition", ['bedrock upcoming']   = 'Upcoming Bedrock Edition', ['minecraftedu']       = "MinecraftEdu", ['education']          = "Education Edition", ['education upcoming'] = 'Upcoming Education Edition', ['china']              = "China Edition", ['bedrock server']     = 'Realms Plus & Bedrock Dedicated Server', ['console']            = 'Legacy Console Edition', ['realms']             = 'Realms', ['new3ds']             = "New Nintendo 3DS Edition", ['pi']                 = "Pi Edition", ['ps4']                = "PlayStation 4 Edition", ['earth']              = "Minecraft Earth", ['dungeons']           = "Minecraft Dungeons", ['legends']           = "Minecraft Legends", ['unknown']            = 'Unknown' }

local versionLinks ={ ['java upcoming'] = 'java', ['bedrock upcoming'] = 'bedrock', ['education upcoming'] = 'education', ['bedrock server'] = 'Bedrock Dedicated Server' }

local sortKeys = { ['java 1.0.0'] = "A", ['java 1.1'] = "B", ['java 1.2.1'] = "C", ['java 1.3.1'] = "D", ['java 1.4.2'] = "E", ['java 1.5'] = "F", ['java 1.6.1'] = "G", ['java 1.7.2'] = "F", ['java 1.8'] = "G", ['java 1.9'] = "H", ['java 1.10'] = "I", ['java 1.11'] = "J", ['java 1.12'] = "K", ['java 1.13'] = "L", ['java 1.14'] = "M", ['java 1.15'] = "N", ['java 1.16'] = "O", ['java texture update'] = "_", ['java indev 0.31'] = "0", ['java alpha v1.2.0'] = "2", ['java beta 1.6'] = "6", ['java beta 1.8'] = "8", ['pocket alpha v0.8.0'] = "A", ['pocket alpha 0.8.0'] = "A", ['pocket alpha v0.9.0'] = "B", ['pocket alpha 0.9.0'] = "B", ['pocket alpha v0.10.0'] = "C", ['pocket alpha 0.10.0'] = "C", ['pocket alpha v0.11.0'] = "D", ['pocket alpha 0.11.0'] = "D", ['pocket alpha v0.12.1'] = "E", ['pocket alpha 0.12.1'] = "E", ['pocket alpha v0.13.0'] = "F", ['pocket alpha 0.13.0'] = "F", ['pocket alpha v0.14.0'] = "G", ['pocket alpha 0.14.0'] = "G", ['pocket alpha v0.15.0'] = "H", ['pocket alpha 0.15.0'] = "H", ['pocket alpha v0.16.0'] = "I", ['pocket alpha 0.16.0'] = "I", ['pocket 1.0.0'] = "X", ['pocket 1.1.0'] = "Y", ['pocket 1.1.3'] = "Z", ['bedrock 1.2.0'] = "A", ['bedrock 1.2.13'] = "B", ['bedrock 1.4.0'] = "C", ['bedrock 1.5.0'] = "D", ['bedrock 1.6.0'] = "E", ['bedrock 1.7.0'] = "F", ['bedrock 1.8.0'] = "G", ['bedrock 1.9.0'] = "H", ['bedrock 1.10.0'] = "I", ['bedrock 1.11.0'] = "J", ['bedrock 1.12.0'] = "K", ['bedrock 1.13.0'] = "L", ['bedrock 1.14.0'] = "M", ['bedrock 1.14.60'] = "M", ['bedrock 1.16.0'] = "N", ['bedrock 1.16.100'] = "N" }

local function getUnknownCate if(mode=='unknown') then return '' end local sortKey = sortKeys[mode..currentVersion] or "*" return mw.getCurrentFrame:preprocess("") end

local function resetConsole currentConsoleVersions.xbox360 = nil currentConsoleVersions.xbone = nil currentConsoleVersions.ps = nil currentConsoleVersions.wiiu = nil currentConsoleVersions.switch = nil end

local function reset currentVersion = nil resetConsole end

local function footReset mode = nil reset end

local function getVersionLink(link,text,isSnap) if(link=='none') then if(text=='unknown' or text=='?') then return '?'..getUnknownCate end if(isSnap and text=='java') then return '' end return text end if(link=='ver') then if(text=='unknown' or text=='?') then return '?'..getUnknownCate end if(isSnap and text=='java') then return '' end if((not isSnap) and (mode=='realms')) then return text end local c			if(not isSnap) then if(text=='Pre-release' and mode == 'pocket Alpha') then c = 'pocket Pre-release' else c= (versionLinks[mode] or mode)..' '..text end else c=text:lower if(c:match('^test build') or c:match('^pre%-release') or c:match('^build') or c:match('^20[01]') or c:match('^release candidate') or c:match('^experimental snapshot')) then c=currentVersion..' '..text elseif(c:match('^pre')) then c=currentVersion..'-'..text elseif(c:match('^release')) then c=currentVersion else c = text end c=(versionLinks[mode] or mode)..' '..c			end return versionLink({c,text:gsub( '^%((.*)%)$', '%1')}) end local cat = '' if(text=='unknown' or text=='?') then cat = getUnknownCate end if(link:find('//',1,true)) then return '['..link..' '..text..']'..cat else return ..text....cat end end

local function consoleVersionLink(platform,version) if(version=='none') then return ' ' end if(version=='unknown' or version=='?') then return '?'..getUnknownCate end local r=platform..' '..version if(platform=='ps') then return ..version:gsub('%w*%(.*%)',)..'' end return versionLink({r,version}) end

local function addConsoleVersions(platform,version,prnt) if((version~=nil and version == currentConsoleVersions[platform]) or (version==nil and currentConsoleVersions[platform]~=nil)) then return end prnt('') prnt(consoleVersionLink(platform,version or 'none')) prnt(' ') end

local function processLine(args, prnt) local snapRows = 1 for i,_ in ipairs(args) do if(i>3) then snapRows = snapRows+1 end end

--Header or Foot if(args[1] ~= nil and args[1] ~= '') then local temp = (args[1]):lower if (temp == 'foot') then prnt(' ') footReset tableHead = 0 return end mode = editionAlias[temp] or temp reset prnt(' ') prnt(headerText[mode] or (.. mode ..)) prnt(' ') return end

--Content rows

prnt(' ')

if((mode == 'console') and (args.xbox or args.xbone or args.ps or args.wiiu or args.switch )) then currentVersion = nil

if(args[3] ~= nil and args[3] ~= '') then snapRows = snapRows+1 end addConsoleVersions("xbox360",args.xbox,prnt) addConsoleVersions("xbone",args.xbone,prnt) addConsoleVersions("ps",args.ps,prnt) addConsoleVersions("wiiu",args.wiiu,prnt) addConsoleVersions("switch",args.switch,prnt) prnt(' '..args[2]..' ') for k,v in ipairs(args) do if(k>2) then prnt(' '..v..'  ') end end

return end

--Other versions:

resetConsole if((args.snap == nil) or (args[2] and args[2]~='' and (args[2] ~= currentVersion))) then currentVersion = nil prnt('')        else            prnt(snapRows .. '" colspan="5">')       end

prnt(getVersionLink(args.link or 'ver', args[2],false)) prnt(' ') end

if(args.snap ~= nil) then prnt('') prnt(getVersionLink(args.slink or 'ver', args.snap,true)) prnt(' ') end

prnt(' '..args[3]..' ') for k,v in ipairs(args) do if(k>3) then prnt(' '..v..'  ') end end

return end

local function getLines(f) local args = f	if f == mw.getCurrentFrame then args = require( 'Module:ProcessArgs' ).merge( true ) end assert(mw.text.trim(args[1]):sub(-14)=='') local stringLines = mw.text.split(mw.text.trim(args[1]):sub(1,-15),'',true) local tableLines = {} local stringArgs local temp,temp1,temp2 for i,l in ipairs(stringLines) do		tableLines[i]={} temp = mw.text.trim(l) or '' if(temp~='') then stringArgs = mw.text.split(temp,'',true) for m,n in ipairs(stringArgs) do				if(n~='') then temp = n:find("=",1,true) temp1 = mw.text.trim(n:sub(1,temp-1)) temp1 = tonumber(temp1) or temp1 temp2 = mw.text.trim(n:sub(temp+1)) tableLines[i][temp1]=temp2 end end end end return tableLines end

function p.printArgs(f) local args = f	if f == mw.getCurrentFrame then args = require( 'Module:ProcessArgs' ).merge( false ) end local result = '' for k,v in pairs(args) do		result=result..k..'='..v..'' end result = result..'' return result end

local function countConsoleRowspans(platform,version,snapRows) if((version~=nil and version == currentConsoleVersions[platform]) or (version==nil and currentConsoleVersions[platform]~=nil)) then consoleRowspans[platform][consoleRowspanIndexes[platform]] = consoleRowspans[platform][consoleRowspanIndexes[platform]] + snapRows return end currentConsoleVersions[platform] = version or "none" consoleRowspanIndexes[platform] = consoleRowspanIndexes[platform] + 1 consoleRowspans[platform][consoleRowspanIndexes[platform]] = (consoleRowspans[platform][consoleRowspanIndexes[platform]] or 0) + snapRows end

local function countRowspan(args) local snapRows = 1 for i,_ in ipairs(args) do if(i>3) then snapRows = snapRows+1 end end

--Header or Foot if(args[1] ~= nil and args[1] ~= '') then local temp = (args[1]):lower if (temp == 'foot') then footReset return end mode = editionAlias[temp] or temp reset return end

--Content rows

if((mode == 'console') and (args.xbox or args.xbone or args.ps or args.wiiu or args.switch )) then currentVersion = nil

if(args[3] ~= nil and args[3] ~= '') then snapRows = snapRows+1 end countConsoleRowspans("xbox360",args.xbox,snapRows) countConsoleRowspans("xbone",args.xbone,snapRows) countConsoleRowspans("ps",args.ps,snapRows) countConsoleRowspans("wiiu",args.wiiu,snapRows) countConsoleRowspans("switch",args.switch,snapRows) return end

--Other versions:

resetConsole if((args.snap == nil) or (args[2] and args[2]~='' and (args[2] ~= currentVersion))) then currentVersion = nil if( args.snap ~= nil) then currentVersion = args[2] rowspanIndex = rowspanIndex + 1 end end

if(args.snap ~= nil) then rowspans[rowspanIndex] = (rowspans[rowspanIndex] or 0) + snapRows end return end

local function initRowspans rowspans = {} consoleRowspans = { xbox360 = {}, xbone = {}, ps = {}, wiiu = {}, switch = {} } end

local function resetRowspanIndexes rowspanIndex = 0 consoleRowspanIndexes = { xbox360 = 0, xbone = 0, ps = 0, wiiu = 0, switch = 0 } end

function p.main(f) local lines = getLines(f)

initRowspans resetRowspanIndexes for _,v in ipairs(lines) do		countRowspan(v) end

resetRowspanIndexes tableHead=0 local result = {} for _,v in ipairs(lines) do		if(tableHead~=1) then table.insert(result, ' ') tableHead = 1 end processLine(v,function(a) table.insert(result, a) end) end return table.concat(result) end

return p