help me show screenshots for every game in this file launcher, the screenshot should be inside the game's folder with the name screenshot.webp and should be loaded with loadAsset(path the file) and then drawn if focused local lfs = require("lfs")  -- LuaFileSystem for directory operations
WebP = require("love-webp")			-- webp library for love
require ("loadAssets")
require "gradient"

	Mono64_0xA000_256 = love.graphics.newFont("fonts/0xa000/0xA000-Mono.ttf", 256)
	Mono32_0xA000 = love.graphics.newFont("fonts/0xa000/0xA000-Mono.ttf", 32)
	Mono24_0xA000 = love.graphics.newFont("fonts/0xa000/0xA000-Mono.ttf", 24)
	Regular12_0xA000 = love.graphics.newFont("fonts/0xa000/0xA000-Regular.ttf", 12)
	love.graphics.setFont(Mono24_0xA000)
	
local games = {}
local music
local musicPlaying = false
local selectedIndex = nil

-- Constants
local MAX_SCREENSHOT_SIZE = {640, 480}
local MAX_DESCRIPTION_WIDTH = 300

-- Load the game launcher
function love.load()
	screenshotFile = loadAsset("screenshot1.webp")
	
    -- Load background music
    music = love.audio.newSource("music.ogg", "stream")
    music:setLooping(true)
    music:play()
    musicPlaying = true

    -- Find games
    local directory = love.filesystem.getWorkingDirectory()
    games = findGames(directory)
end

	local x, y = 40, 60
	local width, height = 300, 150
	-- Rectangle with square gradient
	local color1 = {1, 0, 0, 1} -- Red
	local color2 = {0, 1, 0, 1} -- Green
	
	local color3 = {1, 0, 0, 1} -- Red
	local color3 = {0.7,0.28,0.7} -- Orange
	local color4 = {0.2,0.19,0.23, 1} -- dark grey
	
	local color5 = {0, 0 , 0, 1} -- black
	local color6 = {0.38,0.38,0.38,0.38, 1} -- grey
	
	local color7 = {0.3,0.23,0.63, 1} -- purple
	
	

-- Draw the GUI
function love.draw()
	

	love.graphics.setColor(0.5,0.5,0.5,1)
    love.graphics.rectangle("fill", 0,0,410,1080)
    

    --love.graphics.setColor(0.2,0.19,0.23,1)
    --love.graphics.rectangle("fill", 410,0,1600,100)
    -- love.graphics.setColor(0.5,0.39,0.93)  
    --love.graphics.rectangle("fill", 410,100,1600,1080)
    
    
 
    love.gradient.draw(
		function()
			love.graphics.rectangle("fill", 410,1010,1600,1080)
		end,
		"linear", --gradientType, 
		1010, --centerX,
		200, -- centerY,
		-width*2, -- radialWidth,
		1080, -- radialHeight,
		color5, -- color1,
		color4) -- color2[, angle, scaleX, scaleY])
   

		love.gradient.draw(
		function()
			love.graphics.rectangle("fill", 410,80,1600,10)
		end,
		"linear", --gradientType, 
		1010, --centerX,
		0, -- centerY,
		-width*2, -- radialWidth,
		100, -- radialHeight,
		color4, -- color1,
		color5) -- color2[, angle, scaleX, scaleY])
    

    love.gradient.draw(
		function()
			love.graphics.rectangle("fill", 410,80,1600,10)
		end,
		"linear", --gradientType, 
		1010, --centerX,
		80, -- centerY,
		-width*2, -- radialWidth,
		8, -- radialHeight,
		color4, -- color1,
		color3) -- color2[, angle, scaleX, scaleY])
    

	
    love.gradient.draw(
		function()
		--	love.graphics.rectangle("fill", 410,80,300,10)
		end,
		"square", --gradientType, 
		200, --centerX,
		80, -- centerY,
		width/2, -- radialWidth,
		height/2, -- radialHeight,
		color1, -- color1,
		color2) -- color2[, angle, scaleX, scaleY])

    love.graphics.setColor(1,1,1,1)
    
    -- Draw game list
    local y = 100
    for i, game in ipairs(games) do
    local isSelected = i == selectedIndex
    love.graphics.setColor(isSelected and {0, 1, 0} or {1, 1, 1})
    
    -- Extract the filename from the path
    local filename = game.path:match("[^/]+$")
   
  -- Print only the filename
				if i % 2 == 0 then
					love.graphics.setColor(0.18,0.18,0.23)                
				else
					love.graphics.setColor(0.38,0.38,0.43)
                end
    
    love.graphics.rectangle("fill",10,y,400,100)
    love.graphics.setColor(1,1,1)
    --if i<5 then
		love.graphics.print(filename, 10, y)
    --end
    y = y + 40
	end

    -- Draw game information
    if selectedIndex then
        local game = games[selectedIndex]
        love.graphics.setFont(Mono24_0xA000)
        love.graphics.setColor(1, 1, 1)
        --print("Description:", game.description)
        love.graphics.print(game.description, 420, 120)
        
        if game.screenshot then
            local screenshot = game.screenshot
            love.graphics.draw(screenshot.image, 220, 260, 0, screenshot.scale, screenshot.scale)
        end
    else
    
    love.graphics.print("Navigate the menu with the arrows or thumbstick", 600, 100)    
    end
    
    love.graphics.print("Löve launcher", 1000, 40)    
    
    love.graphics.print("Games", 10, 40)
	

    -- Draw buttons
    --if x >= 620 and x <= 770 and y >= 920 and y <= 950 then
    love.graphics.setColor(0.5,0.5,0.5,1)
    love.graphics.rectangle("fill", 620, 920,300,30)
    love.graphics.rectangle("fill", 950, 920, 300,30)
    
    
    love.graphics.setColor(1, 1, 1)
    love.graphics.rectangle("line", 620, 920, 300,30)
    love.graphics.print("Launch Game", 620, 920)

    love.graphics.rectangle("line", 950, 920, 300,30)
    love.graphics.print("Toggle Music", 950, 920)
