progress
This commit is contained in:
@@ -7,30 +7,31 @@ extends Resource
|
||||
# Properties
|
||||
@export var nodes: Array = [] # List of node data
|
||||
@export var connections: Array = [] # List of connection data
|
||||
@export var parallel_connections: Array = [] # Logical connections for parallel groups
|
||||
@export var metadata: Dictionary = {} # Additional metadata
|
||||
|
||||
# Initialize the resource
|
||||
func _init() -> void:
|
||||
nodes = []
|
||||
connections = []
|
||||
parallel_connections = []
|
||||
metadata = {
|
||||
"version": "1.0",
|
||||
"version": "2.0",
|
||||
"created": Time.get_unix_time_from_system(),
|
||||
"modified": Time.get_unix_time_from_system()
|
||||
}
|
||||
|
||||
# Add a node to the cutscene
|
||||
func add_node(node_data: Dictionary) -> void:
|
||||
# Generate unique ID if not provided
|
||||
if not node_data.has("id") or node_data["id"] == "":
|
||||
node_data["id"] = _generate_unique_id()
|
||||
nodes.append(node_data)
|
||||
metadata["modified"] = Time.get_unix_time_from_system()
|
||||
|
||||
# Remove a node from the cutscene
|
||||
func remove_node(node_name: String) -> void:
|
||||
func remove_node(node_id: String) -> void:
|
||||
# Remove the node
|
||||
for i in range(nodes.size()):
|
||||
if nodes[i].has("name") and nodes[i]["name"] == node_name:
|
||||
if nodes[i].has("id") and nodes[i]["id"] == node_id:
|
||||
nodes.remove_at(i)
|
||||
break
|
||||
|
||||
@@ -38,58 +39,36 @@ func remove_node(node_name: String) -> void:
|
||||
var i = 0
|
||||
while i < connections.size():
|
||||
var conn = connections[i]
|
||||
if conn["from_node"] == node_name or conn["to_node"] == node_name:
|
||||
if conn["from_node"] == node_id or conn["to_node"] == node_id:
|
||||
connections.remove_at(i)
|
||||
else:
|
||||
i += 1
|
||||
|
||||
# Remove any parallel connections to/from this node
|
||||
i = 0
|
||||
while i < parallel_connections.size():
|
||||
var conn = parallel_connections[i]
|
||||
if conn["from_node"] == node_name or conn["to_node"] == node_name:
|
||||
parallel_connections.remove_at(i)
|
||||
else:
|
||||
i += 1
|
||||
|
||||
metadata["modified"] = Time.get_unix_time_from_system()
|
||||
|
||||
# Add a connection to the cutscene
|
||||
func add_connection(connection_data: Dictionary) -> void:
|
||||
# Generate unique ID if not provided
|
||||
if not connection_data.has("id") or connection_data["id"] == "":
|
||||
connection_data["id"] = _generate_unique_id()
|
||||
connections.append(connection_data)
|
||||
metadata["modified"] = Time.get_unix_time_from_system()
|
||||
|
||||
# Remove a connection from the cutscene
|
||||
func remove_connection(from_node: String, from_port: int, to_node: String, to_port: int) -> void:
|
||||
func remove_connection(connection_id: String) -> void:
|
||||
for i in range(connections.size()):
|
||||
var conn = connections[i]
|
||||
if (conn["from_node"] == from_node and conn["from_port"] == from_port and
|
||||
conn["to_node"] == to_node and conn["to_port"] == to_port):
|
||||
if conn["id"] == connection_id:
|
||||
connections.remove_at(i)
|
||||
break
|
||||
|
||||
metadata["modified"] = Time.get_unix_time_from_system()
|
||||
|
||||
# Add a parallel connection to the cutscene
|
||||
func add_parallel_connection(connection_data: Dictionary) -> void:
|
||||
parallel_connections.append(connection_data)
|
||||
metadata["modified"] = Time.get_unix_time_from_system()
|
||||
|
||||
# Remove a parallel connection from the cutscene
|
||||
func remove_parallel_connection(from_node: String, from_port: int, to_node: String, to_port: int) -> void:
|
||||
for i in range(parallel_connections.size()):
|
||||
var conn = parallel_connections[i]
|
||||
if (conn["from_node"] == from_node and conn["from_port"] == from_port and
|
||||
conn["to_node"] == to_node and conn["to_port"] == to_port):
|
||||
parallel_connections.remove_at(i)
|
||||
break
|
||||
|
||||
metadata["modified"] = Time.get_unix_time_from_system()
|
||||
|
||||
# Get node by name
|
||||
func get_node_by_name(node_name: String) -> Dictionary:
|
||||
# Get node by id
|
||||
func get_node_by_id(node_id: String) -> Dictionary:
|
||||
for node in nodes:
|
||||
if node.has("name") and node["name"] == node_name:
|
||||
if node.has("id") and node["id"] == node_id:
|
||||
return node
|
||||
return {}
|
||||
|
||||
@@ -101,21 +80,25 @@ func get_connections_for_node(node_name: String) -> Array:
|
||||
node_connections.append(conn)
|
||||
return node_connections
|
||||
|
||||
# Get all parallel connections for a node
|
||||
func get_parallel_connections_for_node(node_name: String) -> Array:
|
||||
var node_connections = []
|
||||
for conn in parallel_connections:
|
||||
if conn["from_node"] == node_name or conn["to_node"] == node_name:
|
||||
node_connections.append(conn)
|
||||
return node_connections
|
||||
|
||||
# Validate that all referenced nodes exist in the resource
|
||||
func validate() -> bool:
|
||||
# Check if all nodes referenced in connections exist
|
||||
for conn in connections:
|
||||
if not get_node_by_id(conn["from_node"]) or not get_node_by_id(conn["to_node"]):
|
||||
return false
|
||||
return true
|
||||
|
||||
# Clear all data
|
||||
func clear() -> void:
|
||||
nodes.clear()
|
||||
connections.clear()
|
||||
parallel_connections.clear()
|
||||
metadata["modified"] = Time.get_unix_time_from_system()
|
||||
|
||||
# Update metadata
|
||||
func update_metadata() -> void:
|
||||
metadata["modified"] = Time.get_unix_time_from_system()
|
||||
|
||||
# Generate a unique ID for nodes and connections
|
||||
func _generate_unique_id() -> String:
|
||||
return "id_" + str(Time.get_ticks_msec())
|
||||
|
||||
Reference in New Issue
Block a user