Module:Version

local p = {} local Data = mw.loadData('Module:Version/data')

p.Platform = { PC = 'PC', Xbox = 'Xbox', PS = 'PS', Mobile = 'Mobile', Switch = 'Switch', }

local function _assertPlatformIsValid(platform) assert(p.Platform[platform], "platform must be one of the following (case-sensitive): PC, Xbox, PS, Mobile, Switch") end

local function _assertVersionIsValid(platform, version) assert(Data.ToIndex[platform][version], "unknown version") end

function p.getVersionInfo(platform, version) return Data.Info[platform][p.getVersionIndex(platform, version)] end

function p.getVersionIndex(platform, version) return Data.ToIndex[platform][version] end

function p.getReleaseDate(platform, version) local info = p.getVersionInfo(platform, version) return info and info[2] or nil end

function p.getReleaseDateW(f) _assertPlatformIsValid(f.args[1]) _assertVersionIsValid(f.args[1], f.args[2]) return p.getReleaseDate(f.args[1], f.args[2]) or '' end

function p.getCurrentVersion(platform) return Data.Current[platform] end

function p.getCurrentVersionW(f) _assertPlatformIsValid(f.args[1]) return p.getCurrentVersion(f.args[1]) or '' end

function p.getCurrentVersionReleaseDate(platform) return p.getReleaseDate(platform, Data.Current[platform]) end

function p.getPreviousVersion(platform, version) local index = p.getVersionIndex(platform, version) - 1 return index >= 1 and Data.Info[platform][index][1] or nil end

function p.getPreviousVersionW(f) _assertPlatformIsValid(f.args[1]) _assertVersionIsValid(f.args[1], f.args[2]) return p.getPreviousVersion(f.args[1], f.args[2]) or '' end

function p.getNextVersion(platform, version) local index = p.getVersionIndex(platform, version) + 1 return index <= #(Data.Info[platform]) and Data.Info[platform][index][1] or nil end

function p.getNextVersionW(f) _assertPlatformIsValid(f.args[1]) _assertVersionIsValid(f.args[1], f.args[2]) return p.getNextVersion(f.args[1], f.args[2]) or '' end

function p.isVersionMajor(platform, version) local previous = p.getPreviousVersion(platform, version) if previous == nil then return true end return tonumber(version:match('(%d+)%.')) > tonumber(previous:match('(%d+)%.')) end

function p.isVersionMajorW(f) _assertPlatformIsValid(f.args[1]) _assertVersionIsValid(f.args[1], f.args[2]) return p.isVersionMajor(f.args[1], f.args[2]) and 'Yes' or '' end

function p.getVersionLink(platform, version) if platform == p.Platform.PC then return version end return platform .. ' ' .. version end

function p.getVersionLinkW(f) _assertPlatformIsValid(f.args[1]) _assertVersionIsValid(f.args[1], f.args[2]) return p.getVersionLink(f.args[1], f.args[2]) end

-- prototype A function p.renderVersionListInLineW(f) local platform = f.args[1] local line = tonumber(f.args[2]) local separator = f.args[3] or ' ' local lineMax = f.args[4] and tonumber(f.args[4]) or nil _assertPlatformIsValid(platform) assert(line ~= nil, 'version line must be a number, e.g. 340') if lineMax == nil then lineMax = line - (line%10) + 10 end local versions = {} for _, version in ipairs(Data.Info[platform]) do		local major = tonumber(version[1]:match('(%d+)%.')) if major >= line and major < lineMax then table.insert(versions, string.format('%s', p.getVersionLink(platform, version[1]), version[1])) end end return table.concat(versions, separator) end

-- prototype B function p.renderListOfVersionsInMajorsW(f) local platform = f.args[1] local separator = f.args[2] or ' ' _assertPlatformIsValid(platform) -- Collect major versions from arguments local majors = {} for index, majorToMatch in ipairs(f.args) do		if index > 2 then local major = tonumber(majorToMatch) assert(major ~= nil, 'version major must be a number, e.g. 340') majors[major] = true end end -- Render the list local versions = {} local anyRendered = false for _, version in ipairs(Data.Info[platform]) do		local major = tonumber(version[1]:match('(%d+)%.')) if majors[major] then table.insert(versions, string.format('%s', p.getVersionLink(platform, version[1]), version[1])) anyRendered = true elseif anyRendered then -- We've rendered matching versions and found a mismatch, finish the loop. break end end return table.concat(versions, separator) end

return p