Module:ShipInfobox: Difference between revisions
Appearance
Content deleted Content added
No edit summary |
No edit summary |
||
| Line 1: | Line 1: | ||
local |
local Infobox = {} |
||
-- This avoids using the {{#if:{{{factionreq|}}}||}} ParserFunction. |
-- This avoids using the {{#if:{{{factionreq|}}}||}} ParserFunction. |
||
| Line 18: | Line 18: | ||
end |
end |
||
function Factionreq( field ) |
function Infobox.Factionreq( field, vars ) |
||
-- Rather than ParserFunctions, try passing your variables this way. |
-- Rather than ParserFunctions, try passing your variables this way. |
||
local text = 'Requires '.. field.Requirement ..' rank of '.. field.Rank ..' or higher' |
local text = 'Requires '.. field.Requirement ..' rank of '.. field.Rank ..' or higher' |
||
| Line 30: | Line 30: | ||
-- replaces {{#if:{{{topspeed|}}}|{{{topspeed|?}}} m/s|---}} logic |
-- replaces {{#if:{{{topspeed|}}}|{{{topspeed|?}}} m/s|---}} logic |
||
function Quantify( field ) |
function Infobox.Quantify( field, vars ) |
||
local unit = field.Unit or '' |
local unit = field.Unit or '' |
||
local value = field.Value or field.Default or '?' |
local value = field.Value or field.Default or '?' |
||
| Line 40: | Line 40: | ||
end |
end |
||
function Insurance( field ) |
function Infobox.Insurance( field, vars ) |
||
-- replaces {{#if:{{{cost|}}}|{{formatnum:{{#expr:trunc({{formatnum:{{{cost|}}}|R}}*0.05)}}}} CR|}} |
-- replaces {{#if:{{{cost|}}}|{{formatnum:{{#expr:trunc({{formatnum:{{{cost|}}}|R}}*0.05)}}}} CR|}} |
||
local insurance = field.Cost or '' |
local insurance = field.Cost or '' |
||
| Line 49: | Line 49: | ||
end |
end |
||
function |
function Infobox.Internals( field, vars ) |
||
-- |
-- |
||
end |
end |
||
function |
function Infobox.Hardpoints( field, vars ) |
||
-- |
-- |
||
end |
end |
||
return |
return Infobox |
||
Revision as of 01:35, 23 May 2015
Documentation for this module may be created at Module:ShipInfobox/doc
local Infobox = {}
-- 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 )
--
end
return Infobox