Для документации этого модуля может быть создана страница Модуль:Uplink Lookup/doc
local prototypes = mw.loadData("Module:Uplink Lookup/data")
local p = {}
p.store = prototypes.store or {}
-- Возвращает значение поля (без ошибок, если не найдено)
function p.readscalar(frame)
local prototype = frame.args[1]
local field = frame.args[2]
if not prototype or not p.store[prototype] then
return ""
end
return mw.text.nowiki( tostring(p.store[prototype][field] or "") )
end
-- Собирает список шаблонов для указанной группы (или всех, если group == nil)
function p.buildlists(frame)
local group = frame.args[1]
local keys = {}
for k in pairs(p.store) do
if not group or p.store[k].group == group then
table.insert(keys, k)
end
end
local function costOrMax(key)
local entry = p.store[key]
if not entry then return math.huge end
local n = tonumber(entry.cost)
return n or math.huge
end
table.sort(keys, function(a, b)
return costOrMax(a) < costOrMax(b)
end)
local out = {}
for _, k in ipairs(keys) do
-- передаём прототип как именованный параметр шаблона
out[#out + 1] = frame:expandTemplate{ title = "Uplink", args = { prototype = k } }
end
return table.concat(out, "")
end
return p