require("setup")

function love.load()

  Setup()
  
end

function love.update(dt)

  -- this part don't care about the focus

  function love.joystickadded(joystick)
    
    -- problem with multiple devices connected ?
    
    joystick.replace(joystick)
    Global.Joystick.isjoy=true
  
  end
    
  function love.joystickremoved()
    
    Global.Joystick.isjoy=false
    
  end
  
  if Gamestate.loading then
  
    -- load everything without focus
  
  end
  
  if Substate.focus then
    
    function love.keypressed(key,scancode)

      Global.Key.pressed=keyboard.convert(scancode)

    end

    function love.keyreleased(key,scancode)

      Global.Key.released=keyboard.convert(scancode)

    end
    
    if Global.Key.pressed~="" or #Global.Key.list~=0 then -- To avoid workload for analyzing keyboard
  
      Global.Key.list=keyboard.table()
      
    end
    
    if Global.Parameter.touchscreen then
    
      sensor:state()
      
      function love.touchreleased()
      
        Global.Touchscreen.pressure=0
      
      end
      
      function love.touchpressed()
      
        Global.Touchscreen.pressure=1
      
      end
    
    end
  
    love.graphics.origin()
    Flux.update(dt)
    debug:update()
    
    Global.Key.pressed,Global.Key.released="",""
  
  end
  
end

function love.draw()
  
  Push:start()
  
    debug.draw()
  
  Push:finish()
  
end

function love.lowmemory()

  collectgarbage()
  
end

function love.focus(f)

  if f then
  
    Substate.focus=true
  
  else
  
    Substate.focus=false
  
  end

end

function love.resize(w, h)

  Push.resize(w, h)
	
end

function love.quit()
    
end
