Модуль:Prototypes/Хранилище/Предмет: различия между версиями
Pok (обсуждение | вклад) мНет описания правки |
Pok (обсуждение | вклад) мНет описания правки |
||
| Строка 1: | Строка 1: | ||
--------------------------------------------------------------------- | --------------------------------------------------------------------- | ||
-- Функция поиска данных по ID | -- Функция поиска данных по ID | ||
| Строка 99: | Строка 91: | ||
-- Получение содержимого таблицы по tableId с кешированием | -- Получение содержимого таблицы по tableId с кешированием | ||
local function getTableOutput(tableId, visited) | local function getTableOutput(tableId, visited) | ||
local tableData = mw.loadData("Модуль:IanComradeBot/prototypes/table.json/data") | |||
visited = visited or {} | visited = visited or {} | ||
if visited[tableId] then return "" end | if visited[tableId] then return "" end | ||
| Строка 311: | Строка 304: | ||
function p.main(frame) | function p.main(frame) | ||
local mode = frame.args[1] | local mode = frame.args[1] | ||
local id = frame.args[2] | local id = frame.args[2] | ||
if not | if not id then | ||
return 'Не | return 'Не указан ID.' | ||
end | end | ||
if mode == 'framing' then | if mode == 'framing' then | ||
local subMode = frame.args[2] | local subMode = frame.args[2] | ||
local idFraming = frame.args[3] | local idFraming = frame.args[3] | ||
if not idFraming then | if not idFraming then | ||
return 'Не указан ID для режима framing.' | return 'Не указан ID для режима framing.' | ||
end | end | ||
if subMode == 'chem' then | if subMode == 'chem' then | ||
return frame:preprocess('{{СollapsibleMenu|color=#3e7c82|' .. getChemOutput(idFraming) .. '}}') | local chemTranslateData = mw.loadData("Модуль:IanComradeBot/chem prototypes.json/data") | ||
return frame:preprocess('{{СollapsibleMenu|color=#3e7c82|' .. getChemOutput(idFraming, chemTranslateData) .. '}}') | |||
elseif subMode == 'contained' then | elseif subMode == 'contained' then | ||
local itemData = mw.loadData("Модуль:IanComradeBot/prototypes/fills/Item.json/data") | |||
return frame:preprocess('{{СollapsibleMenu|' .. getContainedOutput(itemData, idFraming) .. '}}') | return frame:preprocess('{{СollapsibleMenu|' .. getContainedOutput(itemData, idFraming) .. '}}') | ||
elseif subMode == "slot" then | elseif subMode == "slot" then | ||
local | local itemSlotsData = mw.loadData("Модуль:IanComradeBot/prototypes/ItemSlots.json/data") | ||
if not | local entry = findDataById(itemSlotsData, idFraming) | ||
local startingItem | if not entry then return "" end | ||
if | local startingItem | ||
for _, slot in ipairs( | if entry.ItemSlots and entry.ItemSlots.slots then | ||
for _, slot in ipairs(entry.ItemSlots.slots) do | |||
if slot.startingItem and slot.startingItem ~= "" then | if slot.startingItem and slot.startingItem ~= "" then | ||
startingItem = slot.startingItem | startingItem = slot.startingItem | ||
| Строка 345: | Строка 340: | ||
if not startingItem then return "" end | if not startingItem then return "" end | ||
return frame:preprocess('{{СollapsibleMenu|color=#71702a|' .. formatContent(startingItem) .. '}}') | return frame:preprocess('{{СollapsibleMenu|color=#71702a|' .. formatContent(startingItem) .. '}}') | ||
elseif subMode == "stack" then | elseif subMode == "stack" then | ||
local count = getStackCount(idFraming) | local itemStackData = mw.loadData("Модуль:IanComradeBot/prototypes/fills/stack.json/data") | ||
return count and '(' .. count .. ')' or "" | local count = getStackCount(idFraming, itemStackData) | ||
return count and ('(' .. count .. ')') or "" | |||
else | else | ||
return 'Неизвестный подрежим для framing: ' .. subMode | return 'Неизвестный подрежим для framing: ' .. subMode | ||
end | end | ||
elseif mode == 'stack' then | elseif mode == 'stack' then | ||
local count = getStackCount(id) | local itemStackData = mw.loadData("Модуль:IanComradeBot/prototypes/fills/stack.json/data") | ||
local count = getStackCount(id, itemStackData) | |||
return count or "" | return count or "" | ||
elseif mode == 'chem' then | elseif mode == 'chem' then | ||
return getChemOutput(id) | local chemTranslateData = mw.loadData("Модуль:IanComradeBot/chem prototypes.json/data") | ||
return getChemOutput(id, chemTranslateData) | |||
elseif mode == 'contained' then | elseif mode == 'contained' then | ||
local itemData = mw.loadData("Модуль:IanComradeBot/prototypes/fills/Item.json/data") | |||
return frame:preprocess(getContainedOutput(itemData, id)) | return frame:preprocess(getContainedOutput(itemData, id)) | ||
elseif mode == "slot" then | elseif mode == "slot" then | ||
local | local itemSlotsData = mw.loadData("Модуль:IanComradeBot/prototypes/ItemSlots.json/data") | ||
if not | local entry = findDataById(itemSlotsData, id) | ||
local startingItem | if not entry then return "" end | ||
if | local startingItem | ||
for _, slot in ipairs( | if entry.ItemSlots and entry.ItemSlots.slots then | ||
for _, slot in ipairs(entry.ItemSlots.slots) do | |||
if slot.startingItem and slot.startingItem ~= "" then | if slot.startingItem and slot.startingItem ~= "" then | ||
startingItem = slot.startingItem | startingItem = slot.startingItem | ||
| Строка 372: | Строка 378: | ||
if not startingItem then return "" end | if not startingItem then return "" end | ||
return frame:preprocess(formatContent(startingItem)) | return frame:preprocess(formatContent(startingItem)) | ||
elseif mode == 'rolls' then | elseif mode == 'rolls' then | ||
local itemData = mw.loadData("Модуль:IanComradeBot/prototypes/fills/Item.json/data") | |||
local entity = findDataById(itemData, id) | local entity = findDataById(itemData, id) | ||
if not entity then | if not entity then | ||
return 'ID не найден в данных.' | return 'ID не найден в данных.' | ||
end | end | ||
if entity.EntityTableContainerFill then | if entity.EntityTableContainerFill then | ||
| Строка 384: | Строка 392: | ||
end | end | ||
return '' | return '' | ||
else | else | ||
return 'Неизвестный режим: ' .. mode | return 'Неизвестный режим: ' .. mode | ||