FANDOM


local Infobox = {}
local HF = require('Module:HF')
local FormatNum = require('Module:FormatNum')
local lang = mw.language.new('en')
 
-- if a variable is required, this logic hides them if variable is empty
function Infobox.Required( field, vars )
    -- Rather than ParserFunctions, try passing your variables this way. 
    local output = ''
    if not HF.isempty(field.Requirement) then
        output = field.Value
        return tostring(output)
    end
    return output
end  
 
function Infobox.Factionreq( field, vars )
    local output = ''
    if not HF.isempty(field.Value) then
        output = '[[' .. field.Value .. ']]'
        return output
    end
end
 
-- replaces {{#if:{{{topspeed|}}}|{{{topspeed|?}}} m/s|---}} logic
function Infobox.Quantify( field, vars )
    local unit = field.Unit or ''
    local value = field.Value or field.Default or '?'
    if HF.isempty(value) then 
        return '---'
    else
        return value .. ' ' .. unit
    end
end
 
-- fixes numbers with commas, e.g: 4,323
function Infobox.FormatCost( field, vars )
    if HF.isempty(field.Value) then
        return '---'
    else
        field.Value = FormatNum.commavalue(field.Value:gsub(',',''))
        return Infobox.Quantify(field, vars)
    end
end
 
function Infobox.Insurance( field, vars )
    -- replaces {{#if:{{{cost|}}}|{{formatnum:{{#expr:trunc({{formatnum:{{{cost|}}}|R}}*0.05)}}}} CR|}}
    local insurance = field.Cost:gsub(',','')
    if not HF.isempty(insurance) then
        return FormatNum.commavalue(math.floor(tonumber(insurance) * 0.05)) .. ' CR'
    else return ''
    end
end
 
function Infobox.Internals( field, vars )
    local matroska = nil
    local output = {}
    if not HF.isempty(field.S1) then 
        table.insert(output, field.S1 .. 'x Size 1 ' .. 
            lang:plural( tonumber(field.S1), 'Compartment', 'Compartments'))
        matroska = true
    end
    if not HF.isempty(field.S2) then 
        if (matroska) then table.insert(output, '<br />') end
        table.insert(output, field.S2 .. 'x Size 2 ' .. 
            lang:plural( tonumber(field.S2), 'Compartment', 'Compartments'))
        matroska = true
    end
    if not HF.isempty(field.S3) then 
        if (matroska) then table.insert(output, '<br />') end
        table.insert(output, field.S3 .. 'x Size 3 ' .. 
            lang:plural( tonumber(field.S3), 'Compartment', 'Compartments'))
        matroska = true
    end
    if not HF.isempty(field.S4) then 
        if (matroska) then table.insert(output, '<br />') end
        table.insert(output, field.S4 .. 'x Size 4 ' .. 
            lang:plural( tonumber(field.S4), 'Compartment', 'Compartments'))
        matroska = true
    end
    if not HF.isempty(field.S5) then 
        if (matroska) then table.insert(output, '<br />') end
        table.insert(output, field.S5 .. 'x Size 5 ' .. 
            lang:plural( tonumber(field.S5), 'Compartment', 'Compartments'))
        matroska = true
    end
    if not HF.isempty(field.S6) then 
        if (matroska) then table.insert(output, '<br />') end
        table.insert(output, field.S6 .. 'x Size 6 ' .. 
            lang:plural( tonumber(field.S6), 'Compartment', 'Compartments'))
        matroska = true
    end
    if not HF.isempty(field.S7) then 
        if (matroska) then table.insert(output, '<br />') end
        table.insert(output, field.S7 .. 'x Size 7 ' .. 
            lang:plural( tonumber(field.S7), 'Compartment', 'Compartments'))
        matroska = true
    end
    if not HF.isempty(field.S8) then 
        if (matroska) then table.insert(output, '<br />') end
        table.insert(output, field.S8 .. 'x Size 8 ' .. 
            lang:plural( tonumber(field.S8), 'Compartment', 'Compartments'))
        matroska = true
    end
    if not HF.isempty(field.R1) then 
        if (matroska) then table.insert(output, '<br />') end
        table.insert(output, field.R1 .. 'x Size 1 [[Reserved Compartment|Reserved ]]' .. 
            lang:plural( tonumber(field.R1), 'Compartment', 'Compartments'))
        matroska = true
    end
    if not HF.isempty(field.R2) then 
        if (matroska) then table.insert(output, '<br />') end
        table.insert(output, field.R2 .. 'x Size 2 [[Reserved Compartment|Reserved ]]' .. 
            lang:plural( tonumber(field.R2), 'Compartment', 'Compartments'))
        matroska = true
    end
    if not HF.isempty(field.R3) then 
        if (matroska) then table.insert(output, '<br />') end
        table.insert(output, field.R3 .. 'x Size 3 [[Reserved Compartment|Reserved ]]' .. 
            lang:plural( tonumber(field.R3), 'Compartment', 'Compartments'))
        matroska = true
    end
    if not HF.isempty(field.R4) then 
        if (matroska) then table.insert(output, '<br />') end
        table.insert(output, field.R4 .. 'x Size 4 [[Reserved Compartment|Reserved ]]' .. 
            lang:plural( tonumber(field.R4), 'Compartment', 'Compartments'))
        matroska = true
    end
    if not HF.isempty(field.R5) then 
        if (matroska) then table.insert(output, '<br />') end
        table.insert(output, field.R5 .. 'x Size 5 [[Reserved Compartment|Reserved ]]' .. 
            lang:plural( tonumber(field.R5), 'Compartment', 'Compartments'))
        matroska = true
    end
    if not HF.isempty(field.R6) then 
        if (matroska) then table.insert(output, '<br />') end
        table.insert(output, field.R6 .. 'x Size 6 [[Reserved Compartment|Reserved ]]' .. 
            lang:plural( tonumber(field.R6), 'Compartment', 'Compartments'))
        matroska = true
    end
    if not HF.isempty(field.R7) then 
        if (matroska) then table.insert(output, '<br />') end
        table.insert(output, field.R7 .. 'x Size 7 [[Reserved Compartment|Reserved ]]' .. 
            lang:plural( tonumber(field.R7), 'Compartment', 'Compartments'))
        matroska = true
    end
    if not HF.isempty(field.R8) then 
        if (matroska) then table.insert(output, '<br />') end
        table.insert(output, field.R8 .. 'x Size 8 [[Reserved Compartment|Reserved ]]' .. 
            lang:plural( tonumber(field.R8), 'Compartment', 'Compartments'))
        matroska = true
    end
    if not HF.isempty(field.M1) then 
        if (matroska) then table.insert(output, '<br />') end
        table.insert(output, field.M1 .. 'x Size 1 [[Military Compartment|Military ]]' .. 
            lang:plural( tonumber(field.M1), 'Compartment', 'Compartments'))
        matroska = true
    end
    if not HF.isempty(field.M2) then 
        if (matroska) then table.insert(output, '<br />') end
        table.insert(output, field.M2 .. 'x Size 2 [[Military Compartment|Military ]]' .. 
            lang:plural( tonumber(field.M2), 'Compartment', 'Compartments'))
        matroska = true
    end
    if not HF.isempty(field.M3) then 
        if (matroska) then table.insert(output, '<br />') end
        table.insert(output, field.M3 .. 'x Size 3 [[Military Compartment|Military ]]' .. 
            lang:plural( tonumber(field.M3), 'Compartment', 'Compartments'))
        matroska = true
    end
    if not HF.isempty(field.M4) then 
        if (matroska) then table.insert(output, '<br />') end
        table.insert(output, field.M4 .. 'x Size 4 [[Military Compartment|Military ]]' .. 
            lang:plural( tonumber(field.M4), 'Compartment', 'Compartments'))
        matroska = true
    end
    if not HF.isempty(field.M5) then 
        if (matroska) then table.insert(output, '<br />') end
        table.insert(output, field.M5 .. 'x Size 5 [[Military Compartment|Military ]]' .. 
            lang:plural( tonumber(field.M5), 'Compartment', 'Compartments'))
        matroska = true
    end
    if not HF.isempty(field.M6) then 
        if (matroska) then table.insert(output, '<br />') end
        table.insert(output, field.M6 .. 'x Size 6 [[Military Compartment|Military ]]' .. 
            lang:plural( tonumber(field.M6), 'Compartment', 'Compartments'))
        matroska = true
    end
    if not HF.isempty(field.M7) then 
        if (matroska) then table.insert(output, '<br />') end
        table.insert(output, field.M7 .. 'x Size 7 [[Military Compartment|Military ]]' .. 
            lang:plural( tonumber(field.M7), 'Compartment', 'Compartments'))
        matroska = true
    end
    if not HF.isempty(field.M8) then 
        if (matroska) then table.insert(output, '<br />') end
        table.insert(output, field.M8 .. 'x Size 8 [[Military Compartment|Military ]]' .. 
            lang:plural( tonumber(field.M8), 'Compartment', 'Compartments'))
        matroska = true
    end
    if not HF.isempty(field.Reserved) then 
        if (matroska) then table.insert(output, '<br />') end
        table.insert(output, field.Reserved)
    end
    if not HF.isempty(field.Military) then 
        if (matroska) then table.insert(output, '<br />') end
        table.insert(output, field.Military .. 'x [[Military Compartment|Military]] ' .. 
            lang:plural( tonumber(field.Military), 'Compartment', 'Compartments'))
        matroska = true
    end
    return table.concat(output)
end
 
function Infobox.Hardpoints( field, vars )
    local matroska = nil
    local output = {}
    if not HF.isempty(field.Utility) then 
        table.insert(output, field.Utility .. 'x Utility ' ..
            lang:plural( tonumber(field.Utility), 'Mount', 'Mounts'))
        matroska = true
    end
    if not HF.isempty(field.S) then
        if (matroska) then table.insert(output, '<br />') end
        table.insert(output, field.S .. 'x Small ' .. 
            lang:plural( tonumber(field.S), 'Hardpoint', 'Hardpoints'))
        matroska = true
    end
    if not HF.isempty(field.M) then
        if (matroska) then table.insert(output, '<br />') end
        table.insert(output, field.M .. 'x Medium ' .. 
            lang:plural( tonumber(field.M), 'Hardpoint', 'Hardpoints'))
        matroska = true
    end
    if not HF.isempty(field.L) then
        if (matroska) then table.insert(output, '<br />') end
        table.insert(output, field.L .. 'x Large ' ..
            lang:plural( tonumber(field.L), 'Hardpoint', 'Hardpoints'))
        matroska = true
    end
    if not HF.isempty(field.H) then
        if (matroska) then table.insert(output, '<br />') end
        table.insert(output, field.H .. 'x Huge '  .. 
            lang:plural( tonumber(field.H), 'Hardpoint', 'Hardpoints'))
    end
    return table.concat( output )
end
 
function Infobox.MaxCargo ( field, vars )
    local output = ''
    local number = 0
    if HF.isempty(field.Cargo) then
        if not HF.isempty(field.S1) then 
            number = number + (tonumber(field.S1) * 2)
        end
        if not HF.isempty(field.S2) then 
            number = number + (tonumber(field.S2) * 4)
        end
        if not HF.isempty(field.S3) then 
            number = number + (tonumber(field.S3) * 8)
        end
        if not HF.isempty(field.S4) then 
            number = number + (tonumber(field.S4) * 16)
        end
        if not HF.isempty(field.S5) then 
            number = number + (tonumber(field.S5) * 32)
        end
        if not HF.isempty(field.S6) then 
            number = number + (tonumber(field.S6) * 64)
        end
        if not HF.isempty(field.S7) then 
            number = number + (tonumber(field.S7) * 128)
        end
        if not HF.isempty(field.S8) then 
            number = number + (tonumber(field.S8) * 256)
        end
        if number == 0 then
            output = "---"
        else
            output = tostring(number)
        end
    else
        output = field.Cargo
    end
    field.Value = output
    return Infobox.Quantify(field, vars)
end
 
return Infobox

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.