Модуль:Песочница/Pok: различия между версиями
Pok (обсуждение | вклад) мНет описания правки |
Pok (обсуждение | вклад) Нет описания правки |
||
| Строка 86: | Строка 86: | ||
-- Обработка вложенных таблиц | -- Обработка вложенных таблиц | ||
processNestedSelectors = function(children) | processNestedSelectors = function(children, visited) | ||
if not children or #children == 0 then return "" end | if not children or #children == 0 then return "" end | ||
| Строка 93: | Строка 93: | ||
for _, child in ipairs(children) do | for _, child in ipairs(children) do | ||
if child.id then | if child.id then | ||
results[#results + 1] = formatContent(child) | if not visited[child.id] then | ||
results[#results + 1] = formatContent(child) | |||
else | |||
results[#results + 1] = '' .. child.id | |||
end | |||
elseif child["!type"] == "NestedSelector" then | elseif child["!type"] == "NestedSelector" then | ||
results[#results + 1] = handleNestedSelector(child, true) | results[#results + 1] = handleNestedSelector(child, true, visited) | ||
elseif child["!type"] == "GroupSelector" then | elseif child["!type"] == "GroupSelector" then | ||
results[#results + 1] = handleGroupSelector(child) | results[#results + 1] = handleGroupSelector(child, visited) | ||
end | end | ||
end | end | ||
| Строка 207: | Строка 211: | ||
-- Обработка NestedSelector | -- Обработка NestedSelector | ||
handleNestedSelector = function(nestedSelector, wrapped) | handleNestedSelector = function(nestedSelector, wrapped, visited) | ||
if not nestedSelector.tableId then return '' end | if not nestedSelector.tableId then return '' end | ||
local result = {} | local result = {} | ||
local classesRolls, classesProb | local classesRolls, classesProb | ||
if wrapped then | if wrapped then | ||
if nestedSelector.rolls and nestedSelector.rolls.range then | |||
local rollsResult = processRolls(nestedSelector.rolls) | |||
if rollsResult and #rollsResult > 0 then | |||
classesRolls = ', максимум может выпасть: ' .. rollsResult | |||
end | |||
end | |||
if nestedSelector.prob then | if nestedSelector.prob then | ||
classesProb = string.format(" <div>%s%%</div>", nestedSelector.prob * 100 >= 1 and math.floor(nestedSelector.prob * 100) or nestedSelector.prob * 100) | classesProb = string.format(" <div>%s%%</div>", nestedSelector.prob * 100 >= 1 and math.floor(nestedSelector.prob * 100) or nestedSelector.prob * 100) | ||
| Строка 226: | Строка 229: | ||
end | end | ||
if wrapped and (classesRolls or classesProb) then | |||
result[#result + 1] = string.format('{{LinkСard/Сollapsible|name=Группа предметов%s%s|content=', classesRolls or "", classesProb or "") | |||
end | |||
result[#result + 1] = getTableOutput(nestedSelector.tableId) | result[#result + 1] = getTableOutput(nestedSelector.tableId, visited) | ||
if wrapped and (classesRolls or classesProb) then | |||
result[#result + 1] = "}}" | result[#result + 1] = "}}" | ||
end | |||
return table.concat(result) | return table.concat(result) | ||