Модуль:Prototypes/Механика/Стоимость: различия между версиями
Pok (обсуждение | вклад) мНет описания правки |
Pok (обсуждение | вклад) мНет описания правки |
||
| Строка 12: | Строка 12: | ||
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 | ||
| Строка 22: | Строка 23: | ||
function p.table(frame) | function p.table(frame) | ||
local output = {} | local output = {} | ||
local seen = {} | local seen = {} | ||
table.insert(output, '{| class="sortable-grid sortable"') | |||
table.insert(output, '! Сортировка (по стоимости)') | |||
table.insert(output, '|-') | |||
for _, item in ipairs(priceData) do | for _, item in ipairs(priceData) do | ||
local numericPrice = tonumber(item.StaticPrice.price) | local numericPrice = tonumber(item.StaticPrice.price) | ||
if numericPrice and numericPrice ~= 0 then | if numericPrice and numericPrice ~= 0 then | ||
local name = frame:preprocess( | local name = frame:preprocess( | ||
local priceFormatted = frame:preprocess("${{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 | local key = name .. "-" .. priceFormatted | ||
if not seen[key] then | if not seen[key] then | ||
seen[key] = true | seen[key] = true | ||
table.insert(output, | table.insert( | ||
table.insert(output, | 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 | ||
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 | ||