Модуль:Песочница/Pok: различия между версиями
Pok (обсуждение | вклад) мНет описания правки |
Pok (обсуждение | вклад) Нет описания правки |
||
| Строка 1: | Строка 1: | ||
local p = {} | local p = {} | ||
-- Функция 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 | ||
-- Функция для | -- Функция для загрузки данных без кэширования | ||
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=# | '{{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 allSelectors = loadData('User:IanComradeBot/prototypes/AllSelector.json') | |||
local tableData = findDataById( | 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 data = loadData('User:IanComradeBot/prototypes/fills/Item.json') | |||
local dataIndex = buildIndex(data) | |||
if not data then return 'Не удалось загрузить данные.' end | if not data then return 'Не удалось загрузить данные.' end | ||