Модуль:Prototypes/Хранилище/Предмет: различия между версиями
Pok (обсуждение | вклад) мНет описания правки |
Pok (обсуждение | вклад) мНет описания правки Метка: ручная отмена |
||
| Строка 4: | Строка 4: | ||
local dataCache = {} | local dataCache = {} | ||
local indexCache = {} | local indexCache = {} | ||
-- Функция processRolls для преобразования диапазона | -- Функция processRolls для преобразования диапазона | ||
local processRolls = function(rolls) | local processRolls = function(rolls) | ||
local result = {} | local result = {} | ||
if rolls and rolls.range then | if rolls and rolls.range then | ||
-- Если указан range | |||
local min, max = rolls.range:match("(%d+),%s*(%d+)") | local min, max = rolls.range:match("(%d+),%s*(%d+)") | ||
min, max = tonumber(min), tonumber(max) | min, max = tonumber(min), tonumber(max) | ||
| Строка 23: | Строка 18: | ||
end | end | ||
elseif rolls and rolls.value then | elseif rolls and rolls.value then | ||
-- Если указано value | |||
result[#result + 1] = string.format('Будет сгенерировано %d предметов.', rolls.value) | result[#result + 1] = string.format('Будет сгенерировано %d предметов.', rolls.value) | ||
else | else | ||
result[#result + 1] = 'Не указан параметр rolls.' | result[#result + 1] = 'Не указан параметр rolls.' | ||
end | end | ||
return table.concat(result) | |||
end | end | ||
| Строка 68: | Строка 62: | ||
end | end | ||
local name = string.format('{{#invoke:Entity Lookup|getname|%s}}', content.id) | |||
local image = string.format('%s.png', content.id) | |||
local amount = content.amount and string.format(" [%d]", content.amount) or "" | local amount = content.amount and string.format(" [%d]", content.amount) or "" | ||
local prob = "" | local prob = "" | ||
| Строка 80: | Строка 76: | ||
return string.format( | return string.format( | ||
'{{LinkСard | '{{LinkСard|SideStyle=1|background-color=#cbcbff0b|image=%s|name=%s%s%s {{#invoke:Prototypes/Хранилище/Предмет|main|framing|contained|%s}} }}', | ||
image, name, amount, prob, content.id | |||
) | ) | ||
end | end | ||
| Строка 89: | Строка 85: | ||
local result = {} | local result = {} | ||
for _, content in ipairs(contents) do | for _, content in ipairs(contents) do | ||
result[#result + 1] = | result[#result + 1] = formatContent(content) | ||
end | end | ||
return table.concat(result) | |||
end | end | ||
| Строка 125: | Строка 116: | ||
-- Обработка таблиц | -- Обработка таблиц | ||
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(buildIndex(allSelectors), tableId) | local tableData = findDataById(buildIndex(allSelectors), tableId) | ||
if not tableData then | if not tableData then return 'Таблица не найдена.' end | ||
if tableData['!type:GroupSelector'] then | if tableData['!type:GroupSelector'] then | ||
return handleGroupSelector(tableData['!type:GroupSelector']) | |||
elseif tableData['!type:AllSelector'] then | elseif tableData['!type:AllSelector'] then | ||
return processNestedSelectors(tableData['!type:AllSelector'].children) | |||
end | end | ||
return | return 'Таблица не содержит элементов.' | ||
end | end | ||
| Строка 248: | Строка 232: | ||
-- Формирование списка химии | -- Формирование списка химии | ||
getChemOutput = function(data, id) | getChemOutput = function(data, id) | ||
local item = findDataById(data, id) | local item = findDataById(data, id) | ||
if not item or not item.SolutionContainerManager or not item.SolutionContainerManager.solutions then | if not item or not item.SolutionContainerManager or not item.SolutionContainerManager.solutions then return '' end | ||
local result = {} | local result = {} | ||
| Строка 262: | Строка 241: | ||
end | end | ||
end | end | ||
return string.format('<ul class="1">%s</ul>', table.concat(result)) | |||
end | end | ||