Модуль:Песочница/Pok
Для документации этого модуля может быть создана страница Модуль:Песочница/Pok/doc
-- Загрузка данных
local itemData = mw.loadData("Модуль:IanComradeBot/prototypes/fills/Item.json/data")
local itemSlotsData = mw.loadData("Модуль:IanComradeBot/prototypes/ItemSlots.json/data")
local p = {}
-- Функция для поиска первого 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
-- Поиск данных по ID
local function findDataById(itemDataIndex, id)
if not itemDataIndex then return nil end
for _, item in ipairs(itemDataIndex) do
if item.id == id then
return item
end
end
end
-- Форматирование содержимого
local function formatContent(id)
if not id then return "Ошибка: отсутствует id у элемента." end
local name = string.format("{{#invoke:Entity Lookup|getname|%s}}", id)
local image = string.format("%s.png", id)
return string.format("{{LinkСard|SideStyle=1|background-color=#cbcbff0a|image=%s|name=%s}}", image, name)
end
-- Основная функция модуля
function p.main(frame)
local mode = frame.args[1]
local id = frame.args[2]
if not id then return "Не указан ID." end
if 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
return "Неизвестный режим: " .. mode
end
end
return p