end


-- Handle keypressed events
function love.keypressed(key, scancode, isrepeat)
    -- Initialize selectedIndex if nil
    selectedIndex = selectedIndex or 1
    
    -- Handle keypresses for selecting games
    if key == "up" then
        selectedIndex = math.max(selectedIndex - 1, 1)
    elseif key == "down" then
        selectedIndex = math.min(selectedIndex + 1, #games)
    elseif key == "return" then
        if selectedIndex then
			 music:pause()
			musicPlaying = false
            launchGame(games[selectedIndex].path)
        end
    end
end

-- Handle mousepressed events
function love.mousepressed(x, y, button, istouch, presses)
    -- Check if the mouse click is within the bounds of the launch game button
    if button == 1 then
        if x >= 620 and x <= 770 and y >= 920 and y <= 950 then
            if selectedIndex then
				music:pause()
				musicPlaying = false
                launchGame(games[selectedIndex].path)
            end
        end
    end
end

-- Counter to control gamepad axis navigation speed
local axisCounter = 0
local axisSpeed = 10  -- Adjust this value to control the navigation speed

-- Handle gamepad axis events
function love.gamepadaxis(joystick, axis, value)
   -- Initialize selectedIndex if nil
    selectedIndex = selectedIndex or 1
    -- Threshold for thumbstick sensitivity
    local threshold = 0.2

    -- Increment the axis counter
    axisCounter = axisCounter + 1

    -- Navigate up and down the game list with the thumbstick, based on the counter
    if axisCounter >= axisSpeed then
        if axis == "lefty" then
            -- Move up
            if value < -threshold then
                selectedIndex = math.max(selectedIndex - 1, 1)
            -- Move down
            elseif value > threshold then
                selectedIndex = math.min(selectedIndex + 1, #games)
            end
        end
        -- Reset the counter
        axisCounter = 0
    end
end




-- Find games by searching for main.lua, screenshot.webp, and README.md files
function findGames(directory)
    local games = {}
    for file in lfs.dir(directory) do
		
        local path = directory .. '/' .. file
        if lfs.attributes(path, "mode") == "directory" and file ~= "." and file ~= ".." then
            local mainLuaPath = path .. '/main.lua'
            local screenshotPath = path .. '/screenshot.webp'
            local readmePath = path .. '/README.md'
            local mainLuaFile = io.open(mainLuaPath, "r")
            local screenshotFile = io.open(screenshotPath, "r")
            local readmeFile = io.open(readmePath, "r")
            if mainLuaFile and screenshotFile and readmeFile then
                local description, screenshot = getGameInfo(path)
                table.insert(games, {path = path, description = description, screenshot = screenshot})
            end
            if mainLuaFile then mainLuaFile:close() end
            if screenshotFile then screenshotFile:close() end
            if readmeFile then readmeFile:close() end
        end
    end
    return games
end

function getGameInfo(gamePath)
    local description = "Description not available."
    local screenshot = nil
    local video = nil

    -- Read description from README.md
    local readmePath = gamePath .. '/README.md'
    print("README Path:", readmePath)
    local readmeFile = io.open(readmePath, "r")
    if readmeFile then
        local content = readmeFile:read("*all")
        if content then
            description = content
        end
        readmeFile:close()
    else
        print("README.md not found for game:", gamePath)
    end

    -- Load screenshot if exists
    local screenshotPath = gamePath .. '/screenshot.webp'
    print("Screenshot Path:", screenshotPath)
    local screenshotFile = io.open(screenshotPath, "rb")  -- Open in binary mode
    --print(screenshotPath)
    --local screenshotFile = loadAsset(screenshotPath, "Image")
    --local screenshotFile = love.graphics.newImage(WebP.loadImage(screenshotPath))
    if screenshotFile then
        local content = screenshotFile:read("*all")
        if content then
            -- screenshot = love.graphics.newImage(love.filesystem.newFileData(content))
        end
        screenshotFile:close()
    else
        print("screenshot.webp not found for game:", gamePath)
    end

    -- Load video if exists
    local videoPath = gamePath .. '/video.ogg'
    print("Video Path:", videoPath)
    if love.filesystem.getInfo(videoPath) then
        video = love.graphics.newVideo(videoPath)
        if video then
            video:setLooping(true)
            video:play()
        else
            print("Failed to create video object for game:", gamePath)
        end
    else
        print("video.ogg not found or failed to load for game:", gamePath)
    end

    return description, screenshot, video
end











-- Launch the selected game
function launchGame(gamePath)
    -- Run Love2D from the command line with the game path as an argument
    local command = "love " .. gamePath
    local success, exitstatus, exitreason = os.execute(command)

    if not success then
        print("Failed to launch Love2D:", exitreason)
    end
end





-- Toggle background music
function toggleMusic()
    if musicPlaying then
        music:pause()
        musicPlaying = false
    else
        music:play()
        musicPlaying = true
    end
end