require "debugger"
local simple_tree = require("examples.simple")
local advanced_tree = require("examples.advanced")
local tree_render = require("LOVElyTree.tree_render")
require "tests.tests"

local camera = require "examples.camera"

local tree
local tree_layour_data

function love.load()
    math.randomseed(os.time())

    tree = simple_tree()
    tree_layour_data = tree_render.layout_tree(tree.root, 10, 10)
    love.graphics.setFont(love.graphics.newFont(12))
end

function love.update(dt)
    tree:update(dt)
    camera.update(dt)
end

function love.draw()
    camera.push()
    tree_render.render_tree(tree_layour_data)
    camera.pop()

    love.graphics.setColor(0.5, 0.5, 0.5)
    love.graphics.print("1: Simple Behavior Tree | 2: Complex Behavior tree", 10, 20)
    love.graphics.print("Controls: AWSD or mouse drag to pan. QE or mouse wheel to zoom", 10,
        love.graphics.getHeight() - 20)

    local stats = love.graphics.getStats()
    local fps = love.timer.getFPS()
    love.graphics.print(string.format("FPS: %d\nDraw Calls: %d", fps, stats.drawcalls), 10,
        love.graphics.getHeight() - 50)
end

function love.keypressed(key)
    if key == "1" then
        tree = simple_tree()
        tree_layour_data = tree_render.layout_tree(tree.root, 10, 10)
        camera.reset()
    elseif key == "2" then
        tree = advanced_tree()
        tree_layour_data = tree_render.layout_tree(tree.root, 10, 10)
        camera.reset()
    end
end

function love.mousepressed(x, y, button)
    camera.mousepressed(x, y, button)
end

function love.mousereleased(x, y, button)
    camera.mousereleased(x, y, button)
end

function love.mousemoved(x, y, dx, dy)
    camera.mousemoved(x, y, dx, dy)
end

function love.wheelmoved(x, y)
    camera.wheel_moved(x, y)
end
