Модуль:Песочница/Pok: различия между версиями
Pok (обсуждение | вклад) мНет описания правки |
Pok (обсуждение | вклад) Нет описания правки |
||
| Строка 47: | Строка 47: | ||
return nil | return nil | ||
end | end | ||
-- Локальные функции | |||
local findDataById, formatContent, getContentsOutput, processNestedSelectors, getTableOutput, getContainedOutput, getChemOutput, handleGroupSelector, handleAllSelector, handleNestedSelector | |||
-- Поиск данных по ID через индекс | -- Поиск данных по ID через индекс | ||
findDataById = function(itemDataIndex, id) | |||
if not itemDataIndex then return nil end | if not itemDataIndex then return nil end | ||
for _, item in ipairs(itemDataIndex) do | |||
if item.id == id then | |||
return item | |||
end | |||
end | |||
end | end | ||
-- Форматирование содержимого | -- Форматирование содержимого | ||
formatContent = function(content) | formatContent = function(content) | ||
local name = string.format('{{#invoke:Entity Lookup|getname|%s}}', | if type(content) == "table" and not content.id then | ||
local image = string.format('%s.png', | return "Ошибка: отсутствует id у элемента." | ||
end | |||
-- Если передан объект с id | |||
local id = content.id or content | |||
local name = string.format('{{#invoke:Entity Lookup|getname|%s}}', id) | |||
local image = string.format('%s.png', id) | |||
local amount = (content.amount and content.amount ~= 1) and string.format(" [%d]", content.amount) or "" | |||
local prob = "" | local prob = "" | ||
| Строка 78: | Строка 85: | ||
return string.format( | return string.format( | ||
'{{LinkСard|SideStyle=1|background-color=#cbcbff0a|image=%s|name=%s%s%s {{#invoke:Песочница/Pok|main|framing|contained|%s}} {{#invoke:Песочница/Pok|main|framing|slot|%s}} }}', | '{{LinkСard|SideStyle=1|background-color=#cbcbff0a|image=%s|name=%s%s%s {{#invoke:Песочница/Pok|main|framing|contained|%s}} {{#invoke:Песочница/Pok|main|framing|slot|%s}} }}', | ||
image, name, amount, prob, | image, name, amount, prob, id, id | ||
) | ) | ||
end | end | ||
| Строка 310: | Строка 317: | ||
elseif subMode == 'contained' then | elseif subMode == 'contained' then | ||
return frame:preprocess('{{СollapsibleMenu|' .. getContainedOutput(itemDataIndex, id) .. '}}') | return frame:preprocess('{{СollapsibleMenu|' .. getContainedOutput(itemDataIndex, id) .. '}}') | ||
elseif mode == "slot" then | |||
local itemDataEntry = findDataById(itemSlotsData, id) | |||
if not itemDataEntry then return "ID не найден в данных ItemSlots." end | |||
local startingItem = getFirstStartingItem(itemDataEntry) | |||
if not startingItem then return "Не найден startingItem в slots." end | |||
return frame:preprocess(formatContent(startingItem)) | |||
else | else | ||
return 'Неизвестный подрежим для framing: ' .. subMode | return 'Неизвестный подрежим для framing: ' .. subMode | ||
| Строка 325: | Строка 332: | ||
elseif mode == 'contained' then | elseif mode == 'contained' then | ||
return frame:preprocess(getContainedOutput(itemDataIndex, id)) | return frame:preprocess(getContainedOutput(itemDataIndex, id)) | ||
elseif mode == "slot" then | |||
local itemDataEntry = findDataById(itemSlotsData, id) | |||
if not itemDataEntry then return "ID не найден в данных ItemSlots." end | |||
local startingItem = getFirstStartingItem(itemDataEntry) | |||
if not startingItem then return "Не найден startingItem в slots." end | |||
return frame:preprocess(formatContent(startingItem)) | |||
elseif mode == 'rolls' then | elseif mode == 'rolls' then | ||
local entity = findDataById(itemDataIndex, id) | local entity = findDataById(itemDataIndex, id) | ||