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

Нет описания правки
Метка: ручная отмена
Нет описания правки
Строка 1: Строка 1:
-- Загрузка данных
-- Загрузка данных
local data = mw.loadData("Модуль:IanComradeBot/prototypes/fills/Item.json/data")
local itemData = mw.loadData("Модуль:IanComradeBot/prototypes/fills/Item.json/data")
local allSelectorData = mw.loadData("Модуль:IanComradeBot/prototypes/table.json/data")
local tableData = mw.loadData("Модуль:IanComradeBot/prototypes/table.json/data")


local p = {}
local p = {}
Строка 37: Строка 37:


-- Функция для создания хэш-таблицы для быстрого поиска по ID
-- Функция для создания хэш-таблицы для быстрого поиска по ID
local function buildIndex(data)
local function buildIndex(itemData)
     if not data then return {} end
     if not itemData then return {} end
     local index = {}
     local index = {}
     for _, item in ipairs(data) do
     for _, item in ipairs(itemData) do
         index[item.id] = item
         index[item.id] = item
     end
     end
Строка 47: Строка 47:


-- Поиск данных по ID через индекс
-- Поиск данных по ID через индекс
findDataById = function(dataIndex, id)
findDataById = function(itemDataIndex, id)
     return dataIndex and dataIndex[id] or nil
     return itemDataIndex and itemDataIndex[id] or nil
end
end


Строка 106: Строка 106:
-- Обработка таблиц
-- Обработка таблиц
getTableOutput = function(tableId)
getTableOutput = function(tableId)
     local allSelectors = loadData('User:IanComradeBot/prototypes/table.json')
     local tableData = loadData('User:IanComradeBot/prototypes/table.json')
     local tableData = findDataById(buildIndex(allSelectors), tableId)
     local tableDataIndex = findDataById(buildIndex(tableData), tableId)


     if not tableData then return 'Таблица не найдена.' end
     if not tableDataIndex then return 'Таблица не найдена.' end


     if tableData['!type:GroupSelector'] then
     if tableDataIndex['!type:GroupSelector'] then
         return handleGroupSelector(tableData['!type:GroupSelector'])
         return handleGroupSelector(tableData['!type:GroupSelector'])
     elseif tableData['!type:AllSelector'] then
     elseif tableDataIndex['!type:AllSelector'] then
         return processNestedSelectors(tableData['!type:AllSelector'].children)
         return processNestedSelectors(tableData['!type:AllSelector'].children)
     end
     end
Строка 121: Строка 121:


-- Формирование списка содержащихся предметов или таблиц
-- Формирование списка содержащихся предметов или таблиц
getContainedOutput = function(data, id)
getContainedOutput = function(itemData, id)
     local item = findDataById(data, id)
     local item = findDataById(itemData, id)
     if not item then return '' end
     if not item then return '' end


Строка 229: Строка 229:


-- Формирование списка химии
-- Формирование списка химии
getChemOutput = function(data, id)
getChemOutput = function(itemData, id)
     local item = findDataById(data, id)
     local item = findDataById(itemData, id)
     if not item or not item.SolutionContainerManager or not item.SolutionContainerManager.solutions then return '' end
     if not item or not item.SolutionContainerManager or not item.SolutionContainerManager.solutions then return '' end


Строка 249: Строка 249:
     if not id then return 'Не указан ID.' end
     if not id then return 'Не указан ID.' end
      
      
local dataIndex = buildIndex(data)
local itemDataIndex = buildIndex(itemData)
     if not data then return 'Не удалось загрузить данные.' end
     if not itemData then return 'Не удалось загрузить данные.' end


     if mode == 'framing' then
     if mode == 'framing' then
Строка 262: Строка 262:


         if subMode == 'chem' then
         if subMode == 'chem' then
             return frame:preprocess('{{СollapsibleMenu|' .. getChemOutput(dataIndex, id) .. '}}')
             return frame:preprocess('{{СollapsibleMenu|' .. getChemOutput(itemDataIndex, id) .. '}}')
         elseif subMode == 'contained' then
         elseif subMode == 'contained' then
             return frame:preprocess('{{СollapsibleMenu|' .. getContainedOutput(dataIndex, id) .. '}}')
             return frame:preprocess('{{СollapsibleMenu|' .. getContainedOutput(itemDataIndex, id) .. '}}')
         else
         else
             return 'Неизвестный подрежим для framing: ' .. subMode
             return 'Неизвестный подрежим для framing: ' .. subMode
         end
         end
     elseif mode == 'chem' then
     elseif mode == 'chem' then
         return frame:preprocess(getChemOutput(dataIndex, id))
         return frame:preprocess(getChemOutput(itemDataIndex, id))
     elseif mode == 'contained' then
     elseif mode == 'contained' then
         return frame:preprocess(getContainedOutput(dataIndex, id))
         return frame:preprocess(getContainedOutput(itemDataIndex, id))
     elseif mode == 'rolls' then
     elseif mode == 'rolls' then
         local entity = findDataById(dataIndex, id)
         local entity = findDataById(itemDataIndex, id)
         if not entity then return 'ID не найден в данных.' end
         if not entity then return 'ID не найден в данных.' end