Модуль:Prototypes/Хранилище/Предмет: различия между версиями
Pok (обсуждение | вклад) Новая страница: «local p = {} -- Функция для загрузки данных из страницы local function loadData(filePath) local page = mw.title.new(filePath) local content = page:getContent() return content and mw.text.jsonDecode(content) or nil end -- Поиск данных по ID local function findDataById(data, id) if not data then return nil end for _, item in ipairs(data) do if item.id == id then return ite...» |
Pok (обсуждение | вклад) Нет описания правки |
||
| Строка 37: | Строка 37: | ||
end | end | ||
-- Формирование списка содержащихся предметов | -- Формирование списка содержащихся предметов или таблиц | ||
local function getContainedOutput(data, id, wrapped) | local function getContainedOutput(data, id, wrapped) | ||
local item = findDataById(data, id) | local item = findDataById(data, id) | ||
| Строка 43: | Строка 43: | ||
local contents = item.StorageFill and item.StorageFill.contents | local contents = item.StorageFill and item.StorageFill.contents | ||
local tableContainer = item.EntityTableContainerFill and item.EntityTableContainerFill.containers | |||
local result = wrapped and "<div>" or "" | local result = wrapped and "<div>" or "" | ||
for _, content in ipairs(contents) do | |||
if wrapped then | if contents then | ||
for _, content in ipairs(contents) do | |||
if wrapped then | |||
result = result .. string.format("<div>%s</div>", content.id) | |||
else | |||
result = result .. string.format("%s\n", content.id) | |||
end | |||
end | |||
elseif tableContainer then | |||
local tableId = tableContainer.storagebase and tableContainer.storagebase.tableId | |||
if tableId then | |||
local allSelectors = loadData("User:IanComradeBot/prototypes/AllSelector.json") | |||
local tableData = findDataById(allSelectors, tableId) | |||
local children = tableData and tableData["!type:AllSelector"] and tableData["!type:AllSelector"].children | |||
if children then | |||
for _, child in ipairs(children) do | |||
if wrapped then | |||
result = result .. string.format("<div>%s</div>", child.id) | |||
else | |||
result = result .. string.format("%s\n", child.id) | |||
end | |||
end | |||
else | |||
result = result .. "Таблица не содержит элементов." | |||
end | |||
else | else | ||
result = result .. | result = result .. "Таблица не найдена." | ||
end | end | ||
else | |||
result = result .. "Содержимого не найдено." | |||
end | end | ||
if wrapped then | if wrapped then | ||
result = result .. "</div>" | result = result .. "</div>" | ||
| Строка 59: | Строка 86: | ||
end | end | ||
-- | -- Основная функция модуля | ||
function p.main(frame) | function p.main(frame) | ||
local mode = frame.args[1] | local mode = frame.args[1] | ||