Модуль:Песочница/Pok: различия между версиями
Pok (обсуждение | вклад) Нет описания правки |
Pok (обсуждение | вклад) Нет описания правки |
||
| Строка 1: | Строка 1: | ||
local p = {} | local p = {} | ||
-- Загружаем данные из отдельных модулей | -- Загружаем данные из отдельных модулей | ||
local itemData = mw.loadData("Модуль | local itemData = mw.loadData("Модуль:IanComradeBot/prototypes/fills/Item.json/data") | ||
local tableData = mw.loadData("Модуль | local tableData = mw.loadData("Модуль:IanComradeBot/prototypes/table.json/data") | ||
-- Локализация всех функций | |||
local processRolls, buildIndex, findDataById, formatContent, getContentsOutput, | |||
processNestedSelectors, getTableOutput, getContainedOutput, handleAllSelector, | |||
handleGroupSelector, handleNestedSelector, getChemOutput | |||
----------------------------------------------------------- | ----------------------------------------------------------- | ||
processRolls = function(rolls) | |||
local result = {} | local result = {} | ||
if rolls and rolls.range then | if rolls and rolls.range then | ||
| Строка 26: | Строка 30: | ||
----------------------------------------------------------- | ----------------------------------------------------------- | ||
buildIndex = function(data) | |||
if not data then return {} end | if not data then return {} end | ||
local index = {} | local index = {} | ||
| Строка 36: | Строка 39: | ||
end | end | ||
-- | ----------------------------------------------------------- | ||
findDataById = function(dataIndex, id) | |||
return dataIndex and dataIndex[id] or nil | return dataIndex and dataIndex[id] or nil | ||
end | end | ||
----------------------------------------------------------- | ----------------------------------------------------------- | ||
formatContent = function(content) | |||
if not content.id then | if not content.id then | ||
return "Ошибка: отсутствует id у элемента." | return "Ошибка: отсутствует id у элемента." | ||
| Строка 69: | Строка 71: | ||
----------------------------------------------------------- | ----------------------------------------------------------- | ||
getContentsOutput = function(contents) | |||
local result = {} | local result = {} | ||
for _, content in ipairs(contents) do | for _, content in ipairs(contents) do | ||
| Строка 79: | Строка 80: | ||
----------------------------------------------------------- | ----------------------------------------------------------- | ||
processNestedSelectors = function(children) | |||
if not children or #children == 0 then return "" end | if not children or #children == 0 then return "" end | ||
| Строка 98: | Строка 98: | ||
----------------------------------------------------------- | ----------------------------------------------------------- | ||
getTableOutput = function(tableId) | |||
local tableIndex = buildIndex(tableData) | local tableIndex = buildIndex(tableData) | ||
local tableItem = findDataById(tableIndex, tableId) | local tableItem = findDataById(tableIndex, tableId) | ||
| Строка 114: | Строка 113: | ||
----------------------------------------------------------- | ----------------------------------------------------------- | ||
getContainedOutput = function(dataIndex, id) | |||
local item = findDataById(dataIndex, id) | local item = findDataById(dataIndex, id) | ||
if not item then return '' end | if not item then return '' end | ||
| Строка 121: | Строка 119: | ||
local result = {} | local result = {} | ||
if item.StorageFill and item.StorageFill.contents then | if item.StorageFill and item.StorageFill.contents then | ||
result[#result + 1] = getContentsOutput(item.StorageFill.contents) | result[#result + 1] = getContentsOutput(item.StorageFill.contents) | ||
elseif item.EntityTableContainerFill and item.EntityTableContainerFill.containers then | elseif item.EntityTableContainerFill and item.EntityTableContainerFill.containers then | ||
local containers = item.EntityTableContainerFill.containers | local containers = item.EntityTableContainerFill.containers | ||
if containers.entity_storage then | if containers.entity_storage then | ||
if containers.entity_storage.children then | if containers.entity_storage.children then | ||
result[#result + 1] = processNestedSelectors(containers.entity_storage.children) | result[#result + 1] = processNestedSelectors(containers.entity_storage.children) | ||
end | end | ||
if containers.entity_storage.tableId then | if containers.entity_storage.tableId then | ||
result[#result + 1] = getTableOutput(containers.entity_storage.tableId) | result[#result + 1] = getTableOutput(containers.entity_storage.tableId) | ||
| Строка 140: | Строка 133: | ||
end | end | ||
if containers.storagebase and containers.storagebase.tableId then | if containers.storagebase and containers.storagebase.tableId then | ||
result[#result + 1] = getTableOutput(containers.storagebase.tableId) | result[#result + 1] = getTableOutput(containers.storagebase.tableId) | ||
| Строка 150: | Строка 142: | ||
----------------------------------------------------------- | ----------------------------------------------------------- | ||
handleAllSelector = function(allSelector) | |||
if not allSelector.children then return '' end | if not allSelector.children then return '' end | ||
return processNestedSelectors(allSelector.children) | return processNestedSelectors(allSelector.children) | ||
| Строка 157: | Строка 148: | ||
----------------------------------------------------------- | ----------------------------------------------------------- | ||
handleGroupSelector = function(groupSelector) | |||
if not groupSelector.children then return '' end | if not groupSelector.children then return '' end | ||
local result = {} | local result = {} | ||
| Строка 187: | Строка 177: | ||
----------------------------------------------------------- | ----------------------------------------------------------- | ||
handleNestedSelector = function(nestedSelector, wrapped) | |||
if not nestedSelector.tableId then return '' end | if not nestedSelector.tableId then return '' end | ||
| Строка 208: | Строка 197: | ||
if wrapped and (classesRolls or classesProb) then | if wrapped and (classesRolls or classesProb) then | ||
result[#result + 1] = string.format('{{LinkСard/Сollapsible|name=Группа предметов%s%s|content=', | result[#result + 1] = string.format('{{LinkСard/Сollapsible|name=Группа предметов%s%s|content=', classesRolls or "", classesProb or "") | ||
end | end | ||
| Строка 222: | Строка 210: | ||
----------------------------------------------------------- | ----------------------------------------------------------- | ||
getChemOutput = function(dataIndex, id) | |||
local item = findDataById(dataIndex, id) | local item = findDataById(dataIndex, 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 | ||
| Строка 241: | Строка 228: | ||
----------------------------------------------------------- | ----------------------------------------------------------- | ||
function p.main(frame) | function p.main(frame) | ||
local mode = frame.args[1] | local mode = frame.args[1] | ||
| Строка 258: | Строка 244: | ||
local subMode = frame.args[2] | local subMode = frame.args[2] | ||
local id = frame.args[3] | local id = frame.args[3] | ||
if not id then | if not id then | ||
return 'Не указан ID для режима framing.' | return 'Не указан ID для режима framing.' | ||