Модуль:Prototypes/Хранилище/Предмет: различия между версиями
Pok (обсуждение | вклад) мНет описания правки |
Pok (обсуждение | вклад) мНет описания правки |
||
| Строка 1: | Строка 1: | ||
local p = {} | |||
-- Функции как локальные переменные | |||
local loadData, findDataById, formatContent, getContentsOutput, processNestedSelectors, getTableOutput, getContainedOutput, getChemOutput | local loadData, findDataById, formatContent, getContentsOutput, processNestedSelectors, getTableOutput, getContainedOutput, getChemOutput | ||
-- Функция для загрузки данных | -- Функция для загрузки данных | ||
| Строка 48: | Строка 50: | ||
end | end | ||
-- | -- Обработка вложенных таблиц | ||
processNestedSelectors = function(children) | |||
local | local result = '' | ||
for _, child in ipairs(children) do | for _, child in ipairs(children) do | ||
if child.id then | |||
result = result .. formatContent(child) | |||
elseif child["!type"] == "NestedSelector" and child.tableId then | |||
result = result .. getTableOutput(child.tableId) | |||
end | end | ||
end | end | ||
return result | |||
return | |||
end | end | ||
-- Обработка таблиц | -- Обработка таблиц | ||
getTableOutput = function(tableId | getTableOutput = function(tableId) | ||
local allSelectors = loadData('User:IanComradeBot/prototypes/AllSelector.json') | local allSelectors = loadData('User:IanComradeBot/prototypes/AllSelector.json') | ||
local tableData = findDataById(allSelectors, tableId) | local tableData = findDataById(allSelectors, tableId) | ||
local children = tableData and | local children = tableData and tableData['!type:AllSelector'] and tableData['!type:AllSelector'].children | ||
if not children then return 'Таблица не содержит элементов.' end | if not children then return 'Таблица не содержит элементов.' end | ||
return processNestedSelectors(children) | |||
end | end | ||
| Строка 159: | Строка 87: | ||
or containers.entity_storage and containers.entity_storage.tableId | or containers.entity_storage and containers.entity_storage.tableId | ||
or containers.other_storage and containers.other_storage.tableId | or containers.other_storage and containers.other_storage.tableId | ||
if tableId then | if tableId then | ||
result = result .. getTableOutput(tableId | result = result .. getTableOutput(tableId) | ||
else | else | ||
result = result .. 'Таблица не найдена.' | result = result .. 'Таблица не найдена.' | ||
| Строка 199: | Строка 123: | ||
if not id then return 'Не указан ID.' end | if not id then return 'Не указан ID.' end | ||
local data = loadData('User:IanComradeBot/prototypes/fills/Item.json') | local data = loadData('User:IanComradeBot/prototypes/fills/Item.json', 'items') | ||
if not data then return 'Не удалось загрузить данные.' end | if not data then return 'Не удалось загрузить данные.' end | ||