3.1 KiB
3.1 KiB
CutsceneResource Implementation Plan
Overview
This document describes the changes needed to implement the new CutsceneResource data structure that will properly store nodes and connections for use by both the editor and runtime systems.
Current Issues
The current CutsceneResource.gd has several issues:
- Uses "name" instead of "id" for node identification
- Has separate parallel_connections array which complicates the data structure
- Doesn't follow a consistent data structure for nodes and connections
- Lacks proper unique ID generation for connections
Proposed Implementation
New Data Structure
The resource will store:
nodes: Array of node objects with consistent structureconnections: Array of connection objects with consistent structuremetadata: Version and timestamp information
Node Structure
Each node will have:
{
"id": "unique_string_identifier",
"type": "node_type",
"position": {
"x": 100,
"y": 150
},
"parameters": {
// Type-specific parameters
}
}
Connection Structure
Each connection will have:
{
"id": "unique_string_identifier",
"from_node": "source_node_id",
"from_port": 0,
"to_node": "target_node_id",
"to_port": 0
}
Required Changes to CutsceneResource.gd
1. Update Properties
Replace the current properties with:
@export var nodes: Array = []
@export var connections: Array = []
@export var metadata: Dictionary = {}
2. Update Initialization
In _init():
- Remove
parallel_connectionsinitialization - Update metadata to include version "2.0" to indicate the new structure
3. Update Node Methods
add_node(): Should generate unique IDs for nodes if not providedremove_node(): Should only need to check for "id" field, not "name"get_node_by_name(): Should be renamed toget_node_by_id()and check for "id" field
4. Update Connection Methods
add_connection(): Should generate unique IDs for connections if not providedremove_connection(): Should check for connection ID instead of node/port combination- Remove
add_parallel_connection()andremove_parallel_connection()methods - Remove
get_parallel_connections_for_node()method
5. Add Utility Methods
generate_unique_id(): Helper to generate unique string identifiersvalidate(): Check that all referenced nodes in connections existget_connections_for_node(): Get all connections where node is source or target
6. Update Load/Save Methods
- Ensure that when loading from existing resources, the data structure is converted properly
- When saving, maintain the clean structure
Implementation Steps
- Create backup of current CutsceneResource.gd
- Rewrite CutsceneResource.gd with new structure
- Update references in CutsceneGraphEdit.gd to use new methods
- Update CutsceneGenerator.gd to work with new structure
- Test with existing example cutscenes
- Update documentation
Compatibility Considerations
- Need to maintain backward compatibility with existing cutscene files
- Should provide migration path for existing resources
- Consider adding a version field to distinguish between old and new formats