WARFRAME Wiki
Advertisement
WARFRAME Wiki


Version stores all build versions of WARFRAME based on their update/hotfix designation.

On this Wiki, Version is used in:

Usage

Direct Invocation

{{#invoke:Version|function|input1|input2|...}}

Template

In template: {{#invoke:Ver|function|input1|input2|...}}
In articles: {{Ver|input1|input2|...}}

Module

local p = {}
local Ver = require('Module:Version')

local function func(input)
    return Ver.getVersion(input)
end

Documentation

Package items

version._getVersionCategory(name) (function)
Gets the category page link associated with that version.
Parameter: name Version alias (e.g. 'U26' or 'H30.3.5') (string)
Returns: Version entry as seen in /data (table)
version.getVersion(name) (function)
Gets a version by name or by alias, case insensitive.
Parameter: name (string)
Returns:
  • Version entry as seen in /data (table)
  • Entry index (number)
version.getVersionLink(frame) (function)
Gets a version's link.
Parameter: frame (table)
Returns: Wikitext of version article link (string)
version._getVersionLink(name, color, short) (function)
Gets a version's link.
Parameters:
  • name (string)
  • color (string)
  • short (string)
Returns: Wikitext of version article link (string)
version._getVersionDate(name) (function)
Gets a version's date.
Parameter: name (string)
Returns: ISO date (string)
version.getToCLines(frame) (function)
Creates all lines for table of contents.
Parameter: frame (table)
Returns: Wikitext of the table of contents (string)
version.getAllVersions(frame) (function)
Lists all versions of the game.
Parameter: frame (table)
Returns: Wikitext of version list (string)
version.lastVersion(frame) (function)
Returns the latest version of the game.
Parameter: frame (table)
Returns: Wikitext of version (string)

Created with Docbuntu

See Also

Code


---	'''Version''' stores all build versions of [[WARFRAME]] based on their update/hotfix designation.<br />
--	
--	On this Wiki, Version is used in:
--	* [[Template:Ver]]
--	* [[Template:Ver/Lu]]
--	
--	@module		version
--	@alias		p
--	@author		[[User:Flaicher|Flaicher]]
--	@attribution	[[User:Falterfire|Falterfire]]
--	@attribution	[[User:Cephalon Scientia|Cephalon Scientia]]
--	@image		Launcher (English Version).png
--	@require	[[Module:Version/data]]
--	@require	[[Module:Shared]]
--	@require	[[Module:String]]
--	@release	stable
--	<nowiki>

local p = {}

local VersionData = mw.loadData( [[Module:Version/data]] )
local Shared = require( [[Module:Shared]] )	-- TODO: Replace M:Shared with M:Table
local String = require( [[Module:String]])

---	Gets the category page link associated with that version.
--	@function		p._getVersionCategory
--	@param			{string} name Version alias (e.g. 'U26' or 'H30.3.5')
--	@return			{table} Version entry as seen in <code>/data</code>
function p._getVersionCategory(name)
    assert(name ~= nil, 'p._getVersionCategory(name): name cannot be nil, must put in a version name')
    assert(VersionData['Aliases'][name] ~= nil, 'p._getVersionCategory(name): version name "'..name..'" does not exist in [[Module:Version/data]]')
    
    local parentUpdateAlias = VersionData['Aliases'][name]['Parent']
    -- The number before the decimal point is the first mainline update that starts with that number
	local updateNum = string.gsub(parentUpdateAlias, '(.+).(.+)', '%1')
	
	-- If parent update alias starts with a 0, that means update was a closed beta one
	if (updateNum == 0) then
		return '[[Category:Closed Beta]]'
	end
	
    return '[[Category:Update '..updateNum..']]'
end

---	Gets a version by name or by alias, case insensitive.
--	@function		p.getVersion
--	@param			{string} name
--	@return			{table} Version entry as seen in <code>/data</code>
--	@return			{number} Entry index
function p._getVersion(name)
    assert(name ~= nil, 'p._getVersion(name): name cannot be nil, must put in a version name')
    
    for i, Version in pairs(VersionData["Versions"]) do
        if(string.upper(Version.Name) == string.upper(name) or string.upper(Version.ShortName) == string.upper(name)) then
            return Version, i
        elseif(Version.Aliases ~= nil and Shared.contains(Version.Aliases, name, true)) then
            return Version, i
        end
    end

    error('p._getVersion(name): Version "'..name..'" not found (add to [[Module:Version/data]] if needed)')
end

---	Gets a version's link.
--	@function		p.getVersionLink
--	@param			{table} frame
--	@return			{string} Wikitext of version article link
function p.getVersionLink(frame)
    local name = frame.args ~= nil and frame.args[1] or frame
    local color = frame.args ~= nil and frame.args.color or nil
    local short = frame.args ~= nil and frame.args.short or "false"
    return p._getVersionLink(name, color, short)
end

---	Gets a version's link.
--	@function		p._getVersionLink
--	@param			{string} name
--	@param			{string} color
--	@param			{string} short
--	@return			{string} Wikitext of version article link
function p._getVersionLink(name, color, short)
	local Version = p._getVersion(String.trim(name))
    local name = ''
    local date = ''
    
    if short ~= nil and string.upper(short) == "TRUE" then
        name = Version.ShortName
    else
        name = Version.Name
        date = ' ('..Version.Date..')'
    end
    
    assert(Version ~= nil, 'p._getVersionLink(name, color, short): version name "'..name..'" not found (add to [[Module:Version/data]] if needed)')
    
    if color ~= nil then
        return "[["..Version.Link.."|<span style=\"color:"..color..";\">"..name.."</span>]]"..date
    end
    return "[["..Version.Link.."|"..name.."]]"..date
end

---	Gets a version's date.
--	@function		p._getVersionDate
--	@param			{string} name
--	@return			{string} ISO date
function p._getVersionDate(name)
    local Version = p._getVersion(name)
    assert(Version ~= nil, 'p._getVersionDate(name): version name "'..name..'" not found (add to [[Module:Version/data]] if needed)')
    return Version.Date
end

--- Creates a line for table of contents.
--	@function		getToCLine
--	@param			{string} parent Parent version
--	@return			{string} Wikitext of a line in the table of contents
local function getToCLine(parent)
    local prevParent = nil
    local result = ""
    local LinkTemp ={}
    
    -- TODO: Refactor so there is not many nested code blocks
    for j, Version in pairs(VersionData["Versions"]) do
        local bracket = "[["--reseting the brackets
        local bracket2 = "]]"
        
        if Version.Parent == parent then
            if prevParent == nil then --check if we've been here before
                if Version.ParentName ~= nil then
                    result = "'''"..Version.ParentName..":''' "
                else
                    result = "'''Update "..Version.Parent..":''' "
                end
            elseif prevParent ~= nil then --been here -> add spacer
                result = result.." • "
            end
            local shortname = string.upper(string.sub(Version.ShortName,1,1)) --getting the first letter
            if shortname == "U" or shortname == "V" then --bolding the link if Update or Vanilla
                bracket = "'''[["
                bracket2 = "]]'''"
            end
            LinkTemp = mw.text.split(Version.Link, "#", true)--since ToC is used on Update pages only, and only [[#"Header"|"Name"]] links work in edit mode -> split the link and use second part of it on the next line
            result = result..bracket.."#"..LinkTemp[2].."|"..Version.ShortName..bracket2
            prevParent = Version.Parent --for checking if been in this "if" yet
        elseif prevParent ~= nil then -- ->return result if parent switches. The data is ordered so there's no need to loop through the rest for nothing
            return result
        end
    end
    return result --required for the latest update as the previous return's "if" doesn't come up true as it reaches the end of the data
end

--- Gets all parent version strings of a certain update version
--	@function		getToCAllParents
--	@param			{string} parent Parent version (e.g. 0=Closed beta, 7=U7, 12=U12, etc.)
--	@return			{string} Wikitext
local function getToCAllParents(parent)
    local parents ={}
    local hash = {}
    local parentTemp = {}
    local result = ""
    for j, Version in pairs(VersionData["Versions"]) do
        if not hash[Version.Parent] then --if this Version.Parent isn't in table hash, then
            parentTemp = mw.text.split(Version.Parent, ".", true) --splitting the Parent to a temp table
            if parent == parentTemp[1] then --comparing the function input(parent) and the temp table's first string
                parents[#parents+1] = Version.Parent --if true, add the current V.Parent to table parents at position 1+current lenght
                hash[Version.Parent] = true --add V.Parent to table "hash" and assign value "true" to the V.Parent to prevent duplicate entries in table "parents"
            end
        end
    end
    return parents
end

--- Creates all lines for table of contents.
--	@function		p.getToCLines
--	@param			{table} frame
--	@return			{string} Wikitext of the table of contents
function p.getToCLines(frame)
    local parent = frame.args ~= nil and frame.args[1] or frame
    local result = ''
    local parents = getToCAllParents(parent)
    for i,v in pairs(parents) do
        result = result..getToCLine(v)
        if i < #parents then
            result = result.."<br>"
        end
    end
	assert(result ~= '', 'p.getToCLines(frame): Parent version "'..parent..'" is not a valid version')
    return result
end

--- Lists all versions of the game.
--	@function		p.getAllVersions
--	@param			{table} frame
--	@return			{string} Wikitext of version list
function p.getAllVersions(frame)
	-- TODO: Store result in a table and table.concat() in the end instead of concantenating multiple strings
    local result = ''
    for i, v in pairs(VersionData["Versions"]) do
        result = result..'\n* '..p.getVersionLink(v.Name)
    end
    return result
end

--- Returns the latest version of the game.
--	@function		p.lastVersion
--	@param			{table} frame
--	@return			{string} Wikitext of version
function p.lastVersion(frame)
    local color = frame.args["color"]
    local uCount = 0
    for b, update in pairs(VersionData["Versions"]) do
        uCount = uCount + 1
    end
    local latestUpdate = VersionData["Versions"][uCount]
    if color ~= nil then
        return '[['..latestUpdate.Link..'|<span style="color:'..color..';">'..latestUpdate.Name..'</span>]]'
	end
    return '[['..latestUpdate.Link..'|'..latestUpdate.Name..']]'
end

return p