Модуль:Prototypes/Механика/Стоимость: различия между версиями
Материал из Space Station 14 Вики
Pok (обсуждение | вклад) мНет описания правки Метка: ручная отмена |
Pok (обсуждение | вклад) мНет описания правки |
||
| Строка 1: | Строка 1: | ||
-- Загрузка данных | -- Загрузка данных | ||
local priceData = mw.loadData(" | local JP = require("Module:JsonPaths") | ||
local priceData = mw.loadData( JP.get("prototypes/StaticPrice.json") ) | |||
local p = {} | local p = {} | ||
Текущая версия от 10:51, 17 июля 2025
Для документации этого модуля может быть создана страница Модуль:Prototypes/Механика/Стоимость/doc
-- Загрузка данных
local JP = require("Module:JsonPaths")
local priceData = mw.loadData( JP.get("prototypes/StaticPrice.json") )
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 = {}
local seen = {}
table.insert(output, '{| class="sortable-grid sortable"')
table.insert(output, '! Сортировка (по стоимости)')
table.insert(output, '|-')
for _, item in ipairs(priceData) do
local numericPrice = tonumber(item.StaticPrice.price)
if numericPrice and numericPrice ~= 0 then
local name = frame:preprocess(
"{{#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
table.insert(output, "|}")
return frame:preprocess(table.concat(output, "\n"))
end
return p