Modul:Entity/Orders
Aus Star Citizen Wiki
Weitere Optionen
Die Dokumentation für dieses Modul kann unter Modul:Entity/Orders/doc erstellt werden
require('strict')
local Data = require('Module:Entity/Data')
local TableLua = require('Module:TableLua')
local Lines = require('Module:Entity/Orders/Lines')
local emptyState = require('Module:Entity/EmptyState')
local msg = require('Module:Entity/Message').msg
local function displayNumber(value)
local text = tostring(value)
if require('Module:Entity/StructuredData').backend() == 'smw' then
return (text:gsub('%.', ','))
end
return text
end
local function formatSize(item)
if not item.max_container_size and not item.max_scu and not item.min_scu then
return msg('1 Unit')
end
if item.max_container_size == -1 then
if item.max_scu == 1 then
return '1 SCU'
end
if item.max_scu or item.min_scu then
return '1 - 32 SCU'
end
return msg('1 Unit')
end
if item.max_container_size == 1 then
return displayNumber(item.max_container_size) .. ' SCU'
end
return '1 - ' .. displayNumber(item.max_container_size) .. ' SCU'
end
local function processOrders(orders)
local data = {}
local total = {
unique = 0,
units = 0,
scu = 0,
}
for _, order in ipairs(orders) do
local x = {}
local quantity, units, scu = Lines.formatQuantity(order)
local cargo = Lines.cargoLabel(order)
table.insert(x, quantity)
table.insert(x, cargo)
table.insert(x, formatSize(order))
table.insert(data, x)
total.unique = total.unique + 1
total.units = total.units + units
total.scu = total.scu + scu
end
if require('Module:Entity/StructuredData').backend() == 'smw' then
total.units = displayNumber(total.units)
total.scu = displayNumber(total.scu)
end
return tostring(TableLua.render({
caption = 'Total amount of orders',
hideCaption = true,
class = 'wikitable--fluid t-entity-orders-table',
columns = {
{ id = 'uniqueItems', label = msg('Unique Items') },
{ id = 'totalUnits', label = msg('Total Units') },
{ id = 'totalScu', label = msg('Total SCU') },
},
data = { { total.unique, total.units, total.scu } },
})) .. tostring(TableLua.render({
caption = 'Orders',
hideCaption = true,
class = 'wikitable--fluid t-entity-orders-table',
columns = {
{ id = 'quantity', label = msg('Quantity'), textAlign = 'start' },
{ id = 'cargo', label = msg('Cargo'), textAlign = 'start' },
{ id = 'size', label = msg('Size'), textAlign = 'start' },
},
data = data,
}))
end
local p = {}
--- @param apiData table
--- @return string|nil
function p.main(frame)
local args = Data.parseArgs(frame)
local result = Data.get(args)
local orders = result.apiData and result.apiData.hauling_orders
if type(orders) ~= 'table' or #orders == 0 then
if result.hasApiError then
return emptyState.failed(msg("Couldn't load requested items."))
end
return emptyState.none(msg('No items requested.'))
end
local root = mw.html.create('div'):addClass('t-entity-order-container')
root:wikitext(processOrders(orders))
local styles = mw.getCurrentFrame():extensionTag({
name = 'templatestyles',
args = { src = 'Module:Entity/Orders/styles.css' },
})
return styles .. tostring(root)
end
return p