(Ships module with a view into the ship data. The diplay/view definition code should be moved to a separate module for clarity) |
(Include more columns in ship list) |
||
Line 49: | Line 49: | ||
local getter, view = makeView(args) | local getter, view = makeView(args) | ||
view.format = function(data) | view.format = function(data) | ||
return | return tostring(getter(data)) | ||
end | end | ||
return view | return view | ||
Line 69: | Line 69: | ||
view.format = function(data) | view.format = function(data) | ||
local value = getter(data) | local value = getter(data) | ||
if args.omitZero and value == | if args.omitZero and value == 0 then | ||
return '' | return '' | ||
end | end | ||
Line 91: | Line 91: | ||
p.view['Name'] = title{'name'} | p.view['Name'] = title{'name'} | ||
p.view['Make'] = text{'make'} | p.view['Make'] = text{'make'} | ||
local nonZero = function(n) | |||
return n and n ~= 0 | |||
end | |||
p.view['Processed cargo'] = { | p.view['Processed cargo'] = { | ||
Line 96: | Line 100: | ||
local pc = formatNum(ship.processedCargo, 'kg') | local pc = formatNum(ship.processedCargo, 'kg') | ||
local pcc = formatNum(ship.processedCargoCombined, 'kg (combined)') | local pcc = formatNum(ship.processedCargoCombined, 'kg (combined)') | ||
if ship.processedCargo and ship.processedCargoCombined then | if nonZero(ship.processedCargo) and nonZero(ship.processedCargoCombined) then | ||
return pc .. ' + ' .. pcc | return pc .. ' + ' .. pcc | ||
elseif ship.proceessedCargoCombined then | elseif nonZero(ship.proceessedCargoCombined) then | ||
return pcc | return pcc | ||
elseif ship.processedCargo then | elseif nonZero(ship.processedCargo) then | ||
return pc | return pc | ||
end | end | ||
Line 114: | Line 118: | ||
p.view['Drone hardpoints'] = number{'droneHardpoints'} | p.view['Drone hardpoints'] = number{'droneHardpoints'} | ||
p.view['Docking bays'] = number{'dockingBays'} | p.view['Docking bays'] = number{'dockingBays'} | ||
p.view['Crew'] = number{'crew'} | |||
p.view['Engines'] = number{'engines'} | |||
p.view['Thrusters'] = number{'thrusters'} | |||
p.view['Dry mass'] = number{'dryMass', unit='kg'} | p.view['Dry mass'] = number{'dryMass', unit='kg'} | ||
Line 135: | Line 142: | ||
end | end | ||
local result = {'{|', '| | local result = {'{|', '|-'} | ||
for j,view in ipairs(views) do | for j,view in ipairs(views) do | ||
table.insert(result, '!' .. tostring(view.heading)) | table.insert(result, '!' .. tostring(view.heading)) | ||
end | end | ||
for i,row in ipairs(data) do | for i,row in ipairs(data) do | ||
table.insert(result ,'| | table.insert(result ,'|-') | ||
for j,view in ipairs(views) do | for j,view in ipairs(views) do | ||
table.insert(result, '|' .. tostring(view.format(row))) | table.insert(result, '|' .. tostring(view.format(row))) | ||
Line 161: | Line 168: | ||
}) | }) | ||
return displayTable(data, p.view, {'Name', 'Dry mass', ' | return displayTable(data, p.view, { | ||
'Name', | |||
'High-Stress', 'Low-Stress', 'Drone hardpoints', 'Docking bays', 'Crew', | |||
'Dry mass', 'Processed cargo', | |||
'Engines', 'EMP shielding', 'New price', 'Variant' | |||
}) | |||
end | end | ||
return p | return p |
Revision as of 00:30, 8 March 2023
This ship module exists to present the data from Module:Ships/Data in tables of ships, ship variants, and ship info boxes.
Infobox
Script error: The function "infobox" does not exist.
Usage
{{#invoke:Ships|infobox|K37 |image=[[File:K37-tntrl.png|200px]] |caption=Top-down view of the K37}}
The image
and its caption
are optional.
The infobox floats to the side of other content. Example output is to the right. The float is cleared here to keep it from being confused with the next section of the documentation.
Ship list
Usage
{{#invoke:Ships|list}}
Example output
Name | High-Stress | Low-Stress | Drone hardpoints | Docking bays | Crew | Dry mass | Processed cargo | Engines | EMP shielding | New price | Variant |
---|---|---|---|---|---|---|---|---|---|---|---|
ND-LIS Kitsune | 0 | 1 | 0 | 0 | 3 | 4,000 kg | nil | 0 | nil | nil | |
Cothon-212 | 0 | 4 | 0 | 0 | 3 | 83,700 kg | 27,000 kg | 1 | 100 MJ | nil | nil |
Cothon-213 "Triplet" | 0 | 4 | 0 | 0 | 3 | 84,700 kg | 27,000 kg | 3 | nil | Triple main engines | |
Cothon-211 "Chonker" | 0 | 4 | 0 | 0 | 3 | 83,700 kg | 27,000 kg | 1 | 100 MJ | nil | Larger excavator |
Cothon-217 "Bender" | 0 | 4 | 0 | 0 | 3 | 103,700 kg | nil | 1 | 100 MJ | nil | Variable processed cargo storage |
K37 TNTRL | 1 | 2 | 0 | 0 | 4 | 33,200 kg | 7,000 kg | 1 | nil | nil | |
KTA24 TNTRL | 1 | 2 | 0 | 0 | 4 | 27,970 kg | 3,000 kg | 1 | nil | Tug with angled reverse thrust | |
KX37 TNTRL | 1 | 2 | 0 | 0 | 4 | 37,970 kg | 10,000 kg | 1 | nil | Extended cargo hold | |
Runasimi KR37 TNTRL | 1 | 2 | 0 | 0 | 6 | 47,500 kg | 4,000 kg | 1 | 200 MJ | nil | EMP shielded |
K44 MHFTR Prototype | 0 | 4 | 0 | 0 | 4 | 54,600 kg | 14,000 kg | 1 | nil | Abandoned prototype | |
Eagle Prospector | 0 | 2 | 2 | 0 | 6 | 27,500 kg | 14,000 kg | 2 | nil | nil | |
Bald Eagle | 0 | 2 | 2 | 0 | 6 | 29,500 kg | 14,000 kg | 4 | nil | Racing | |
Peacock Prospector | 0 | 2 | 2 | 0 | 4 | 27,500 kg | 14,000 kg | 2 | nil | Luxury interior influences crew morale towards happy | |
Vulture Prospector | 1 | 2 | 0 | 0 | 6 | 37,500 kg | 14,000 kg | 2 | nil | Drone hardpoints replaced with a high-stress hardpoint | |
Pelican Prospector | 0 | 2 | 2 | 0 | 6 | 62,000 kg | 14,000 kg | 2 | nil | Larger cargo bay, grinders replaced with excavator | |
OCP-209 | 2 | 2 | 0 | 0 | 8 | 184,500 kg | nil | 1 | nil | nil | |
Antonoff-Titan K225 | 0 | 2 | 0 | 6 | 12 | 220,100 kg | 7,000 kg | 3 | nil | nil | |
Antonoff-Titan K225-BB | 0 | 2 | 0 | 2 | 12 | 190,100 kg | 7,000 kg | 3 | nil | 4 docking bays removed to fit a much larger cargo bay | |
Antonoff-Titan K225 (modified) | 0 | 2 | 0 | 0 | 12 | 250,100 kg | 7,000 kg | 9 | 100 MJ | nil | Custom research retrofit, replaced docking bays with torch fittings and a Faraday cage fitted to give EMP resistance |
Elon Interstellar Model E | 1 | 2 | 0 | 0 | 5 | 27,000 kg | 11,000 kg | 2 | nil | nil |
A list of columns to display can be specified as additional arguments
{{#invoke:Ships|list|Name |Make |Cargo bay |Thrusters}}
Name | High-Stress | Low-Stress | Drone hardpoints | Docking bays | Crew | Dry mass | Processed cargo | Engines | EMP shielding | New price | Variant |
---|---|---|---|---|---|---|---|---|---|---|---|
ND-LIS Kitsune | 0 | 1 | 0 | 0 | 3 | 4,000 kg | nil | 0 | nil | nil | |
Cothon-212 | 0 | 4 | 0 | 0 | 3 | 83,700 kg | 27,000 kg | 1 | 100 MJ | nil | nil |
Cothon-213 "Triplet" | 0 | 4 | 0 | 0 | 3 | 84,700 kg | 27,000 kg | 3 | nil | Triple main engines | |
Cothon-211 "Chonker" | 0 | 4 | 0 | 0 | 3 | 83,700 kg | 27,000 kg | 1 | 100 MJ | nil | Larger excavator |
Cothon-217 "Bender" | 0 | 4 | 0 | 0 | 3 | 103,700 kg | nil | 1 | 100 MJ | nil | Variable processed cargo storage |
K37 TNTRL | 1 | 2 | 0 | 0 | 4 | 33,200 kg | 7,000 kg | 1 | nil | nil | |
KTA24 TNTRL | 1 | 2 | 0 | 0 | 4 | 27,970 kg | 3,000 kg | 1 | nil | Tug with angled reverse thrust | |
KX37 TNTRL | 1 | 2 | 0 | 0 | 4 | 37,970 kg | 10,000 kg | 1 | nil | Extended cargo hold | |
Runasimi KR37 TNTRL | 1 | 2 | 0 | 0 | 6 | 47,500 kg | 4,000 kg | 1 | 200 MJ | nil | EMP shielded |
K44 MHFTR Prototype | 0 | 4 | 0 | 0 | 4 | 54,600 kg | 14,000 kg | 1 | nil | Abandoned prototype | |
Eagle Prospector | 0 | 2 | 2 | 0 | 6 | 27,500 kg | 14,000 kg | 2 | nil | nil | |
Bald Eagle | 0 | 2 | 2 | 0 | 6 | 29,500 kg | 14,000 kg | 4 | nil | Racing | |
Peacock Prospector | 0 | 2 | 2 | 0 | 4 | 27,500 kg | 14,000 kg | 2 | nil | Luxury interior influences crew morale towards happy | |
Vulture Prospector | 1 | 2 | 0 | 0 | 6 | 37,500 kg | 14,000 kg | 2 | nil | Drone hardpoints replaced with a high-stress hardpoint | |
Pelican Prospector | 0 | 2 | 2 | 0 | 6 | 62,000 kg | 14,000 kg | 2 | nil | Larger cargo bay, grinders replaced with excavator | |
OCP-209 | 2 | 2 | 0 | 0 | 8 | 184,500 kg | nil | 1 | nil | nil | |
Antonoff-Titan K225 | 0 | 2 | 0 | 6 | 12 | 220,100 kg | 7,000 kg | 3 | nil | nil | |
Antonoff-Titan K225-BB | 0 | 2 | 0 | 2 | 12 | 190,100 kg | 7,000 kg | 3 | nil | 4 docking bays removed to fit a much larger cargo bay | |
Antonoff-Titan K225 (modified) | 0 | 2 | 0 | 0 | 12 | 250,100 kg | 7,000 kg | 9 | 100 MJ | nil | Custom research retrofit, replaced docking bays with torch fittings and a Faraday cage fitted to give EMP resistance |
Elon Interstellar Model E | 1 | 2 | 0 | 0 | 5 | 27,000 kg | 11,000 kg | 2 | nil | nil |
Ship variants
Usage
{{#invoke:Ships|variants|K37}}
Example output
Script error: The function "variants" does not exist.
A list of columns to display can be specified as additional arguments
{{#invoke:Ships|variants|K37 |Name|Make |Crew|Dry mass|Cargo|Processed cargo|EMP shielding |Variant}}
Script error: The function "variants" does not exist.
local p = {} local d = require('Module:Data') local processedCargoTypes = 6 p.view = {} local makeGetter = function(path) if type(path) == 'function' then return path elseif type(path) == 'string' then return d.path{path} elseif type(path) == 'table' then return d.path(path) end end local makeView = function(args) local path = table.remove(args, 1) local getter = makeGetter(path) local view = {} for k,v in pairs(args) do view[k] =v end return getter, view end local viewNotFound = function(name) return { heading = string.format("View %s is not defined", name), format = function(data) return nil end } end local title = function(args) local getter, view = makeView(args) view.format = function(data) local value = getter(data) if value then return '[[' .. getter(data) .. ']]' end end return view end local text = function(args) local getter, view = makeView(args) view.format = function(data) return tostring(getter(data)) end return view end local formatNum = function(n, ...) local unit = select(1, ...) if unit then return string.format('%s %s', mw.getContentLanguage():formatNum(n), unit) else return mw.getContentLanguage():formatNum(n) end end local number = function(args) local getter,view = makeView(args) view.format = function(data) local value = getter(data) if args.omitZero and value == 0 then return '' end if type(value) == 'number' then return formatNum(value, args.unit) end return value end view.sortType = 'number' view.sortValue = function(data) local value = getter(data) if type(value) == number then return tostring(value) end end return view end p.view['Name'] = title{'name'} p.view['Make'] = text{'make'} local nonZero = function(n) return n and n ~= 0 end p.view['Processed cargo'] = { format = function(ship) local pc = formatNum(ship.processedCargo, 'kg') local pcc = formatNum(ship.processedCargoCombined, 'kg (combined)') if nonZero(ship.processedCargo) and nonZero(ship.processedCargoCombined) then return pc .. ' + ' .. pcc elseif nonZero(ship.proceessedCargoCombined) then return pcc elseif nonZero(ship.processedCargo) then return pc end end, sortType = 'number', sortValue = function(ship) return ship.processedCargo * processedCargoTypes + ship.processedCargoCombined end } p.view['High-Stress'] = number{'highStress'} p.view['Low-Stress'] = number{'lowStress'} p.view['Drone hardpoints'] = number{'droneHardpoints'} p.view['Docking bays'] = number{'dockingBays'} p.view['Crew'] = number{'crew'} p.view['Engines'] = number{'engines'} p.view['Thrusters'] = number{'thrusters'} p.view['Dry mass'] = number{'dryMass', unit='kg'} p.view['Cargo bay'] = number{'cargoBay', unit='m^3'} p.view['EMP shielding'] = number{'empShielding', unit='MJ', omitZero=true} p.view['New price'] = number{'newPrice', unit='E$'} p.view['Variant'] = text{'variant'} for k,v in pairs(p.view) do v.heading = v.heading or k end local displayTable = function(data, view, columns) local views = {} for i,col in ipairs(columns) do view = p.view[col] or viewNotFound(col) table.insert(views, view) end local result = {'{|', '|-'} for j,view in ipairs(views) do table.insert(result, '!' .. tostring(view.heading)) end for i,row in ipairs(data) do table.insert(result ,'|-') for j,view in ipairs(views) do table.insert(result, '|' .. tostring(view.format(row))) end end table.insert(result,'|}') return table.concat(result, '\n') end p.list = function(f) local data = mw.loadData('Module:Ships/Data') data = d.sort(data, { d.on(d.path{'baseModelData', 'hullValue'}, d.asc), d.on(d.path{'baseModelData', 'name'}, d.asc), d.on(d.path{'isVariant'}, d.asc), d.on(d.path{'hullValue'}, d.asc), d.on(d.path{'name'}, d.asc), }) return displayTable(data, p.view, { 'Name', 'High-Stress', 'Low-Stress', 'Drone hardpoints', 'Docking bays', 'Crew', 'Dry mass', 'Processed cargo', 'Engines', 'EMP shielding', 'New price', 'Variant' }) end return p