Module:Slots
From Stationeers Community Wiki
More actions
Documentation for this module may be created at Module:Slots/doc
local p = {}
local ROW_MARKER = string.char(1)
local FIELD_SEP = string.char(2)
local BASE_PARAMS = {
'Class', 'Damage', 'MaxQuantity', 'Occupied', 'OccupantHash', 'Quantity', 'ReferenceId'
}
local EXTRA_PARAMS = {
Battery = {'Charge', 'ChargeRatio'},
GasCanister = {'Pressure', 'Temperature'},
GasFilter = {'FilterType'},
}
local function getLogicParams(slotType)
local params = {}
for _, v in ipairs(BASE_PARAMS) do table.insert(params, v) end
if EXTRA_PARAMS[slotType] then
for _, v in ipairs(EXTRA_PARAMS[slotType]) do table.insert(params, v) end
end
table.sort(params)
return table.concat(params, ', ')
end
-- {{Slots/row|name=Battery|type=Battery|index=0|logicParams=...}}
-- index and logicParams are optional.
function p.row(frame)
local args = frame.args
local name = mw.text.trim(args.name or '')
local slotType = mw.text.trim(args.type or 'None')
local index = mw.text.trim(args.index or '')
local logicParams = mw.text.trim(args.logicParams or '')
return ROW_MARKER .. table.concat({index, name, slotType, logicParams}, FIELD_SEP)
end
-- {{Slots|logic=1|{{Slots/row|...}}|{{Slots/row|...}}}}
function p.render(frame)
local args = frame:getParent().args
local showLogic = args['logic'] ~= nil and args['logic'] ~= ''
local rows = {}
for i, v in ipairs(args) do
local parts = mw.text.split(v:sub(2), FIELD_SEP)
local index = mw.text.trim(parts[1] or '')
local name = mw.text.trim(parts[2] or '')
local slotType = mw.text.trim(parts[3] or 'None')
local logicParams = mw.text.trim(parts[4] or '')
if index == '' then index = tostring(i - 1) end
if name ~= '' then
local row = '|-\n| ' .. index .. ' || ' .. name .. ' || ' .. slotType
if showLogic then
local params = logicParams ~= '' and logicParams or getLogicParams(slotType)
row = row .. ' || ' .. params
end
table.insert(rows, row)
end
end
local header = '{| class="wikitable"\n|-\n! Index !! Slot Name !! Type'
if showLogic then
header = header .. ' !! Logic Parameters'
end
return header .. '\n' .. table.concat(rows, '\n') .. '\n|}'
end
return p