Модуль:Prototypes/Хранилище/Предмет: различия между версиями
Pok (обсуждение | вклад) мНет описания правки |
Pok (обсуждение | вклад) мНет описания правки |
||
| Строка 82: | Строка 82: | ||
local function processAllSelectors(children) end | local function processAllSelectors(children) end | ||
-- AllSelectors | -- AllSelectors | ||
| Строка 161: | Строка 146: | ||
end | end | ||
-- | -- Функция обработки всех селекторов | ||
local function | local function processAllSelectors(children) | ||
local result = '' | |||
for _, child in ipairs(children) do | |||
if child.id then | |||
result = result .. formatContent(child) | |||
elseif child["!type"] == "GroupSelector" and child.children then | |||
result = result .. processNestedSelectors(child.children, 1) | |||
elseif child["!type"] == "AllSelector" and child.children then | |||
result = result .. processAllSelectors(child.children) | |||
elseif child["!type"] == "NestedSelector" and child.tableId then | |||
local nestedRolls | |||
if child.rolls then | |||
if child.rolls.value then | |||
nestedRolls = child.rolls.value | |||
elseif child.rolls.range then | |||
local rangeParts = {string.match(child.rolls.range, "(%d+),%s*(%d+)")} | |||
nestedRolls = math.random(tonumber(rangeParts[1]), tonumber(rangeParts[2])) | |||
else | |||
nestedRolls = 1 | |||
end | |||
else | |||
nestedRolls = 1 | |||
end | |||
result = result .. getTableOutput(child.tableId, nestedRolls) | |||
end | |||
end | |||
return result | |||
end | |||
local | -- Обработка таблиц | ||
local function getTableOutput(tableId, rolls) | |||
local allSelectors = loadData('User:IanComradeBot/prototypes/AllSelector.json', 'selectors') | |||
local tableData = findDataById(allSelectors, tableId) | |||
local children = tableData and (tableData['!type:GroupSelector'] and tableData['!type:GroupSelector'].children or tableData['!type:AllSelector'] and tableData['!type:AllSelector'].children) | |||
if not children then return 'Таблица не содержит элементов.' end | |||
if tableData['!type:AllSelector'] then | |||
return processAllSelectors(children) | |||
else | |||
return processNestedSelectors(children, rolls) | |||
end | end | ||
end | end | ||