Jump to content

Module:ShipInfobox: Difference between revisions

From Elite Dangerous Wiki
Content deleted Content added
No edit summary
No edit summary
Line 53: Line 53:
function Infobox.Internals( field, vars )
function Infobox.Internals( field, vars )
--
--
end
end


Line 59: Line 60:
local u = field.Utility
local u = field.Utility
local hplabel = lang:plural(u, 'Hardpoint', 'Hardpoints')
local hplabel = lang:plural(u, 'Hardpoint', 'Hardpoints')
local s, m, l, h = field.S, field.M, field.L, field.H
local matroska = nil
local output = {}
local output = {}
if (u) then
if (u) then
table.insert(output, u .. 'x Utility ' .. lang:plural(u, 'Mount', 'Mounts'))
table.insert(output, u .. 'x Utility ' .. lang:plural(u, 'Mount', 'Mounts'))
matroska = true
end
end
if (s) then
if (field.S) then
if (u) then table.insert(output, '<br />') end
if (matroska) then table.insert(output, '<br />') end
table.insert(output, s .. 'x Small ' .. hplabel)
table.insert(output, field.S .. 'x Small ' .. hplabel)
matroska = true
end
end
if (m) then
if (field.M) then
if (u or s) then table.insert(output, '<br />') end
if (matroska) then table.insert(output, '<br />') end
table.insert(output, m .. 'x Medium ' .. hplabel)
table.insert(output, field.M .. 'x Medium ' .. hplabel)
matroska = true
end
end
if (l) then
if (field.L) then
if (u or s or m) then table.insert(output, '<br />') end
if (matroska) then table.insert(output, '<br />') end
table.insert(output, l .. 'x Large ' .. hplabel)
table.insert(output, field.L .. 'x Large ' .. hplabel)
matroska = true
end
end
if (h) then
if (field.H) then
if (u or s or m or l) then table.insert(output, '<br />') end
if (matroska) then table.insert(output, '<br />') end
table.insert(output, h .. 'x Huge ' .. hplabel)
table.insert(output, field.H .. 'x Huge ' .. hplabel)
end
end
return table.concat( output )
return table.concat( output )

Revision as of 02:30, 23 May 2015

Documentation for this module may be created at Module:ShipInfobox/doc

local Infobox = {}
local HF = require('Module:HF')
local lang = mw.language.new('en')

-- This avoids using the {{#if:{{{factionreq|}}}||}} ParserFunction.
local function isempty(s)
  local result = false
  if type(s) == "nil" then
    result = true
  elseif type(s) == "string" then
    if s == "" then
      result = true
    end
  elseif type(s) == "table" then
    if next(s) == nil then
      result = true
    end
  end
  return result
end

function Infobox.Factionreq( field, vars )
    -- Rather than ParserFunctions, try passing your variables this way. 
    local text = 'Requires '.. field.Requirement ..' rank of '.. field.Rank ..' or higher'
    if not isempty(field.Requirement) then
        -- Use mw.html for the best HTML output.
        local output = mw.html.create('span')
        :addClass('factionreq'):wikitext(text)
        return tostring(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 isempty(value) then 
        return '---'
    else
        return value .. ' ' .. unit
    end
end

function Infobox.Insurance( field, vars )
    -- replaces {{#if:{{{cost|}}}|{{formatnum:{{#expr:trunc({{formatnum:{{{cost|}}}|R}}*0.05)}}}} CR|}}
    local insurance = field.Cost or ''
    if not isempty(insurance) then
        return math.floor(tonumber(insurance) * 0.05) .. 'CR'
    else return ''
    end
end

function Infobox.Internals( field, vars )
    --
    
end

function Infobox.Hardpoints( field, vars )
    --
    local u = field.Utility
    local hplabel = lang:plural(u, 'Hardpoint', 'Hardpoints')
    local matroska = nil
    local output = {}
    if (u) then 
        table.insert(output, u .. 'x Utility ' .. lang:plural(u, 'Mount', 'Mounts'))
        matroska = true
    end
    if (field.S) then
        if (matroska) then table.insert(output, '<br />') end
        table.insert(output, field.S .. 'x Small ' .. hplabel)
        matroska = true
    end
    if (field.M) then
        if (matroska) then table.insert(output, '<br />') end
        table.insert(output, field.M .. 'x Medium ' .. hplabel)
        matroska = true
    end
    if (field.L) then
        if (matroska) then table.insert(output, '<br />') end
        table.insert(output, field.L .. 'x Large ' .. hplabel)
        matroska = true
    end
    if (field.H) then
        if (matroska) then table.insert(output, '<br />') end
        table.insert(output, field.H .. 'x Huge ' .. hplabel)
    end
    return table.concat( output )
end

return Infobox