Module:ShipInfobox: Difference between revisions
Appearance
Content deleted Content added
No edit summary |
No edit summary |
||
| Line 56: | Line 56: | ||
if not isempty(field.S1) then |
if not isempty(field.S1) then |
||
table.insert(output, field.S1 .. 'x Size 1 ' .. |
table.insert(output, field.S1 .. 'x Size 1 ' .. |
||
lang:plural( |
lang:plural( field.S1, 'Compartment', 'Compartments')) |
||
matroska = true |
matroska = true |
||
end |
end |
||
| Line 62: | Line 62: | ||
if (matroska) then table.insert(output, '<br />') end |
if (matroska) then table.insert(output, '<br />') end |
||
table.insert(output, field.S2 .. 'x Size 2 ' .. |
table.insert(output, field.S2 .. 'x Size 2 ' .. |
||
lang:plural( |
lang:plural( field.S2, 'Compartment', 'Compartments')) |
||
matroska = true |
matroska = true |
||
end |
end |
||
| Line 68: | Line 68: | ||
if (matroska) then table.insert(output, '<br />') end |
if (matroska) then table.insert(output, '<br />') end |
||
table.insert(output, field.S3 .. 'x Size 3 ' .. |
table.insert(output, field.S3 .. 'x Size 3 ' .. |
||
lang:plural( |
lang:plural( field.S3, 'Compartment', 'Compartments')) |
||
matroska = true |
matroska = true |
||
end |
end |
||
| Line 74: | Line 74: | ||
if (matroska) then table.insert(output, '<br />') end |
if (matroska) then table.insert(output, '<br />') end |
||
table.insert(output, field.S4 .. 'x Size 4 ' .. |
table.insert(output, field.S4 .. 'x Size 4 ' .. |
||
lang:plural( |
lang:plural( field.S4, 'Compartment', 'Compartments')) |
||
matroska = true |
matroska = true |
||
end |
end |
||
| Line 80: | Line 80: | ||
if (matroska) then table.insert(output, '<br />') end |
if (matroska) then table.insert(output, '<br />') end |
||
table.insert(output, field.S5 .. 'x Size 5 ' .. |
table.insert(output, field.S5 .. 'x Size 5 ' .. |
||
lang:plural( |
lang:plural( field.S5, 'Compartment', 'Compartments')) |
||
matroska = true |
matroska = true |
||
end |
end |
||
| Line 86: | Line 86: | ||
if (matroska) then table.insert(output, '<br />') end |
if (matroska) then table.insert(output, '<br />') end |
||
table.insert(output, field.S6 .. 'x Size 6 ' .. |
table.insert(output, field.S6 .. 'x Size 6 ' .. |
||
lang:plural( |
lang:plural( field.S6, 'Compartment', 'Compartments')) |
||
matroska = true |
matroska = true |
||
end |
end |
||
| Line 92: | Line 92: | ||
if (matroska) then table.insert(output, '<br />') end |
if (matroska) then table.insert(output, '<br />') end |
||
table.insert(output, field.S7 .. 'x Size 7 ' .. |
table.insert(output, field.S7 .. 'x Size 7 ' .. |
||
lang:plural( |
lang:plural( field.S7, 'Compartment', 'Compartments')) |
||
matroska = true |
matroska = true |
||
end |
end |
||
| Line 98: | Line 98: | ||
if (matroska) then table.insert(output, '<br />') end |
if (matroska) then table.insert(output, '<br />') end |
||
table.insert(output, field.S8 .. 'x Size 8 ' .. |
table.insert(output, field.S8 .. 'x Size 8 ' .. |
||
lang:plural( |
lang:plural( field.S8, 'Compartment', 'Compartments')) |
||
matroska = true |
matroska = true |
||
end |
end |
||
| Line 108: | Line 108: | ||
function Infobox.Hardpoints( field, vars ) |
function Infobox.Hardpoints( field, vars ) |
||
local u |
|||
if not isempty(field.Utility) then |
|||
| ⚫ | |||
else |
|||
u = 0 |
|||
end |
|||
| ⚫ | |||
local matroska = nil |
local matroska = nil |
||
local output = {} |
local output = {} |
||
if ( |
if not isempty(field.Utility) then |
||
table.insert(output, |
table.insert(output, field.Utility .. 'x Utility ' .. |
||
| ⚫ | |||
matroska = true |
matroska = true |
||
end |
end |
||
if not isempty(field.S) then |
if not isempty(field.S) then |
||
if (matroska) then table.insert(output, '<br />') end |
if (matroska) then table.insert(output, '<br />') end |
||
table.insert(output, field.S .. 'x Small ' .. |
table.insert(output, field.S .. 'x Small ' .. |
||
| ⚫ | |||
matroska = true |
matroska = true |
||
end |
end |
||
if not isempty(field.M) then |
if not isempty(field.M) then |
||
if (matroska) then table.insert(output, '<br />') end |
if (matroska) then table.insert(output, '<br />') end |
||
table.insert(output, field.M .. 'x Medium ' .. |
table.insert(output, field.M .. 'x Medium ' .. |
||
lang:plural( field.M, 'Hardpoint', 'Hardpoints')) |
|||
matroska = true |
matroska = true |
||
end |
end |
||
if not isempty(field.L) then |
if not isempty(field.L) then |
||
if (matroska) then table.insert(output, '<br />') end |
if (matroska) then table.insert(output, '<br />') end |
||
table.insert(output, field.L .. 'x Large ' .. |
table.insert(output, field.L .. 'x Large ' .. |
||
lang:plural( field.L, 'Hardpoint', 'Hardpoints')) |
|||
matroska = true |
matroska = true |
||
end |
end |
||
if not isempty(field.H) then |
if not isempty(field.H) then |
||
if (matroska) then table.insert(output, '<br />') end |
if (matroska) then table.insert(output, '<br />') end |
||
table.insert(output, field.H .. 'x Huge ' .. |
table.insert(output, field.H .. 'x Huge ' .. |
||
lang:plural( field.H, 'Hardpoint', 'Hardpoints')) |
|||
end |
end |
||
return table.concat( output ) |
return table.concat( output ) |
||
Revision as of 03:33, 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 )
local matroska = nil
local output = {}
if not isempty(field.S1) then
table.insert(output, field.S1 .. 'x Size 1 ' ..
lang:plural( field.S1, 'Compartment', 'Compartments'))
matroska = true
end
if not isempty(field.S2) then
if (matroska) then table.insert(output, '<br />') end
table.insert(output, field.S2 .. 'x Size 2 ' ..
lang:plural( field.S2, 'Compartment', 'Compartments'))
matroska = true
end
if not isempty(field.S3) then
if (matroska) then table.insert(output, '<br />') end
table.insert(output, field.S3 .. 'x Size 3 ' ..
lang:plural( field.S3, 'Compartment', 'Compartments'))
matroska = true
end
if not isempty(field.S4) then
if (matroska) then table.insert(output, '<br />') end
table.insert(output, field.S4 .. 'x Size 4 ' ..
lang:plural( field.S4, 'Compartment', 'Compartments'))
matroska = true
end
if not isempty(field.S5) then
if (matroska) then table.insert(output, '<br />') end
table.insert(output, field.S5 .. 'x Size 5 ' ..
lang:plural( field.S5, 'Compartment', 'Compartments'))
matroska = true
end
if not isempty(field.S6) then
if (matroska) then table.insert(output, '<br />') end
table.insert(output, field.S6 .. 'x Size 6 ' ..
lang:plural( field.S6, 'Compartment', 'Compartments'))
matroska = true
end
if not isempty(field.S7) then
if (matroska) then table.insert(output, '<br />') end
table.insert(output, field.S7 .. 'x Size 7 ' ..
lang:plural( field.S7, 'Compartment', 'Compartments'))
matroska = true
end
if not isempty(field.S8) then
if (matroska) then table.insert(output, '<br />') end
table.insert(output, field.S8 .. 'x Size 8 ' ..
lang:plural( field.S8, 'Compartment', 'Compartments'))
matroska = true
end
if not isempty(field.Reserved) then
if (matroska) then table.insert(output, '<br />') end
table.insert(output, field.Reserved)
end
end
function Infobox.Hardpoints( field, vars )
local matroska = nil
local output = {}
if not isempty(field.Utility) then
table.insert(output, field.Utility .. 'x Utility ' ..
lang:plural(field.Utility, 'Mount', 'Mounts'))
matroska = true
end
if not isempty(field.S) then
if (matroska) then table.insert(output, '<br />') end
table.insert(output, field.S .. 'x Small ' ..
lang:plural( field.S, 'Hardpoint', 'Hardpoints'))
matroska = true
end
if not isempty(field.M) then
if (matroska) then table.insert(output, '<br />') end
table.insert(output, field.M .. 'x Medium ' ..
lang:plural( field.M, 'Hardpoint', 'Hardpoints'))
matroska = true
end
if not isempty(field.L) then
if (matroska) then table.insert(output, '<br />') end
table.insert(output, field.L .. 'x Large ' ..
lang:plural( field.L, 'Hardpoint', 'Hardpoints'))
matroska = true
end
if not isempty(field.H) then
if (matroska) then table.insert(output, '<br />') end
table.insert(output, field.H .. 'x Huge ' ..
lang:plural( field.H, 'Hardpoint', 'Hardpoints'))
end
return table.concat( output )
end
return Infobox