This commit is contained in:
Bryce
2025-08-01 08:34:51 -07:00
parent 15f11fc0f3
commit 44d3f10875
77 changed files with 605 additions and 713 deletions

63
addons/cutscene_editor/editor/CutsceneGenerator.gd Normal file → Executable file
View File

@@ -9,7 +9,7 @@ var graph_nodes: Dictionary = {} # Map of node IDs to node data
var connections: Array = [] # List of connection data
# Generate a cutscene from graph data
func generate_cutscene(cutscene_resource: CutsceneResource) -> CutsceneManager:
func generate_cutscene(scene: Node, cutscene_resource: CutsceneResource) -> CutsceneManager:
# Clear previous data
graph_nodes.clear()
connections.clear()
@@ -30,7 +30,7 @@ func generate_cutscene(cutscene_resource: CutsceneResource) -> CutsceneManager:
return cutscene_manager
# Build action sequence starting from entry node
_build_action_sequence(entry_node, cutscene_manager)
_build_action_sequence(scene, entry_node, cutscene_manager)
return cutscene_manager
@@ -43,45 +43,42 @@ func _find_entry_node() -> Dictionary:
return {}
# Build action sequence from graph data
func _build_action_sequence(start_node: Dictionary, cutscene_manager: CutsceneManager) -> void:
# Use a queue-based traversal to process nodes in order
var node_queue = []
var processed_nodes = {}
var next_connections = _get_outgoing_connections(start_node["id"])
func _build_action_sequence(scene: Node, start_node: Dictionary, cutscene_manager: CutsceneManager) -> void:
# First pass: Create all actions
var action_map = {} # Map of node IDs to action instances
# Add initial connections to queue
for conn in next_connections:
node_queue.append(conn["to_node"])
# Process nodes in order
while not node_queue.is_empty():
var current_node_id = node_queue.pop_front()
for node_id in graph_nodes:
var node_data = graph_nodes[node_id]
# Skip if already processed
if processed_nodes.has(current_node_id):
continue
# Mark as processed
processed_nodes[current_node_id] = true
# Get node data
var node_data = graph_nodes.get(current_node_id, {})
if node_data.is_empty():
# Skip entry and exit nodes as they don't create actions
if node_data["type"] == "entry" or node_data["type"] == "exit":
continue
# Create action for regular nodes
var action = _create_action_from_node(node_data)
var action = _create_action_from_node(scene, node_data)
if action:
cutscene_manager.add_action(action)
action_map[node_id] = action
# Second pass: Add actions with their dependencies
for node_id in action_map:
print("setting up", node_id)
var action = action_map[node_id]
# Add next nodes to queue
var outgoing_connections = _get_outgoing_connections(current_node_id)
for conn in outgoing_connections:
if not processed_nodes.has(conn["to_node"]):
node_queue.append(conn["to_node"])
# Get dependencies (incoming connections)
var deps = []
var incoming_connections = _get_incoming_connections(node_id)
for conn in incoming_connections:
# Only add as dependency if the source node creates an action
var from_node_data = graph_nodes.get(conn["from_node"], {})
if not from_node_data.is_empty() and from_node_data["type"] != "entry":
deps.append(conn["from_node"])
# Add action with dependencies
cutscene_manager.add_action(node_id, action, deps)
# Create an action instance from node data
func _create_action_from_node(node_data: Dictionary):
func _create_action_from_node(scene: Node, node_data: Dictionary):
var parameters = node_data["parameters"]
match node_data["type"]:
@@ -93,7 +90,7 @@ func _create_action_from_node(node_data: Dictionary):
# In a real implementation, we would resolve the character path to an actual node
# For now, we'll create a placeholder
var character_node = null # This would be resolved at runtime
var character_node = scene.find_child(character_path) # This would be resolved at runtime
var target_position = Vector2(target_x, target_y)
return MoveAction.new(character_node, target_position, speed)