Модуль:Prototypes/Хранилище/Предмет: различия между версиями
Pok (обсуждение | вклад) Нет описания правки |
Pok (обсуждение | вклад) Нет описания правки |
||
| Строка 1: | Строка 1: | ||
-- Загрузка данных | -- Загрузка данных | ||
local itemData = mw.loadData("Модуль:IanComradeBot/prototypes/fills/Item.json/data") | local itemData = mw.loadData("Модуль:IanComradeBot/prototypes/fills/Item.json/data") | ||
local itemSlotsData = mw.loadData("Модуль:IanComradeBot/prototypes/ItemSlots.json/data") | |||
local p = {} | local p = {} | ||
| Строка 31: | Строка 32: | ||
return result | return result | ||
end | end | ||
-- Функция для поиска первого startingItem в slots | |||
local function getFirstStartingItem(data) | |||
if not data or not data.ItemSlots or not data.ItemSlots.slots then | |||
return nil | |||
end | |||
for _, slot in pairs(data.ItemSlots.slots) do | |||
if slot.startingItem and slot.startingItem ~= "" then | |||
return slot.startingItem | |||
end | |||
end | |||
return nil | |||
end | |||
-- Локальные функции | -- Локальные функции | ||
| Строка 47: | Строка 64: | ||
-- Форматирование содержимого | -- Форматирование содержимого | ||
formatContent = function(content) | formatContent = function(content) | ||
if not content.id then | if type(content) == "table" and not content.id then | ||
return "Ошибка: отсутствует id у элемента." | return "Ошибка: отсутствует id у элемента." | ||
end | end | ||
local name = string.format('{{#invoke:Entity Lookup|getname|%s}}', | -- Если передан объект с id | ||
local image = string.format('%s.png', | 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 = "" | ||
| Строка 65: | Строка 84: | ||
return string.format( | return string.format( | ||
'{{LinkСard|SideStyle=1|background-color=#cbcbff0a|image=%s|name=%s%s%s {{#invoke: | '{{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 | ||
| Строка 298: | Строка 317: | ||
elseif subMode == 'contained' then | elseif subMode == 'contained' then | ||
return frame:preprocess('{{СollapsibleMenu|' .. getContainedOutput(itemDataIndex, id) .. '}}') | return frame:preprocess('{{СollapsibleMenu|' .. getContainedOutput(itemDataIndex, id) .. '}}') | ||
elseif subMode == "slot" then | |||
local itemDataEntry = findDataById(itemSlotsData, id) | |||
if not itemDataEntry then return "" end | |||
local startingItem = getFirstStartingItem(itemDataEntry) | |||
if not startingItem then return "" end | |||
return frame:preprocess('{{СollapsibleMenu|' .. formatContent(startingItem) .. '}}') | |||
else | else | ||
return 'Неизвестный подрежим для framing: ' .. subMode | return 'Неизвестный подрежим для framing: ' .. subMode | ||
| Строка 305: | Строка 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 "" end | |||
local startingItem = getFirstStartingItem(itemDataEntry) | |||
if not startingItem then return "" end | |||
return frame:preprocess(formatContent(startingItem)) | |||
elseif mode == 'rolls' then | elseif mode == 'rolls' then | ||
local entity = findDataById(itemDataIndex, id) | local entity = findDataById(itemDataIndex, id) | ||