local flagstatus='NONE'

function update(dt)


    if ac.getSim().raceFlagType==2 then
        flagstatus='YELLOW'
    elseif ac.getSim().raceFlagType==12 then
        flagstatus='BLUE'
    elseif ac.getSim().raceFlagType==1 and ac.getSim().timeToSessionStart>-5000 then
        flagstatus='GREEN'
    elseif ac.getSim().raceFlagType==5 then
        flagstatus='BLACK'
    elseif ac.getSim().raceFlagType==8 then
        flagstatus='PITS'
    elseif ac.getSim().raceFlagType==14 then
        flagstatus='WHITE'
    elseif ac.getSim().raceFlagType==13 then
        flagstatus='FINISH'
    elseif ac.getSim().raceFlagType==0 then
        flagstatus='NONE'
    else
        flagstatus='NONE'
    end

    
    
    ui.pushDWriteFont('Segoe UI:../fonts/impact.ttf; Weight=bold; Stretch=Expanded')
    ui.setCursor(vec2(0,0))
    ac.debug('flagstatus', ac.getSim().raceFlagType)
    ac.debug('time', ac.getSim().timeToSessionStart)

if flagstatus=='YELLOW' then
    ui.drawRectFilled(vec2(0,0), vec2(512,320), rgbm(1,1,0,1))
    ui.dwriteTextAligned(flagstatus, 120, ui.Alignment.Center, ui.Alignment.Center, vec2(0,300), false, rgbm(0,0,0,1))
elseif flagstatus=='BLUE' then
    ui.drawRectFilled(vec2(0,0), vec2(512,320), rgbm(0,0,1,1))
    ui.dwriteTextAligned(flagstatus, 120, ui.Alignment.Center, ui.Alignment.Center, vec2(0,300), false, rgbm(1,1,1,1))
elseif flagstatus=='GREEN' then
    ui.drawRectFilled(vec2(0,0), vec2(512,320), rgbm(0,1,0,1))
    ui.dwriteTextAligned(flagstatus, 120, ui.Alignment.Center, ui.Alignment.Center, vec2(0,300), false, rgbm(0,0,0,1))
elseif flagstatus=='BLACK' then
    ui.drawRectFilled(vec2(0,0), vec2(512,320), rgbm(0,0,0,1))
    ui.dwriteTextAligned(flagstatus, 120, ui.Alignment.Center, ui.Alignment.Center, vec2(0,300), false, rgbm(1,1,1,1))
elseif flagstatus=='PITS' then
    ui.drawRectFilled(vec2(0,0), vec2(512,320), rgbm(1,1,1,1))
    ui.dwriteTextAligned(flagstatus, 120, ui.Alignment.Center, ui.Alignment.Center, vec2(0,300), false, rgbm(0,0,0,1))
elseif flagstatus=='WHITE' then
    ui.drawRectFilled(vec2(0,0), vec2(512,320), rgbm(1,1,1,1))
    ui.dwriteTextAligned(flagstatus, 120, ui.Alignment.Center, ui.Alignment.Center, vec2(0,300), false, rgbm(0,0,0,1))
elseif flagstatus=='FINISH' then
    ui.drawRectFilled(vec2(0,0), vec2(64,80), rgbm(1,1,1,1))
    ui.drawRectFilled(vec2(128,0), vec2(192,80), rgbm(1,1,1,1))
    ui.drawRectFilled(vec2(256,0), vec2(320,80), rgbm(1,1,1,1))
    ui.drawRectFilled(vec2(384,0), vec2(448,80), rgbm(1,1,1,1))

    ui.drawRectFilled(vec2(64,80), vec2(128,160), rgbm(1,1,1,1))
    ui.drawRectFilled(vec2(192,80), vec2(256,160), rgbm(1,1,1,1))
    ui.drawRectFilled(vec2(320,80), vec2(384,160), rgbm(1,1,1,1))
    ui.drawRectFilled(vec2(448,80), vec2(512,160), rgbm(1,1,1,1))

    ui.drawRectFilled(vec2(0,160), vec2(64,240), rgbm(1,1,1,1))
    ui.drawRectFilled(vec2(128,160), vec2(192,240), rgbm(1,1,1,1))
    ui.drawRectFilled(vec2(256,160), vec2(320,240), rgbm(1,1,1,1))
    ui.drawRectFilled(vec2(384,160), vec2(448,240), rgbm(1,1,1,1))

    ui.drawRectFilled(vec2(64,240), vec2(128,320), rgbm(1,1,1,1))
    ui.drawRectFilled(vec2(192,240), vec2(256,320), rgbm(1,1,1,1))
    ui.drawRectFilled(vec2(320,240), vec2(384,320), rgbm(1,1,1,1))
    ui.drawRectFilled(vec2(448,240), vec2(512,320), rgbm(1,1,1,1))    
end
    


    -- display.text{ width=512, pos=vec2(0,70) , letter=vec2(50, 100), text="YELLOW", font="rss-arial", alignment=0.5, spacing = 15, color = rgbm(1, 1, 1, 1) }
end