extends Node

## Test script for StudioBridge
## This demonstrates how to use the bridge from GDScript

func _ready():
	print("=== StudioBridge Test ===")
	
	# Get the singleton
	var bridge = StudioBridge
	
	# Start the server
	var err = bridge.start_server(6007)
	if err == OK:
		print("✓ Bridge server started on port 6007")
		print("  Connect Studio to: http://localhost:6007")
	else:
		print("✗ Failed to start bridge:", err)
		return
	
	# Create a test scene
	setup_test_scene()
	
	print("\n=== Test Complete ===")
	print("Server is running. Test it with:")
	print('  curl -X POST http://localhost:6007/rpc -d \'{"method":"getSceneTree","params":{}}\'')

func _process(_delta):
	# Process incoming HTTP requests
	StudioBridge.process()

func setup_test_scene():
	# Create a simple test scene
	var sprite = Sprite2D.new()
	sprite.name = "TestSprite"
	add_child(sprite)
	
	var camera = Camera2D.new()
	camera.name = "MainCamera"
	add_child(camera)
	
	# Set the scene root in the bridge
	StudioBridge.set_edited_scene_root(get_tree().root)
	
	print("✓ Test scene created:")
	print("  - TestSprite (Sprite2D)")
	print("  - MainCamera (Camera2D)")

func _exit_tree():
	# Clean shutdown
	StudioBridge.stop_server()
	print("✓ Bridge server stopped")
