Module:Sandbox/History

local p = {} local Hmode = nil local Hver = nil local HV = { xbox360 = nil, xbone = nil, ps = nil, wiiu = nil, switch = nil } local HVindex local HVrowspan local Hindex local Hrowspan 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" }

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

function resetCon HV.xbox360 = nil HV.xbone = nil HV.ps = nil HV.wiiu = nil HV.switch = nil end

function reset Hver = nil resetCon end

function footReset Hmode = nil reset end

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 (Hmode=='realms')) then return text end local c			if(not isSnap) then if(text=='Pre-release' and Hmode == 'pocket Alpha') then c = 'pocket Pre-release' else c= (versionLinks[Hmode] or Hmode)..' '..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=Hver..' '..text elseif(c:match('^pre')) then c=Hver..'-'..text elseif(c:match('^release')) then c=Hver else c = text end c=(versionLinks[Hmode] or Hmode)..' '..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

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

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

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 mode = (args[1]):lower if (mode == 'foot') then prnt(' ') footReset Hhead = 0 return end Hmode = editionAlias[mode] or mode reset prnt(' ') prnt(headerText[Hmode] or (.. Hmode ..)) prnt(' ') return end

--Content rows

prnt(' ')

if((Hmode == 'console') and (args.xbox or args.xbone or args.ps or args.wiiu or args.switch )) then Hver = 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:

resetCon if((args.snap == nil) or (args[2] and args[2]~='' and (args[2] ~= Hver))) then Hver = 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

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

function countConsoleRowspan(platform,version,snapRows) if((version~=nil and version == HV[platform]) or (version==nil and HV[platform]~=nil)) then HVrowspan[platform][HVindex[platform]] = HVrowspan[platform][HVindex[platform]] + snapRows return end HV[platform] = version or "none" HVindex[platform] = HVindex[platform] + 1 HVrowspan[platform][HVindex[platform]] = (HVrowspan[platform][HVindex[platform]] or 0) + snapRows end

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 mode = (args[1]):lower if (mode == 'foot') then footReset return end Hmode = editionAlias[mode] or mode reset return end

--Content rows

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

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

--Other versions:

resetCon if((args.snap == nil) or (args[2] and args[2]~='' and (args[2] ~= Hver))) then Hver = nil if( args.snap ~= nil) then Hver = args[2] Hindex = Hindex + 1 end end

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

function initRowspan Hrowspan = {} HVrowspan = { xbox360 = {}, xbone = {}, ps = {}, wiiu = {}, switch = {} } end

function initRowspanIndex Hindex = 0 HVindex = { xbox360 = 0, xbone = 0, ps = 0, wiiu = 0, switch = 0 } end

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

initRowspan initRowspanIndex for k,v in ipairs(lines) do		countRowspan(v) end

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

return p