FANDOM


-- <nowiki>
local p = {};
 
function template_args()
    return mw.getCurrentFrame():getParent().args
end
 
function p.translation(frame)
    local args = template_args()
    local ret = ''
    for i, v in ipairs(args) do
        ret = ret .. '{{Translation/element|' .. v .. '}}&nbsp;•&nbsp;'
    end
    return frame:preprocess(ret .. '{' .. '{Translation/element}}')
end
 
function p.joiner(frame)
    local args = template_args() 
    local ret = ''
    local joinText = ''
    if args[1] then
        joinText = args[1]
    end
    for i, v in ipairs(args) do
        if i > 1 then
           ret = ret .. v .. joinText
        end
    end
    ret = string.gsub(ret, joinText .. '$', '')
    return ret
end
 
function p.dots(frame)
    local args = template_args()
    local ret = ''
    for i, v in ipairs(args) do
        ret = ret .. v .. '&nbsp;•&nbsp;'
    end
    ret = string.gsub(ret, '&nbsp;•&nbsp;$', '')
    return ret
end
 
function p.supjoin(frame)
    local args = template_args()
    local ret = ''
    local joins = {}
    local count = 0
 
    -- Leading text 
    if args[1] == '' then
        preText = 'Only&nbsp;'
    else
        preText = args[1] .. '&nbsp;'
    end
 
    -- Count elements to join, and set join text ", "
    for i, v in ipairs(args) do
        joins[i] = ',&nbsp;'
        count = count + 1
    end
 
    -- If more than two, replace last join with "and"
    if count > 3 then
        joins[count - 1] = '&nbsp;and&nbsp;'
    end
 
    -- Build final joined list
    for i, v in ipairs(args) do
        if i > 1 then
            if not (i == count) then
                ret = ret .. v .. joins[i]
            else
                ret = ret .. v
            end
        end
    end
 
    return '<sup>' .. preText .. ret .. '</sup>'
end
 
local mc_abbr =  {
    bedrock = "Bedrock",
    java = "Java Edition",
    console = "Legacy Console Edition",
    ios = "iOS version",
    android = "Android version",
    vr ="VR version",
    win10 ="Windows 10 version"
}
 
function p.mc(frame)
    local args = template_args()
    local ret = ''
    local joins = {}
    local count = 0
 
    -- Leading text 
    preText = "<i>[[Minecraft]]</i>"
 
    -- Count elements to join, and set join text ", "
    for i, v in ipairs(args) do
        joins[i] = ',&nbsp;'
        count = count + 1
    end
 
    -- If more than two, replace last join with "and"
    if count > 2 then
        joins[count - 1] = '&nbsp;and&nbsp;'
    end
 
    -- Build final joined list
    for i, v in ipairs(args) do
        local text = mc_abbr[v] or v
        if not (i == count) then
            ret = ret .. text .. joins[i]
        else
            ret = ret .. text
        end
    end
 
    if count == 0 then
        return preText
    else
        return preText .. '&nbsp;<sup>' .. ret .. '</sup>'
    end
end
 
function p.loop(frame)
    local args = template_args()
    local cols = frame.args[1]
    local template = frame.args[2]
    local ret = ''
    local data = {}
    local del = 0
    if frame.args[3] then
        del = tonumber(frame.args[3])
    end
    for i, v in ipairs(args) do
        local ind = i - del
        local index = math.ceil(ind / cols)
        if ind > 0 then
            if not(data[index]) then
                data[index] = {}
            end
            data[index][((ind - 1) % cols) + 1] = v
        end
    end
    for i, v in ipairs(data) do
        ret = ret .. '{' .. '{' .. template .. '/element|'
        for i2, v2 in ipairs(v) do
            ret = ret .. mw.text.trim(v2) .. '|'
        end
        ret = ret .. '}}'
    end
    return frame:preprocess(ret)
end
 
return p
-- </nowiki>
Community content is available under CC-BY-SA unless otherwise noted.