extends Node
class_name IsometricCameraController

var camera : Camera2D
var initial_position : Vector2
var initial_zoom : Vector2

var drag_start = Vector2()
var drag_active = false
var zoom_min = 0.1
var zoom_max = 4.0
var zoom_speed = 0.1

func _init(camera_node):
    camera = camera_node
    initial_position = camera.position
    initial_zoom = camera.zoom

func handle_input(event):
    # Camera drag (pan) control
    if event is InputEventMouseButton:
        if event.button_index == MOUSE_BUTTON_RIGHT:
            if event.pressed:
                drag_start = event.position
                drag_active = true
            else:
                drag_active = false
        
        # Zoom control with mouse wheel
        if event.button_index == MOUSE_BUTTON_WHEEL_DOWN:
            zoom_camera(-zoom_speed)
        elif event.button_index == MOUSE_BUTTON_WHEEL_UP:
            zoom_camera(zoom_speed)
    
    # Handle camera movement while dragging
    if event is InputEventMouseMotion and drag_active:
        camera.position -= event.relative / camera.zoom

func zoom_camera(zoom_amount):
    var new_zoom = camera.zoom.x + zoom_amount
    new_zoom = clamp(new_zoom, zoom_min, zoom_max)
    camera.zoom = Vector2(new_zoom, new_zoom)

func reset_camera():
    camera.position = initial_position
    camera.zoom = initial_zoom
