Нет описания правки Метка: ручная отмена |
Нет описания правки |
||
(не показано 14 промежуточных версий этого же участника) | |||
Строка 11: | Строка 11: | ||
local out = "" | local out = "" | ||
local store = frame.args[1] | local store = frame.args[1] | ||
local firstproduct = p.store[store].product[1] | |||
for id, content in pairs(p.store[store].product) do | for id, content in pairs(p.store[store].product) do | ||
out = out .. frame:expandTemplate{ title = "SupplyContent", args = { prototype = id, quantity = content }} | out = out .. frame:expandTemplate{ title = "SupplyContent", args = { prototype = id, quantity = content }} | ||
Строка 34: | Строка 35: | ||
table.sort(keys, compareByCost) | table.sort(keys, compareByCost) | ||
for _, k in ipairs(keys) do | |||
out = out .. frame:expandTemplate{ title = "Supply", args = { prototype = k}} | local firstProduct = nil | ||
for productKey, _ in pairs(p.store[k].product) do | |||
firstProduct = productKey | |||
break | |||
end | |||
out = out .. frame:expandTemplate{ title = "Supply", args = { prototype = k, firstproduct = firstProduct}} | |||
end | end | ||
Текущая версия от 17:47, 28 января 2024
Для документации этого модуля может быть создана страница Модуль:Supply Lookup/doc
local prototypes = mw.loadData("Module:Supply Lookup/data") local p = {} p.store = prototypes.store function p.readscalar(frame) return mw.text.nowiki(p.store[frame.args[1]][frame.args[2]]) end function p.buildcontent(frame) local out = "" local store = frame.args[1] local firstproduct = p.store[store].product[1] for id, content in pairs(p.store[store].product) do out = out .. frame:expandTemplate{ title = "SupplyContent", args = { prototype = id, quantity = content }} end return out end function p.buildlists(frame) local out = "" local group = frame.args[1] local keys = {} for k in pairs(p.store) do if p.store[k].group == group or group == nil then table.insert(keys, k) end end local function compareByCost(a, b) return tonumber(p.store[a].cost) < tonumber(p.store[b].cost) end table.sort(keys, compareByCost) for _, k in ipairs(keys) do local firstProduct = nil for productKey, _ in pairs(p.store[k].product) do firstProduct = productKey break end out = out .. frame:expandTemplate{ title = "Supply", args = { prototype = k, firstproduct = firstProduct}} end return out end return p