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

мНет описания правки
мНет описания правки
 
(не показано 11 промежуточных версий этого же участника)
Строка 1: Строка 1:
-- Загрузка данных
-- Загрузка данных
local priceData = mw.loadData("Модуль:IanComradeBot/prototypes/StaticPrice.json/data")
local JP = require("Module:JsonPaths")
local priceData = mw.loadData( JP.get("prototypes/StaticPrice.json") )


local p = {}
local p = {}


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: Строка 11:
     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
             return frame:preprocess("{{ColorPalette|Other|price|" .. item.StaticPrice.price .. "}}$")
             return frame:preprocess(
                "${{ColorPalette|Other|price|" .. item.StaticPrice.price .. "}}"
            )
         end
         end
     end
     end


    -- Если не нашли совпадение, возвращаем стандартный текст
     return frame:preprocess("нет")
     return frame:preprocess("нет")
end
end
Строка 24: Строка 24:
function p.table(frame)
function p.table(frame)
     local output = {}
     local output = {}
     table.insert(output, '{| class="wikitable"')
    local seen = {}
     table.insert(output, '{| class="sortable-grid sortable"')
    table.insert(output, '! Сортировка (по стоимости)')
     table.insert(output, '|-')
     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 .. '}}')
        local numericPrice = tonumber(item.StaticPrice.price)
        table.insert(output, '|-')
        if numericPrice and numericPrice ~= 0 then
        table.insert(output, '| [[File:' .. item.id .. '.png|32px]] [[' .. itemData .. '|' .. itemData .. ']]')
            local name = frame:preprocess(
        table.insert(output, '| {{ColorPalette|Other|price|' .. item.StaticPrice.price .. '}}$')
                "{{#invoke:Entity Lookup|getname|" .. item.id .. "}}"
            )
            local priceFormatted = frame:preprocess(
                "${{ColorPalette|Other|price|" .. item.StaticPrice.price .. "}}"
            )
 
            local key = name .. "-" .. priceFormatted
            if not seen[key] then
                seen[key] = true
                table.insert(
                    output,
                    "|data-sort-value=" .. item.StaticPrice.price ..
                    "|{{Cut-Layout|1=[[File:" .. item.id .. ".png|32px|link=]] " ..  
                    name .. "|2=" .. priceFormatted .. "}}"
                )
                table.insert(output, "|-")
            end
        end
     end
     end
     table.insert(output, '|}')
 
     table.insert(output, "|}")
     return frame:preprocess(table.concat(output, "\n"))
     return frame:preprocess(table.concat(output, "\n"))
end
end


return p
return p