import bge
import colors

def main():
    import bge
    #import GameLogic
    cont = bge.logic.getCurrentController()
    own = cont.owner
    dict = bge.logic.globalDict
    #print("nnnnnnpause level", dict['level'])
    own['last_stBut'] = False
    level = dict['level']
    scene = bge.logic.getCurrentScene()
    cam = scene.objects['Camera.003']
    curscene = bge.logic.getCurrentScene()
    
#    scenes = bge.logic.getSceneList()
#    for scene in scenes :
#        if scene.name == 'main':
#            player = scene.objects['player']    
#    main = bge.logic.getSceneList["main"]

    dict['overlay_fadeout'] = 1
    scenes = bge.logic.getSceneList()
    own['pre_pause_linvel'] = 0.0

    objList = scene.objects

    # get object named MainCharacter
    parent = objList["control_cube.002"]

    # combine child's shape with parent's
    compound = True
    obj = scene.objects['Char4']
    # child is solid
    ghost = False
    # set parent
    obj.setParent( parent, compound, ghost) 
    parent.worldPosition.z += .5 
  
    scene.gravity = [0,0,dict['gravity']]    
    for i in scenes:
        if i.name == "main":
            main = i
    
    for i in scenes:
        if i.name == "fade_out":
            print('ending fade_out', scenes)
            scene2 = i
            scene2.end()  
               
    
    if level == 'newday':
        brightness = 2.6
        cam['BC_BRIGHTNESS'] = 1.3
        cam['BC_CONTRAST'] = 1.5
#    elif level == 'lot':
#        brightness = 2.6
#        cam['BC_BRIGHTNESS'] = 1
#        cam['BC_CONTRAST'] = 1   
#        #main.world.zenithColor = [1.0, .9, .975, 0]
#        #main.world.horizonColor = [.42, .555, .823, 0] 
#        curscene.world.zenithColor = [1.0, .9, .975, 0]
#        curscene.world.horizonColor = [.42, .555, .823, 0]                 
        #print("sadfasdfsdfasdfasdfasdfasdfasdf")
    elif level == 'spine':
        brightness = 2.6
        cam['BC_BRIGHTNESS'] = .85
        cam['BC_CONTRAST'] = 1.1  
        
    elif level == 'sc':
        print('setting color of', curscene)
        curscene.world.zenithColor = [.23, .23, .25, 1] #[0.1,.2,.4,.5]#[.58, .86, 1.0, 0] #[.3, 0.3, 0.3, 0]
        curscene.world.horizonColor = [.1, .15, .3, 1] #[0.1,0,0,1] #[.58, .86, 1.0, 1]         
        
    elif level == 'garage18':
        print('setting color of', curscene)
        curscene.world.zenithColor = [0, 0.0, 0.0, 0]
        curscene.world.horizonColor = [0, 0, 0.0, 0]   

    elif level == 'pats':
        print('setting color of', curscene)
     
    if dict['bc'] == 1:
        cont.activate(cam.actuators["bc"])

    else:
        cont.activate(cam.actuators["bc_off"])  
    if dict['hdr'] == 1:
        cont.activate(cam.actuators["hdr"])

    else:
        cont.activate(cam.actuators["hdr_off"])
                            
    if dict['ao'] == 1:
        cont.activate(cam.actuators["ao"])

    else:
        cont.activate(cam.actuators["ao_off"])                    

    if dict['dof_on'] == 1:
        cont.activate(cam.actuators["DOF"])

    else:
        cont.activate(cam.actuators["DOF_off"])
        
    if dict['bloom_on'] == 1:
        cont.activate(cam.actuators["Bloom"])

    else:
        cont.activate(cam.actuators["bloom_off"])
        
#    print(dict['shadow_on'], 'shadow_on')    
#    if dict['shadow_on'] == 1:
#        bge.render.setGLSLMaterialSetting("shadows", 1) 
#    else:
#        bge.render.setGLSLMaterialSetting("shadows", 0)  

    if dict['music_player'] == 1:
        dict['music_start'] =  True   
        print('starting music') 
    else:
        print('not starting music', dict['music_player'])        
        
    scene.world.envLightEnergy = dict['ambient_strength']   
    
    cam['BC_BRIGHTNESS'] = dict['BC_BRIGHTNESS'] 
    cam['BC_CONTRAST'] = dict['BC_CONTRAST']
    cam['bc'] = dict['bc']  
    cam['hdr'] = dict['hdr']
    cam['avgL'] = dict['avgL']
    cam['HDRamount'] = dict['HDRamount']
    cam['ao'] = dict['ao']  
    cam['onlyAO'] = dict['onlyAO']
    cam['aowidth'] = dict['aowidth']
    cam['aoradius'] = dict['aoradius']  
    cam['ambient_strength'] = dict['ambient_strength']
    cam['sun_strength'] = dict['sun_strength']
    cam['sun_pos_x'] = dict['sun_rot_x']
    cam['sun_pos_y'] = dict['sun_rot_y']
    #cam['shadow_on'] = dict['shadow_on']
    cam['dof_on'] = dict['dof_on']
    cam['bloom_on'] = dict['bloom_on'] 
    cam['fxaa'] = dict['fxaa']
    cam['FXAA_SPAN_MAX'] = dict['FXAA_SPAN_MAX']     
    own['grindnew_timer'] = 0   
    own['last_ramp'] = 0
    own['requestAction'] = ''
    own['l_actionState'] = ''
    own['actionState'] = ''
    own['transition_timer'] = 0
    own['transitioning'] = 0
    own['driving'] = False
    dict['last_driving'] = False
    own['last_roty'] = 0.0
    
    own['walk_targ_speed'] = 2
    own['walk_fast_targ_speed'] = 5
    own['walk_speed'] = 0
    own['walk_inc'] = .05
    own['walk_jump_timer'] = 0
    own['no_grind_timer'] = 0
    own['last_jump_frame'] = 0
    
    colors.update_shirt_tex() 
    colors.update_truck_tex()
    
    print('scene init ran')
      
main()
