Difference between revisions of "Module:Map credits"

From Team Fortress Wiki
Jump to: navigation, search
m (Update qmark_langs)
m
 
Line 1: Line 1:
 
local p = {}
 
local p = {}
  
local creditsData = require("Module:Map credits/data")
+
local creditsData = mw.loadData("Module:Map credits/data")
  
 
function format_credit(link, link_type, link_name)
 
function format_credit(link, link_type, link_name)
Line 52: Line 52:
 
     local credits = creditsData
 
     local credits = creditsData
 
     local map_credits = credits[map] or credits._default
 
     local map_credits = credits[map] or credits._default
    local num_credits = #map_credits
+
     local output = {}
     local output = ""
 
  
 
     for i, credit in ipairs(map_credits) do
 
     for i, credit in ipairs(map_credits) do
Line 60: Line 59:
 
         local link_type = options == "nolink" and "nolink" or (credit[3] or "")
 
         local link_type = options == "nolink" and "nolink" or (credit[3] or "")
  
         output = output .. format_credit(link, link_type, name)
+
         table.insert(output, format_credit(link, link_type, name))
        output = output .. (i < num_credits and separator or "")
 
 
     end
 
     end
  
     return output
+
     return table.concat(output, separator)
 
end
 
end
  
 
return p
 
return p

Latest revision as of 20:55, 30 September 2024

Documentation for Map credits

Intended for use in the {{map infobox}} and other tables. Not compatible with custom maps. When adding map credits, include the creator's name exactly as it appears in the in-game credits (see File:tf_english.txt).

Adding more maps

Usage

Syntax

{{map credits|<file name>|separator=<separator>|options=<options>|override=<override>}}

<file name> unnamed parameter 1
Map file name, exactly as it is written in-game.
(optional) <separator>
Separator for maps with multiple people credited. Defaults to <br> .
(optional) <options>
Additional rendering options:
nolink - Disables rendering of links (Steam profile URL, Wikipedia links, etc.).

local p = {}

local creditsData = mw.loadData("Module:Map credits/data")

function format_credit(link, link_type, link_name)
    local if_lang = mw.getCurrentFrame():expandTemplate{title="If lang"}
    local qmark_langs = {
        ["/ar"] = { opening = " «", closing = "» " },
        ["/cs"] = { opening = " „", closing = "“ " },
        ["/es"] = { opening = " «", closing = "» " },
        ["/de"] = { opening = " „", closing = "“ " },
        ["/fr"] = { opening = " « ", closing = " » " },
        ["/ja"] = { opening = "「", closing = "」" },
        ["/pl"] = { opening = " „", closing = "” " },
        ["/ro"] = { opening = " „", closing = '” ' },
        ["/ru"] = { opening = " «", closing = "» " }
    }

    local qmark = qmark_langs[if_lang]
    if qmark then
        local openingMark = qmark.opening
        local closingMark = qmark.closing
        local openingIndex, closingIndex = link_name:find(' "'), link_name:find('" ', 2)

        if openingIndex and closingIndex then
            link_name = link_name:gsub(' "', openingMark, 1)
            link_name = link_name:gsub('" ', closingMark, 1)
        end
    end

    -- Link types
    local formats = {
        ["nolink"] = link_name,
        ["yeslink"] = link,
        ["wikitext"] = "[[%s" .. if_lang .. "|%s]]",
        ["steam"] = "[https://steamcommunity.com/profiles/%s %s]",
        ["external"] = "[%s %s]",
        ["wikipedia"] = "[[w:%s|%s]]"  -- TODO: figure out how to make this thing translatable. Use dictionary?
    }

    local format = formats[link_type] or link_name

    return string.format(format, link, link_name)
end

function p.credits(f)
    local args = f.args
    local map = args[1]
    local separator = args.separator ~= "" and args.separator or "<br>"
    local options = args.options ~= "" and args.options or ""
    local override = args.override ~= "" and args.override or ""
    local credits = creditsData
    local map_credits = credits[map] or credits._default
    local output = {}

    for i, credit in ipairs(map_credits) do
        local name = override ~= "" and override or credit[1]
        local link = credit[2] or ""
        local link_type = options == "nolink" and "nolink" or (credit[3] or "")

        table.insert(output, format_credit(link, link_type, name))
    end

    return table.concat(output, separator)
end

return p