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

мНет описания правки
Нет описания правки
Строка 1: Строка 1:
-- Загрузка данных
local data = mw.loadData("Модуль:IanComradeBot/prototypes/fills/Item.json/data")
local allSelectorData = mw.loadData("Модуль:IanComradeBot/prototypes/table.json/data")
local p = {}
local p = {}
-- Функция для загрузки данных
local loadData = function(filePath)
    local page = mw.title.new(filePath)
    local content = page:getContent()
    return content and mw.text.jsonDecode(content) or nil
end


-- Функция processRolls для преобразования диапазона
-- Функция processRolls для преобразования диапазона
Строка 34: Строка 23:


-- Локальные функции
-- Локальные функции
local findDataById, formatContent, getContentsOutput, processNestedSelectors, getTableOutput, getContainedOutput, getChemOutput, handleGroupSelector, handleAllSelector, handleNestedSelector
local loadData, findDataById, formatContent, getContentsOutput, processNestedSelectors, getTableOutput, getContainedOutput, getChemOutput, handleGroupSelector, handleAllSelector, handleNestedSelector


-- Функция для создания хэш-таблицы для быстрого поиска по ID
-- Функция для загрузки данных без кэширования
loadData = function(filePath)
    local page = mw.title.new(filePath)
    local content = page:getContent()
    return content and mw.text.jsonDecode(content) or nil
end
 
-- Создание хэш-таблицы для быстрого поиска по ID
local function buildIndex(data)
local function buildIndex(data)
     if not data then return {} end
     if not data then return {} end
Строка 46: Строка 42:
end
end


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


     return string.format(
     return string.format(
         '{{LinkСard|SideStyle=1|background-color=#cbcbff0a|image=%s|name=%s%s%s {{#invoke:Prototypes/Хранилище/Предмет|main|framing|contained|%s}} }}',
         '{{LinkСard|SideStyle=1|background-color=#cbcbff0b|image=%s|name=%s%s%s {{#invoke:Prototypes/Хранилище/Предмет|main|framing|contained|%s}} }}',
         image, name, amount, prob, content.id
         image, name, amount, prob, content.id
     )
     )
Строка 106: Строка 102:
-- Обработка таблиц
-- Обработка таблиц
getTableOutput = function(tableId)
getTableOutput = function(tableId)
local allSelectorDataIndex = buildIndex(allSelectorData)
    local allSelectors = loadData('User:IanComradeBot/prototypes/AllSelector.json')
     local tableData = findDataById(allSelectorDataIndex, tableId)
     local tableData = findDataById(buildIndex(allSelectors), tableId)


     if not tableData then return 'Таблица не найдена.' end
     if not tableData then return 'Таблица не найдена.' end
Строка 248: Строка 244:


     if not id then return 'Не указан ID.' end
     if not id then return 'Не указан ID.' end
      
 
local dataIndex = buildIndex(data)
     local data = loadData('User:IanComradeBot/prototypes/fills/Item.json')
    local dataIndex = buildIndex(data)
 
     if not data then return 'Не удалось загрузить данные.' end
     if not data then return 'Не удалось загрузить данные.' end