Module:ShipInfobox: Difference between revisions
Content deleted Content added
mNo edit summary |
|||
| (20 intermediate revisions by the same user not shown) | |||
Line 4:
local lang = mw.language.new('en')
-- if a variable is required, this logic hides them if variable is empty
-- Rather than ParserFunctions, try passing your variables this way. ▼
local
if type(s) == "nil" then▼
if not HF.isempty(field.Requirement) then
result = true▼
output = field.Value
result = true▼
end
end ▼
result = true▼
end▼
end▼
▲end
function Infobox.Factionreq( field, vars )
▲ -- Rather than ParserFunctions, try passing your variables this way.
if not HF.isempty(field.Value) then
▲ local output = mw.html.create('span')
▲ return tostring(output)
end
end
-- replaces {{#if:{{{topspeed|}}}|{{{topspeed|?}}} m/s|---}} logic
Line 36 ⟶ 27:
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
else
field.Value = FormatNum.commavalue(field.Value:gsub(',',''))
return Infobox.Quantify(field, vars)
end
end
Line 46 ⟶ 47:
-- 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
Line 55 ⟶ 56:
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 ' ..
Line 66 ⟶ 67:
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 ' ..
Line 72 ⟶ 73:
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 ' ..
Line 78 ⟶ 79:
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'))
▲ 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 ' ..
Line 90 ⟶ 97:
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 ' ..
Line 96 ⟶ 103:
matroska = true
end
if not HF.isempty(field.Reserved) then
if (matroska) then table.insert(output, '<br />') end
table.insert(output, field.Reserved)
Line 106 ⟶ 113:
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 ' ..
Line 117 ⟶ 124:
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 ' ..
Line 123 ⟶ 130:
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 ' ..
Line 129 ⟶ 136:
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 ' ..
Line 135 ⟶ 142:
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)
if not HF.isempty(field.S2) then
number = number + (tonumber(field.S2) * 4)
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
output = "---"
else
output = tostring(number)
end
else
output = field.Cargo
end
field.Value = output
return Infobox.Quantify(field, vars)
end
| |||