Модуль:Prototypes/Хранилище/Предмет: различия между версиями
Pok (обсуждение | вклад) мНет описания правки |
Pok (обсуждение | вклад) мНет описания правки |
||
| Строка 292: | Строка 292: | ||
--------------------------------------------------------------------- | --------------------------------------------------------------------- | ||
-- Формирование списка химии | -- Формирование списка химии | ||
getChemOutput = function( | getChemOutput = function(id) | ||
local function loadSolutionData(solutionType) | local function loadSolutionData(solutionType) | ||
local modulePath = string.format("Модуль:IanComradeBot/prototypes/fills/chem/%s.json/data", solutionType) | local modulePath = string.format("Модуль:IanComradeBot/prototypes/fills/chem/%s.json/data", solutionType) | ||
| Строка 308: | Строка 300: | ||
local function processSolution(solutionType) | local function processSolution(solutionType) | ||
local solutionModule = loadSolutionData(solutionType) | local solutionModule = loadSolutionData(solutionType) | ||
if not solutionModule | if not solutionModule then | ||
return "" | |||
end | |||
local item = findDataById(solutionModule, id) | |||
if not item then | |||
return "" | |||
end | |||
local solutionData = item[solutionType] or item | |||
if not solutionData or not solutionData.reagents then | |||
return "" | return "" | ||
end | end | ||
local output = "" | local output = "" | ||
for _, reagent in ipairs(solutionData.reagents) do | |||
local chemInfo = chemTranslateData[reagent.ReagentId] | |||
local displayName = chemInfo and chemInfo.name or reagent.ReagentId | |||
output = output .. string.format( | |||
'<li>[[Химия#chem_%s|%s]] (%d ед.)</li>', | |||
reagent.ReagentId, displayName, reagent.Quantity | |||
) | |||
end | end | ||
return output | return output | ||
| Строка 331: | Строка 327: | ||
local result = "" | local result = "" | ||
local solutionTypes = {"drink", "beaker", "injector", "pen"} | |||
for _, solutionType in ipairs(solutionTypes) do | |||
result = result .. processSolution(solutionType) | |||
end | |||
return result ~= "" and string.format('<ul>%s</ul>', result) or '' | return result ~= "" and string.format('<ul><b>%s</b></ul>', result) or '' | ||
end | end | ||
| Строка 358: | Строка 353: | ||
local id = frame.args[2] | local id = frame.args[2] | ||
if not id then return 'Не указан ID.' end | if not id then | ||
return 'Не указан ID.' | |||
end | |||
local itemDataIndex = itemData | local itemDataIndex = itemData | ||
if not itemData then return 'Не удалось загрузить данные.' end | if not itemData then | ||
return 'Не удалось загрузить данные.' | |||
end | |||
if mode == 'framing' then | if mode == 'framing' then | ||
| Строка 373: | Строка 372: | ||
if subMode == 'chem' then | if subMode == 'chem' then | ||
return frame:preprocess('{{СollapsibleMenu|color=#3e7c82|' .. getChemOutput( | return frame:preprocess('{{СollapsibleMenu|color=#3e7c82|' .. getChemOutput(id) .. '}}') | ||
elseif subMode == 'contained' then | elseif subMode == 'contained' then | ||
return frame:preprocess('{{СollapsibleMenu|' .. getContainedOutput(itemDataIndex, id) .. '}}') | return frame:preprocess('{{СollapsibleMenu|' .. getContainedOutput(itemDataIndex, id) .. '}}') | ||
| Строка 400: | Строка 399: | ||
return count or "" | return count or "" | ||
elseif mode == 'chem' then | elseif mode == 'chem' then | ||
return getChemOutput( | return getChemOutput(id) | ||
elseif mode == 'contained' then | elseif mode == 'contained' then | ||
return frame:preprocess(getContainedOutput(itemDataIndex, id)) | return frame:preprocess(getContainedOutput(itemDataIndex, id)) | ||
| Строка 419: | Строка 418: | ||
elseif mode == 'rolls' then | elseif mode == 'rolls' then | ||
local entity = findDataById(itemDataIndex, id) | local entity = findDataById(itemDataIndex, id) | ||
if not entity then return 'ID не найден в данных.' end | if not entity then | ||
return 'ID не найден в данных.' | |||
end | |||
if entity.EntityTableContainerFill then | if entity.EntityTableContainerFill then | ||
local containers = entity.EntityTableContainerFill.containers | local containers = entity.EntityTableContainerFill.containers | ||