105 lines
2.9 KiB
GDScript
105 lines
2.9 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 metadata: Dictionary = {} # Additional metadata
|
|
|
|
# Initialize the resource
|
|
func _init() -> void:
|
|
nodes = []
|
|
connections = []
|
|
metadata = {
|
|
"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_id: String) -> void:
|
|
# Remove the node
|
|
for i in range(nodes.size()):
|
|
if nodes[i].has("id") and nodes[i]["id"] == node_id:
|
|
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_id or conn["to_node"] == node_id:
|
|
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(connection_id: String) -> void:
|
|
for i in range(connections.size()):
|
|
var conn = connections[i]
|
|
if conn["id"] == connection_id:
|
|
connections.remove_at(i)
|
|
break
|
|
|
|
metadata["modified"] = Time.get_unix_time_from_system()
|
|
|
|
|
|
# Get node by id
|
|
func get_node_by_id(node_id: String) -> Dictionary:
|
|
for node in nodes:
|
|
if node.has("id") and node["id"] == node_id:
|
|
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
|
|
|
|
|
|
# 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()
|
|
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())
|