Модуль:Prototypes/Механика/Стоимость: различия между версиями

мНет описания правки
мНет описания правки
Строка 5: Строка 5:


function p.main(frame)
function p.main(frame)
    -- Получаем первый параметр, который должен быть id
     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


    -- Проходим по всем записям в priceData
     for _, item in ipairs(priceData) do
     for _, item in ipairs(priceData) do
         if item.id == id then
         if item.id == id then
Строка 24: Строка 22:
function p.table(frame)
function p.table(frame)
     local output = {}
     local output = {}
    table.insert(output, '{| class="wikitable"')
    table.insert(output, '|-')
    table.insert(output, '! Предмет')
    table.insert(output, '! Стоимость')
     for _, item in ipairs(priceData) do
     for _, item in ipairs(priceData) do
    local itemData = frame:preprocess('{{#invoke:Entity Lookup|getname|' .. item.id .. '}}')
        if tonumber(item.StaticPrice.price) ~= 0 then
        table.insert(output, '|-')
            local name = frame:preprocess('{{#invoke:Entity Lookup|getname|' .. item.id .. '}}')
        table.insert(output, '| [[File:' .. item.id .. '.png|32px]] [[' .. itemData .. '|' .. itemData .. ']]')
            local price = frame:preprocess("{{ColorPalette|Other|price|" .. item.StaticPrice.price .. "}}$")
        table.insert(output, '| {{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
    table.insert(output, '|}')
     return frame:preprocess(table.concat(output, "\n"))
     return frame:preprocess(table.concat(output, "\n"))
end
end


return p
return p