Модуль:Песочница/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
        if nestedSelector.rolls and nestedSelector.rolls.range then
    local rollsResult = processRolls(nestedSelector.rolls)
            local rollsResult = processRolls(nestedSelector.rolls)
    if rollsResult and #rollsResult > 0 then
            if rollsResult and #rollsResult > 0 then
        classesRolls = ', максимум может выпасть: ' .. rollsResult
                classesRolls = ', максимум может выпасть: ' .. rollsResult
    end
            end
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
    if wrapped and (classesRolls or classesProb) then
    if (classesRolls and #classesRolls > 0) or (classesProb and #classesProb > 0) then
        result[#result + 1] = string.format('{{LinkСard/Сollapsible|name=Группа предметов%s%s|content=', classesRolls or "", classesProb or "")
        result[#result + 1] = string.format('{{LinkСard/Сollapsible|name=Группа предметов%s%s|content=', classesRolls or "", classesProb or "")
    end
    end
end


     result[#result + 1] = getTableOutput(nestedSelector.tableId)
     result[#result + 1] = getTableOutput(nestedSelector.tableId, visited)


if wrapped and (classesRolls or classesProb) then
    if wrapped and (classesRolls or classesProb) then
    if (classesRolls and #classesRolls > 0) or (classesProb and #classesProb > 0) then
         result[#result + 1] = "}}"
         result[#result + 1] = "}}"
    end
    end
end


     return table.concat(result)
     return table.concat(result)