Deprecated: ScribuntoContent overrides fillParserOutput which was deprecated in MediaWiki 1.38. [Called from MediaWiki\Content\Renderer\ContentRenderer::getParserOutput in /var/www/html/includes/content/Renderer/ContentRenderer.php at line 47] in /var/www/html/includes/debug/MWDebug.php on line 381

Deprecated: Use of AbstractContent::getParserOutput was deprecated in MediaWiki 1.38. [Called from ContentHandler::callDeprecatedContentGPO in /var/www/html/includes/content/ContentHandler.php at line 1883] in /var/www/html/includes/debug/MWDebug.php on line 381

Deprecated: Use of ParserOutput::addModules with non-array argument was deprecated in MediaWiki 1.38. [Called from ScribuntoHooks::invokeHook in /var/www/html/extensions/Scribunto/includes/common/Hooks.php at line 164] in /var/www/html/includes/debug/MWDebug.php on line 381
Module:Ships - ΔV: Wiki

Module:Ships

From ΔV: Wiki
Revision as of 00:05, 8 March 2023 by Cirdec (talk | contribs) (Ships module with a view into the ship data. The diplay/view definition code should be moved to a separate module for clarity)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

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 Dry mass View Oops is not defined
ND-LIS Kitsune 4,000 kg nil
Cothon-212 83,700 kg nil
Cothon-213 "Triplet" 84,700 kg nil
Cothon-211 "Chonker" 83,700 kg nil
Cothon-217 "Bender" 103,700 kg nil
K37 TNTRL 33,200 kg nil
KTA24 TNTRL 27,970 kg nil
KX37 TNTRL 37,970 kg nil
Runasimi KR37 TNTRL 47,500 kg nil
K44 MHFTR Prototype 54,600 kg nil
Eagle Prospector 27,500 kg nil
Bald Eagle 29,500 kg nil
Peacock Prospector 27,500 kg nil
Vulture Prospector 37,500 kg nil
Pelican Prospector 62,000 kg nil
OCP-209 184,500 kg nil
Antonoff-Titan K225 220,100 kg nil
Antonoff-Titan K225-BB 190,100 kg nil
Antonoff-Titan K225 (modified) 250,100 kg nil
Elon Interstellar Model E 27,000 kg nil

A list of columns to display can be specified as additional arguments

{{#invoke:Ships|list|Name
|Make
|Cargo bay
|Thrusters}}


Name Dry mass View Oops is not defined
ND-LIS Kitsune 4,000 kg nil
Cothon-212 83,700 kg nil
Cothon-213 "Triplet" 84,700 kg nil
Cothon-211 "Chonker" 83,700 kg nil
Cothon-217 "Bender" 103,700 kg nil
K37 TNTRL 33,200 kg nil
KTA24 TNTRL 27,970 kg nil
KX37 TNTRL 37,970 kg nil
Runasimi KR37 TNTRL 47,500 kg nil
K44 MHFTR Prototype 54,600 kg nil
Eagle Prospector 27,500 kg nil
Bald Eagle 29,500 kg nil
Peacock Prospector 27,500 kg nil
Vulture Prospector 37,500 kg nil
Pelican Prospector 62,000 kg nil
OCP-209 184,500 kg nil
Antonoff-Titan K225 220,100 kg nil
Antonoff-Titan K225-BB 190,100 kg nil
Antonoff-Titan K225 (modified) 250,100 kg nil
Elon Interstellar Model E 27,000 kg 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 == zero 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'}

p.view['Processed cargo'] = {
    format = function(ship)
        local pc  = formatNum(ship.processedCargo, 'kg')
        local pcc = formatNum(ship.processedCargoCombined, 'kg (combined)')
        if ship.processedCargo and ship.processedCargoCombined then
            return pc .. ' + ' .. pcc
        elseif ship.proceessedCargoCombined then
            return pcc
        elseif 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['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', 'Dry mass', 'Oops'})
end

return p