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:43, 19 November 2024 by Hev (talk | contribs) (fixed error)

This ship module exists to present the data from Module:Ships/Data in tables of ships, ship variants, and ship info boxes.


Infobox

Lua error at line 62: attempt to perform arithmetic on a string value.

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

Lua error at line 62: attempt to perform arithmetic on a string value.

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

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


Lua error at line 62: attempt to perform arithmetic on a string value.

Ship variants

Usage

{{#invoke:Ships|variants|K37}}

Example output

Lua error at line 62: attempt to perform arithmetic on a string value.


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}}

Lua error at line 62: attempt to perform arithmetic on a string value.


local p = {}
local d = require('Module:Data')
local dv = require('Module:Data/View')
local capiunto = require 'capiunto'

local processedCargoTypes = 6

p.view = {}

p.view['Name'] = dv.title{'key', text='name'}
p.view['Make'] = dv.text{'make'}

local nonZero = function(n)
    return n and n ~= 0
end

p.view['Processed cargo'] = {
    format = function(ship)
        local pc  = dv.formatNum(ship.processedCargo, 'kg')
        local pcc = dv.formatNum(ship.processedCargoCombined, 'kg (combined)')
        if nonZero(ship.processedCargo) and nonZero(ship.processedCargoCombined) then
            return pc .. ' + ' .. pcc
        elseif nonZero(ship.processedCargoCombined) 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['Processed cargo (tons)'] = {
    format = function(ship)
        local pc  = dv.formatNum(ship.processedCargo/1000, 't')
        local pcc = dv.formatNum(ship.processedCargoCombined/1000, 't (combined)')
        if nonZero(ship.processedCargo) and nonZero(ship.processedCargoCombined) then
            return pc .. ' + ' .. pcc
        elseif nonZero(ship.processedCargoCombined) 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'] = dv.number{'highStress'}
p.view['Low-Stress'] = dv.number{'lowStress'}
p.view['Drone hardpoints'] = dv.number{'droneHardpoints'}
p.view['Docking bays'] = dv.number{'dockingBays'}
p.view['Crew'] = dv.number{'crew'}
p.view['Engines'] = dv.number{'engines'}
p.view['Thrusters'] = dv.number{'thrusters'}

p.view['Dry mass'] = dv.number{'dryMass', unit='kg'}
p.view['Dry mass (tons)'] = dv.number{'dryMass'/1000, unit='t'}
p.view['Cargo bay'] = dv.number{'cargoBay', unit='m^3'}
p.view['EMP shielding'] = dv.number{'empShielding', unit='MJ', omitZero=true}
p.view['New price'] = dv.number{'priceNew', unit='E$'}
p.view['Stripped hull price'] = dv.number{'hullValue', unit='E$'}

p.view['Hull Width'] = dv.number{'width', unit='m'}
p.view['Hull Length'] = dv.number{'length', unit='m'}
p.view['Min. Cargo Bay Width'] = dv.number{'minBayWidth', unit='m'}

p.view['Variant'] = dv.text{'variant'}

for k,v in pairs(p.view) do
    v.heading = v.heading or k
end

p.infoboxRows = {
    'Make',
    'High-Stress', 'Low-Stress', 'Drone hardpoints', 'Docking bays', 'Crew',
    'Dry mass', 'Cargo bay', 'Processed cargo',
    'New price', 
    'Hull Length', 
    'Hull Width', 
    'Min. Cargo Bay Width'
}

p.infobox = function(f)
    local key = mw.text.trim(f.args[1])
    local data = mw.loadData('Module:Ships/Data')
    data = data[key]

    local cap = capiunto.create{title=p.view.Name.format(data)}

    if f.args.image then
        cap:addImage(f.args.image, f.args.caption)
    end

    for i,viewKey in ipairs(p.infoboxRows) do
        local view = p.view[viewKey]
        local dataPoint = view.format(data)
        -- Skip zeros
        if view.sortType == 'number' then
            local sortValue = view.sortValue(data)
            if sortValue == 0 then
                dataPoint = nil
            end
        end
        if dataPoint then
            cap:addRow(view.heading, dataPoint)
        end
    end
    return cap
end


p.defaultColumns = {
    'Name',
    'High-Stress', 'Low-Stress', 'Drone hardpoints', 'Docking bays', 'Crew',
    'Dry mass', 'Processed cargo',
    'Engines', 'EMP shielding', 'New price', 
    'Hull Length', 
    'Hull Width', 
    'Min. Cargo Bay Width',
    'Variant'
}

p.positionalArgs = function(f)
    local posArgs = {}
    for i,posArg in ipairs(f.args) do
        -- positional arguments don't get trimmed
        table.insert(posArgs, mw.text.trim(posArg))
    end
    return posArgs
end

p.list = function(f)
    local columns = p.positionalArgs (f)
    if table.getn(columns) == 0 then
        columns = p.defaultColumns
    end


    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 dv.displayTable(data, p.view, columns)
end

p.variants = function(f)
    local posArgs = p.positionalArgs(f)
    local baseModel = table.remove(posArgs, 1)
    local columns = posArgs
    if table.getn(columns) == 0 then
        columns = p.defaultColumns
    end

    local data = mw.loadData('Module:Ships/Data')

    data = d.filter(data, function (ship)
         return ship.baseModel == baseModel
    end)

    data = d.sort(data, {
        d.on(d.path{'isVariant'}, d.asc),
        d.on(d.path{'hullValue'}, d.asc),
        d.on(d.path{'name'}, d.asc),
    })

    return dv.displayTable(data, p.view, columns)
end

p.minInfoboxRows = {
    'Make',
    'High-Stress', 'Low-Stress', 'Drone hardpoints', 'Docking bays', 'Crew',
    'Dry mass (tons)', 'Cargo bay', 'Processed cargo (tons)',
    'New price'
}

p.minInfobox = function(f)
    local key = mw.text.trim(f.args[1])
    local data = mw.loadData('Module:Ships/Data')
    data = data[key]

    local cap = capiunto.create{title=p.view.Name.format(data)}

    if f.args.image then
        cap:addImage(f.args.image, f.args.caption)
    end

    for i,viewKey in ipairs(p.minInfoboxRows) do
        local view = p.view[viewKey]
        local dataPoint = view.format(data)
        -- Skip zeros
        if view.sortType == 'number' then
            local sortValue = view.sortValue(data)
            if sortValue == 0 then
                dataPoint = nil
            end
        end
        if dataPoint then
            cap:addRow(view.heading, dataPoint)
        end
    end
    return cap
end


return p