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

мНет описания правки
мНет описания правки
Строка 113: Строка 113:
     end
     end
     result = result .. '</ul>'
     result = result .. '</ul>'
    return result
end
-- Обработка rolls
processRolls = function(rolls)
    local result = ''
    if rolls.range then
        -- Если указан range
        local min, max = rolls.range:match("(%d+),%s*(%d+)")
        min, max = tonumber(min), tonumber(max)
        if min and max then
            result = string.format('Максимальное количество предметов: от %d до %d.', min, max)
        else
            result = 'Некорректный формат для range.'
        end
    elseif rolls.value then
        -- Если указано value
        result = string.format('Будет сгенерировано %d предметов.', rolls.value)
    else
        result = 'Не указан параметр rolls.'
    end
     return result
     return result
end
end
Строка 149: Строка 170:
     elseif mode == 'contained' then
     elseif mode == 'contained' then
         return frame:preprocess(getContainedOutput(data, id, false))
         return frame:preprocess(getContainedOutput(data, id, false))
    elseif mode == 'rolls' then
        local entity = findDataById(data, id)
        if not entity then return 'ID не найден в данных.' end
        if entity.EntityTableContainerFill then
            local containers = entity.EntityTableContainerFill.containers
            if containers.entity_storage and containers.entity_storage.rolls then
                return processRolls(containers.entity_storage.rolls)
            end
        end
        return 'Режим rolls не найден для этого ID.'
     else
     else
         return 'Неизвестный режим: ' .. mode
         return 'Неизвестный режим: ' .. mode