extends Node # Unit tests for CutsceneResource func _ready() -> void: test_add_node() test_remove_node() test_add_connection() test_remove_connection() test_get_node_by_id() test_get_connections_for_node() test_validate() print("All tests passed!") func test_add_node() -> void: var resource = CutsceneResource.new() var node_data = { "id": "test_node_1", "type": "move", "position": {"x": 100, "y": 150}, "parameters": { "character": "player", "target_x": 200, "target_y": 300, "speed": 100 } } resource.add_node(node_data) assert(resource.nodes.size() == 1, "Node should be added to resource") assert(resource.nodes[0]["id"] == "test_node_1", "Node ID should match") print("test_add_node passed") func test_remove_node() -> void: var resource = CutsceneResource.new() var node_data = { "id": "test_node_1", "type": "move", "position": {"x": 100, "y": 150}, "parameters": { "character": "player", "target_x": 200, "target_y": 300, "speed": 100 } } resource.add_node(node_data) assert(resource.nodes.size() == 1, "Node should be added to resource") resource.remove_node("test_node_1") assert(resource.nodes.size() == 0, "Node should be removed from resource") print("test_remove_node passed") func test_add_connection() -> void: var resource = CutsceneResource.new() var connection_data = { "id": "test_conn_1", "from_node": "node_1", "from_port": 0, "to_node": "node_2", "to_port": 0 } resource.add_connection(connection_data) assert(resource.connections.size() == 1, "Connection should be added to resource") assert(resource.connections[0]["id"] == "test_conn_1", "Connection ID should match") print("test_add_connection passed") func test_remove_connection() -> void: var resource = CutsceneResource.new() var connection_data = { "id": "test_conn_1", "from_node": "node_1", "from_port": 0, "to_node": "node_2", "to_port": 0 } resource.add_connection(connection_data) assert(resource.connections.size() == 1, "Connection should be added to resource") resource.remove_connection("test_conn_1") assert(resource.connections.size() == 0, "Connection should be removed from resource") print("test_remove_connection passed") func test_get_node_by_id() -> void: var resource = CutsceneResource.new() var node_data = { "id": "test_node_1", "type": "move", "position": {"x": 100, "y": 150}, "parameters": { "character": "player", "target_x": 200, "target_y": 300, "speed": 100 } } resource.add_node(node_data) var retrieved_node = resource.get_node_by_id("test_node_1") assert(not retrieved_node.is_empty(), "Node should be found by ID") assert(retrieved_node["id"] == "test_node_1", "Retrieved node ID should match") print("test_get_node_by_id passed") func test_get_connections_for_node() -> void: var resource = CutsceneResource.new() var node1_data = { "id": "node_1", "type": "entry", "position": {"x": 100, "y": 100}, "parameters": {} } var node2_data = { "id": "node_2", "type": "move", "position": {"x": 200, "y": 100}, "parameters": { "character": "player", "target_x": 300, "target_y": 200, "speed": 100 } } var connection_data = { "id": "conn_1", "from_node": "node_1", "from_port": 0, "to_node": "node_2", "to_port": 0 } resource.add_node(node1_data) resource.add_node(node2_data) resource.add_connection(connection_data) var connections = resource.get_connections_for_node("node_1") assert(connections.size() == 1, "Should find one connection for node_1") assert(connections[0]["from_node"] == "node_1", "Connection should be from node_1") connections = resource.get_connections_for_node("node_2") assert(connections.size() == 1, "Should find one connection for node_2") assert(connections[0]["to_node"] == "node_2", "Connection should be to node_2") print("test_get_connections_for_node passed") func test_validate() -> void: var resource = CutsceneResource.new() var node1_data = { "id": "node_1", "type": "entry", "position": {"x": 100, "y": 100}, "parameters": {} } var node2_data = { "id": "node_2", "type": "move", "position": {"x": 200, "y": 100}, "parameters": { "character": "player", "target_x": 300, "target_y": 200, "speed": 100 } } var valid_connection = { "id": "conn_1", "from_node": "node_1", "from_port": 0, "to_node": "node_2", "to_port": 0 } var invalid_connection = { "id": "conn_2", "from_node": "node_1", "from_port": 0, "to_node": "nonexistent_node", "to_port": 0 } # Test with valid connections resource.add_node(node1_data) resource.add_node(node2_data) resource.add_connection(valid_connection) assert(resource.validate(), "Resource with valid connections should validate") # Test with invalid connections resource.add_connection(invalid_connection) assert(not resource.validate(), "Resource with invalid connections should not validate") print("test_validate passed")