Модуль:Песочница/Pok: различия между версиями
Pok (обсуждение | вклад) Нет описания правки |
Pok (обсуждение | вклад) мНет описания правки |
||
| Строка 1: | Строка 1: | ||
-- Загрузка данных | |||
local dataModule = mw.loadData("Модуль:Prototypes/Хранилище/Предмет/data") | |||
local itemData = dataModule.Item | |||
local allSelectorData = dataModule.AllSelector | |||
local p = {} | local p = {} | ||
-- Функция processRolls для преобразования диапазона | -- Функция processRolls для преобразования диапазона | ||
| Строка 9: | Строка 10: | ||
local result = {} | local result = {} | ||
if rolls and rolls.range then | if rolls and rolls.range then | ||
local min, max = rolls.range:match("(%d+),%s*(%d+)") | local min, max = rolls.range:match("(%d+),%s*(%d+)") | ||
min, max = tonumber(min), tonumber(max) | min, max = tonumber(min), tonumber(max) | ||
| Строка 18: | Строка 18: | ||
end | end | ||
elseif rolls and rolls.value then | elseif rolls and rolls.value then | ||
result[#result + 1] = string.format('[%d]', rolls.value) | result[#result + 1] = string.format('[%d]', rolls.value) | ||
else | else | ||
| Строка 26: | Строка 25: | ||
end | end | ||
-- | -- Поиск данных по ID | ||
local function findDataById(data, id) | |||
local function | |||
for _, item in ipairs(data) do | for _, item in ipairs(data) do | ||
if item.id == id then | |||
return item | |||
end | |||
end | end | ||
return nil | |||
return | |||
end | end | ||
-- Форматирование содержимого | -- Форматирование содержимого | ||
formatContent | local function formatContent(content) | ||
if not content.id then | if not content.id then | ||
return "Ошибка: отсутствует id у элемента." | return "Ошибка: отсутствует id у элемента." | ||
| Строка 64: | Строка 43: | ||
local name = string.format('{{#invoke:Entity Lookup|getname|%s}}', content.id) | local name = string.format('{{#invoke:Entity Lookup|getname|%s}}', content.id) | ||
local image = string.format('%s.png', content.id) | local image = string.format('%s.png', content.id) | ||
local amount = (content.amount and content.amount ~= 1) and string.format(" [%d]", content.amount) or "" | |||
local prob = "" | local prob = "" | ||
| Строка 80: | Строка 59: | ||
) | ) | ||
end | end | ||
-- Локальные функции | |||
local loadData, findDataById, formatContent, getContentsOutput, processNestedSelectors, getTableOutput, getContainedOutput, getChemOutput, handleGroupSelector, handleAllSelector, handleNestedSelector | |||
-- Получение содержимого через таблицу | -- Получение содержимого через таблицу | ||
| Строка 258: | Строка 240: | ||
if not id then return 'Не указан ID.' end | if not id then return 'Не указан ID.' end | ||
if mode == 'framing' then | if mode == 'framing' then | ||
| Строка 273: | Строка 250: | ||
if subMode == 'chem' then | if subMode == 'chem' then | ||
return frame:preprocess('{{СollapsibleMenu|' .. getChemOutput( | return frame:preprocess('{{СollapsibleMenu|' .. getChemOutput(itemData, id) .. '}}') | ||
elseif subMode == 'contained' then | elseif subMode == 'contained' then | ||
return frame:preprocess('{{СollapsibleMenu|' .. getContainedOutput( | return frame:preprocess('{{СollapsibleMenu|' .. getContainedOutput(itemData, id) .. '}}') | ||
else | else | ||
return 'Неизвестный подрежим для framing: ' .. subMode | return 'Неизвестный подрежим для framing: ' .. subMode | ||
end | end | ||
elseif mode == 'chem' then | elseif mode == 'chem' then | ||
return frame:preprocess(getChemOutput( | return frame:preprocess(getChemOutput(itemData, id)) | ||
elseif mode == 'contained' then | elseif mode == 'contained' then | ||
return frame:preprocess(getContainedOutput( | return frame:preprocess(getContainedOutput(itemData, id)) | ||
elseif mode == 'rolls' then | elseif mode == 'rolls' then | ||
local entity = findDataById( | local entity = findDataById(itemData, id) | ||
if not entity then return 'ID не найден в данных.' end | if not entity then return 'ID не найден в данных.' end | ||