Нет описания правки |
Dantes (обсуждение | вклад) Нет описания правки |
||
| (не показано 7 промежуточных версий 1 участника) | |||
| Строка 2: | Строка 2: | ||
local p = {} | local p = {} | ||
p.store = prototypes.store | p.store = prototypes.store or {} | ||
-- Возвращает значение поля (без ошибок, если не найдено) | |||
function p.readscalar(frame) | 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 | end | ||
-- Собирает список шаблонов для указанной группы (или всех, если group == nil) | |||
function p.buildlists(frame) | function p.buildlists(frame) | ||
local group = frame.args[1] | |||
local keys = {} | 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 | |||
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 | end | ||
table.sort(keys, | table.sort(keys, function(a, b) | ||
return costOrMax(a) < costOrMax(b) | |||
end) | |||
local out = {} | |||
for _, k in ipairs(keys) do | for _, k in ipairs(keys) do | ||
out = | -- передаём прототип как именованный параметр шаблона | ||
out[#out + 1] = frame:expandTemplate{ title = "Uplink", args = { prototype = k } } | |||
end | end | ||
return table.concat(out, "") | |||
end | end | ||
return p | return p | ||
Текущая версия от 16:07, 16 октября 2025
Для документации этого модуля может быть создана страница Модуль: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