Модуль:Prototypes/Хранилище/Предмет: различия между версиями

мНет описания правки
мНет описания правки
Строка 197: Строка 197:
     if not tableId then return result end
     if not tableId then return result end


     -- Генерация классов для div
     -- Создание строки с вероятностью
     local classes = {}
    local probString = ''
    if nestedSelector.prob then
        local percentage = nestedSelector.prob * 100
        probString = string.format('<div class="probability">Шанс выпадения: %.2f%%</div>', percentage)
    end
 
    -- Создание строки с диапазоном выпадения
     local rollsString = ''
     if nestedSelector.rolls and nestedSelector.rolls.range then
     if nestedSelector.rolls and nestedSelector.rolls.range then
         table.insert(classes, 'rolls-' .. tostring(nestedSelector.rolls.range):gsub(',', '-'))
         local min, max = nestedSelector.rolls.range:match("(%d+),%s*(%d+)")
    end
        min, max = tonumber(min), tonumber(max)
    if nestedSelector.prob then
        if min and max then
        table.insert(classes, 'prob-' .. tostring(nestedSelector.prob):gsub('%.', '_'))
            rollsString = string.format('<div class="rolls">Количество предметов: от %d до %d</div>', min, max)
        end
     end
     end


     -- Обёртка div с классами
     -- Обёртка в <div> с дополнительными данными
    local classString = table.concat(classes, ' ')
     result = result .. '<div class="nested-selector">'
     result = result .. string.format('<div class="%s">', classString)
    result = result .. probString .. rollsString
     result = result .. getTableOutput(tableId)
     result = result .. getTableOutput(tableId)
     result = result .. '</div>'
     result = result .. '</div>'