Модуль:Prototypes/Хранилище/Предмет: различия между версиями
Материал из Space Station 14 Вики
Pok (обсуждение | вклад) м Pok переименовал страницу Модуль:Prototypes/Предмет/Хранилища в Модуль:Prototypes/Хранилища/Предмет без оставления перенаправления |
Pok (обсуждение | вклад) Нет описания правки |
||
Строка 49: | Строка 49: | ||
if contents then | if contents then | ||
for _, content in ipairs(contents) do | for _, content in ipairs(contents) do | ||
result = result .. string.format('{{LinkСard|SideStyle=1|background-color=#d7d7ff0b|image=%s.png|name={{#invoke:Entity Lookup|getname|%s}}%s }}', content.id, content.id, content.amount and string.format(" [%d]", content.amount) or "") | result = result .. string.format('{{LinkСard|SideStyle=1|background-color=#d7d7ff0b|image=%s.png|name={{#invoke:Entity Lookup|getname|%s}}%s }}', content.id, content.id, content.amount and string.format(" [%d]", content.amount) or "", content.prob and string.format(" <div>%c</div>]", content.prob) or "") | ||
end | end | ||
elseif tableContainer then | elseif tableContainer then | ||
Строка 60: | Строка 60: | ||
if children then | if children then | ||
for _, child in ipairs(children) do | for _, child in ipairs(children) do | ||
result = result .. string.format('{{LinkСard|SideStyle=1|background-color=#d7d7ff0b|image=%s.png|name={{#invoke:Entity Lookup|getname|%s}}%s }}', | result = result .. string.format('{{LinkСard|SideStyle=1|background-color=#d7d7ff0b|image=%s.png|name={{#invoke:Entity Lookup|getname|%s}}%s }}', content.id, content.id, content.amount and string.format(" [%d]", content.amount) or "", content.prob and string.format(" <div>%c</div>]", content.prob) or "") | ||
end | end | ||
else | else |
Версия от 01:43, 27 января 2025
Для документации этого модуля может быть создана страница Модуль:Prototypes/Хранилище/Предмет/doc
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 item
end
end
return nil
end
-- Формирование списка веществ
local function getChemOutput(data, id)
local item = findDataById(data, id)
if not item then return '' end
local solutions = item.SolutionContainerManager and item.SolutionContainerManager.solutions
if not solutions then return '' end
local result = '<ul class="1">'
for _, solution in pairs(solutions) do
for _, reagent in ipairs(solution.reagents) do
result = result .. string.format('<li>[[Химия#chem_%s|%s]] (%d ед.)</li>', reagent.ReagentId, reagent.ReagentId, reagent.Quantity)
end
end
result = result .. '</ul>'
return mw.getCurrentFrame():preprocess(result)
end
-- Формирование списка содержащихся предметов или таблиц
local function getContainedOutput(data, id, wrapped)
local item = findDataById(data, id)
if not item then return '' end
local contents = item.StorageFill and item.StorageFill.contents
local tableContainer = item.EntityTableContainerFill and item.EntityTableContainerFill.containers
local result = wrapped and '<div class="2">' or ''
if contents then
for _, content in ipairs(contents) do
result = result .. string.format('{{LinkСard|SideStyle=1|background-color=#d7d7ff0b|image=%s.png|name={{#invoke:Entity Lookup|getname|%s}}%s }}', content.id, content.id, content.amount and string.format(" [%d]", content.amount) or "", content.prob and string.format(" <div>%c</div>]", content.prob) or "")
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
result = result .. string.format('{{LinkСard|SideStyle=1|background-color=#d7d7ff0b|image=%s.png|name={{#invoke:Entity Lookup|getname|%s}}%s }}', content.id, content.id, content.amount and string.format(" [%d]", content.amount) or "", content.prob and string.format(" <div>%c</div>]", content.prob) or "")
end
else
result = result .. 'Таблица не содержит элементов.'
end
else
result = result .. 'Таблица не найдена.'
end
else
result = result .. ''
end
if wrapped then
result = result .. '</div>'
end
return mw.getCurrentFrame():preprocess(result)
end
-- Основная функция модуля
function p.main(frame)
local mode = frame.args[1]
local id = frame.args[2]
if not id then return 'Не указан ID.' end
local data = loadData('User:IanComradeBot/prototypes/fills/Item.json')
if not data then return 'Не удалось загрузить данные.' end
if mode == 'chem' then
return getChemOutput(data, id)
elseif mode == 'contained' then
return getContainedOutput(data, id, false)
elseif mode == 'framing' then
return getContainedOutput(data, id, true)
else
return 'Неизвестный режим: ' .. mode
end
end
return p