Модуль:Prototypes/Хранилище/Предмет: различия между версиями
Pok (обсуждение | вклад) мНет описания правки |
Pok (обсуждение | вклад) мНет описания правки |
||
| (не показано 7 промежуточных версий этого же участника) | |||
| Строка 1: | Строка 1: | ||
--------------------------------------------------------------------- | --------------------------------------------------------------------- | ||
-- Функция поиска данных по ID | -- Функция поиска данных по ID | ||
| Строка 60: | Строка 52: | ||
end | end | ||
-- Имитирует "string.format('{{#invoke:Предмет|main|%s|%s<span>%s</span>|repository=1|wrapper=1}}', id, amount, prob)", но работает быстрее, поэтому так | |||
return "{{LinkCard|название={{#invoke:Entity Lookup|getname|" .. id .. "}} {{#invoke:Prototypes/Хранилище/Предмет|main|framing|stack|" .. id .. "}} ".. amount .." <span>" .. prob .. "</span>|пин={{#invoke:Prototypes/Хранилище/Предмет|main|framing|contained|" .. id .. "}} {{#invoke:Prototypes/Хранилище/Предмет|main|framing|slot|" .. id .. "}} {{#invoke:Prototypes/Хранилище/Предмет|main|framing|chem|" .. id .. "}}|изображение=[[Файл:" .. id .. ".png|32px]]|горизонт_стиль=1}}" | |||
end | end | ||
| Строка 99: | Строка 92: | ||
-- Получение содержимого таблицы по 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 | ||
| Строка 185: | Строка 179: | ||
local wrapperStart, wrapperEnd = "", "" | local wrapperStart, wrapperEnd = "", "" | ||
if groupSelector.weight and groupSelector.weight ~= "default" then | if groupSelector.weight and groupSelector.weight ~= "default" then | ||
wrapperStart = string.format('{{ | wrapperStart = string.format('{{LinkCard/Сollapsible|название=Группа предметов %s%%|содержание=', groupSelector.weight) | ||
wrapperEnd = "}}" | wrapperEnd = "}}" | ||
elseif groupSelector["!type"] == "GroupSelector" and not groupSelector.weight then | elseif groupSelector["!type"] == "GroupSelector" and not groupSelector.weight then | ||
wrapperStart = '{{ | wrapperStart = '{{LinkCard/Сollapsible|название=Может выпасть лишь один из:|содержание=' | ||
wrapperEnd = "}}" | wrapperEnd = "}}" | ||
end | end | ||
| Строка 196: | Строка 190: | ||
result[#result + 1] = handleGroupSelector(child, visited) | result[#result + 1] = handleGroupSelector(child, visited) | ||
elseif child["!type"] == "AllSelector" then | elseif child["!type"] == "AllSelector" then | ||
result[#result + 1] = string.format('{{ | result[#result + 1] = string.format('{{LinkCard/Сollapsible|название=Выпадают только вместе:|содержание=%s}}', handleAllSelector(child)) | ||
elseif child.id then | elseif child.id then | ||
result[#result + 1] = formatContent(child) | result[#result + 1] = formatContent(child) | ||
| Строка 228: | Строка 222: | ||
if wrapped and (classesRolls ~= "" or classesProb ~= "") then | if wrapped and (classesRolls ~= "" or classesProb ~= "") then | ||
result[#result + 1] = string.format('{{ | result[#result + 1] = string.format('{{LinkCard/Сollapsible|название=Группа предметов%s%s|содержание=', classesRolls, classesProb) | ||
end | end | ||
| Строка 261: | Строка 255: | ||
-- Формирование списка химии | -- Формирование списка химии | ||
function getChemOutput(id) | function getChemOutput(id) | ||
local chemTranslateData = mw.loadData("Модуль:IanComradeBot/chem prototypes.json/data") | |||
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) | ||
| Строка 311: | Строка 307: | ||
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: | Строка 343: | ||
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: | Строка 381: | ||
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: | Строка 395: | ||
end | end | ||
return '' | return '' | ||
else | else | ||
return 'Неизвестный режим: ' .. mode | return 'Неизвестный режим: ' .. mode | ||