122 lines
3.8 KiB
GDScript
122 lines
3.8 KiB
GDScript
@tool
|
|
class_name CutsceneResource
|
|
extends Resource
|
|
|
|
# Resource for storing cutscene data
|
|
|
|
# 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",
|
|
"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:
|
|
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:
|
|
# Remove the node
|
|
for i in range(nodes.size()):
|
|
if nodes[i].has("name") and nodes[i]["name"] == node_name:
|
|
nodes.remove_at(i)
|
|
break
|
|
|
|
# Remove any connections to/from this node
|
|
var i = 0
|
|
while i < connections.size():
|
|
var conn = connections[i]
|
|
if conn["from_node"] == node_name or conn["to_node"] == node_name:
|
|
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:
|
|
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:
|
|
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):
|
|
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:
|
|
for node in nodes:
|
|
if node.has("name") and node["name"] == node_name:
|
|
return node
|
|
return {}
|
|
|
|
# Get all connections for a node
|
|
func get_connections_for_node(node_name: String) -> Array:
|
|
var node_connections = []
|
|
for conn in connections:
|
|
if conn["from_node"] == node_name or conn["to_node"] == node_name:
|
|
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
|
|
|
|
# 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()
|