local celeste = require("#celeste")

function getCounter(key)
    return engine.Scene.Session:GetCounter(key)
end

function getSlider(key)
    return engine.Scene.Session:GetSlider(key)
end

function setCounter(key, value)
    return engine.Scene.Session:SetCounter(key, value)
end

function setSlider(key, value)
    return engine.Scene.Session:SetSlider(key, value)
end


function  makeBaseText(tab)
    local nums = {0, 5, 50, 100, 500, 1000, 5000, 10000, 50000, 100000, 500000, 1000000, 5000000, 10000000, 50000000, 100000000, 500000000, 1000000000, 5000000000, 10000000000, 50000000000, 100000000000, 500000000000, 1000000000000, 5000000000000, 10000000000000, 100000000000000}

    for i, value in ipairs(nums) do
        if (value == nums[27]) or (getSlider("berriesThisAscension") >= value and getSlider("berriesThisAscension") < nums[i + 1]) then
            table.insert(tab, "CommunityVoice_strawsim_news_count_"..value)
            break
        end
    end
end



function onBegin()
    makeUnskippable()

    local dialogs = {}

    local level = getRoom()
        
    makeBaseText(dialogs)

    for _, value in ipairs(dialogs) do
        setFlag(value, false)
    end

    local template = getEntity("CinematicText", "Celeste.Mod.FemtoHelper.Entities.")

    while true do

        local dialogs = {}
        
        makeBaseText(dialogs)
        
        local pick = math.random(#dialogs)

        log(dialogs[pick], "Strawberry Simulator News Ticker")

        template.Str = "test"

        level:Remove(template)
        level:Add(template)
        
        wait(5)

    end
end


function onEnd ()

end