Модуль:Песочница/Pok: различия между версиями

Нет описания правки
Нет описания правки
Строка 1: Строка 1:
local p = {}
local p = {}


-- Загружаем данные из отдельных модулей с JSON-таблицами
-- Загружаем данные из отдельных модулей
local itemData = mw.loadData("Модуль:User:IanComradeBot/prototypes/fills/Item.json/data")
local itemData = mw.loadData("Модуль:IanComradeBot/prototypes/fills/Item.json/data")
local tableData = mw.loadData("Модуль:User:IanComradeBot/prototypes/table.json/data")
local tableData = mw.loadData("Модуль:IanComradeBot/prototypes/table.json/data")
 
-- Локализация всех функций
local processRolls, buildIndex, findDataById, formatContent, getContentsOutput,
      processNestedSelectors, getTableOutput, getContainedOutput, handleAllSelector,
      handleGroupSelector, handleNestedSelector, getChemOutput


-----------------------------------------------------------
-----------------------------------------------------------
-- Функция processRolls для преобразования диапазона
processRolls = function(rolls)
local processRolls = function(rolls)
     local result = {}
     local result = {}
     if rolls and rolls.range then
     if rolls and rolls.range then
Строка 26: Строка 30:


-----------------------------------------------------------
-----------------------------------------------------------
-- Создание хэш-таблицы для быстрого поиска по ID
buildIndex = function(data)
local function buildIndex(data)
     if not data then return {} end
     if not data then return {} end
     local index = {}
     local index = {}
Строка 36: Строка 39:
end
end


-- Поиск данных по ID через хэш-таблицу
-----------------------------------------------------------
local function findDataById(dataIndex, id)
findDataById = function(dataIndex, id)
     return dataIndex and dataIndex[id] or nil
     return dataIndex and dataIndex[id] or nil
end
end


-----------------------------------------------------------
-----------------------------------------------------------
-- Форматирование содержимого
formatContent = function(content)
local function formatContent(content)
     if not content.id then
     if not content.id then
         return "Ошибка: отсутствует id у элемента."
         return "Ошибка: отсутствует id у элемента."
Строка 69: Строка 71:


-----------------------------------------------------------
-----------------------------------------------------------
-- Получение содержимого через таблицу
getContentsOutput = function(contents)
local function getContentsOutput(contents)
     local result = {}
     local result = {}
     for _, content in ipairs(contents) do
     for _, content in ipairs(contents) do
Строка 79: Строка 80:


-----------------------------------------------------------
-----------------------------------------------------------
-- Обработка вложенных таблиц
processNestedSelectors = function(children)
local function processNestedSelectors(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 function getTableOutput(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 function getContainedOutput(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 = {}


    -- Обработка StorageFill
     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)
    -- Обработка EntityTableContainerFill
     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


        -- Обработка entity_storage
         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


        -- Обработка storagebase
         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:


-----------------------------------------------------------
-----------------------------------------------------------
-- Обработка AllSelector
handleAllSelector = function(allSelector)
local function handleAllSelector(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:


-----------------------------------------------------------
-----------------------------------------------------------
-- Обработка GroupSelector
handleGroupSelector = function(groupSelector)
local function handleGroupSelector(groupSelector)
     if not groupSelector.children then return '' end
     if not groupSelector.children then return '' end
     local result = {}
     local result = {}
Строка 187: Строка 177:


-----------------------------------------------------------
-----------------------------------------------------------
-- Обработка NestedSelector
handleNestedSelector = function(nestedSelector, wrapped)
local function handleNestedSelector(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 "")
            classesRolls or "", classesProb or "")
     end
     end


Строка 222: Строка 210:


-----------------------------------------------------------
-----------------------------------------------------------
-- Формирование списка химии
getChemOutput = function(dataIndex, id)
local function getChemOutput(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.'