Модуль:Песочница/Pok: различия между версиями
Материал из Space Station 14 Вики
Pok (обсуждение | вклад) мНет описания правки |
Pok (обсуждение | вклад) мНет описания правки |
||
| Строка 5: | Строка 5: | ||
function p.main(frame) | function p.main(frame) | ||
local id = frame.args[1] or frame.args.id | local id = frame.args[1] or frame.args.id | ||
if not id then | if not id then | ||
| Строка 11: | Строка 10: | ||
end | end | ||
for _, item in ipairs(priceData) do | for _, item in ipairs(priceData) do | ||
if item.id == id then | if item.id == id then | ||
| Строка 25: | Строка 23: | ||
local output = {} | local output = {} | ||
for _, item in ipairs(priceData) do | for _, item in ipairs(priceData) do | ||
local name = frame:preprocess('{{#invoke:Entity Lookup|getname|' .. item.id .. '}}') | if tonumber(item.StaticPrice.price) ~= 0 then | ||
local name = frame:preprocess('{{#invoke:Entity Lookup|getname|' .. item.id .. '}}') | |||
local price = frame:preprocess("{{ColorPalette|Other|price|" .. item.StaticPrice.price .. "}}$") | |||
table.insert(output, '|data-sort-value=' .. item.StaticPrice.price .. '|{{Cut-Layout|1=[[File:' .. item.id .. '.png|32px]] ' .. name .. '|2=' .. price .. '}}') | |||
table.insert(output, '|-') | |||
end | |||
end | end | ||
return frame:preprocess(table.concat(output, "\n")) | return frame:preprocess(table.concat(output, "\n")) | ||
Версия от 20:00, 15 апреля 2025
Для документации этого модуля может быть создана страница Модуль:Песочница/Pok/doc
-- Загрузка данных
local priceData = mw.loadData("Модуль:IanComradeBot/prototypes/StaticPrice.json/data")
local p = {}
function p.main(frame)
local id = frame.args[1] or frame.args.id
if not id then
return "Ошибка: не передан id"
end
for _, item in ipairs(priceData) do
if item.id == id then
return frame:preprocess("{{ColorPalette|Other|price|" .. item.StaticPrice.price .. "}}$")
end
end
-- Если не нашли совпадение, возвращаем стандартный текст
return frame:preprocess("нет")
end
function p.table(frame)
local output = {}
for _, item in ipairs(priceData) do
if tonumber(item.StaticPrice.price) ~= 0 then
local name = frame:preprocess('{{#invoke:Entity Lookup|getname|' .. item.id .. '}}')
local price = frame:preprocess("{{ColorPalette|Other|price|" .. item.StaticPrice.price .. "}}$")
table.insert(output, '|data-sort-value=' .. item.StaticPrice.price .. '|{{Cut-Layout|1=[[File:' .. item.id .. '.png|32px]] ' .. name .. '|2=' .. price .. '}}')
table.insert(output, '|-')
end
end
return frame:preprocess(table.concat(output, "\n"))
end
return p