@@ -31,7 +31,65 @@ public enum LayerInputDataEntity_V22: StitchSchemaVersionable {
3131
3232extension LayerInputDataEntity_V22 . LayerInputDataEntity : StitchVersionedCodable {
3333 public init ( previousInstance: LayerInputDataEntity_V22 . PreviousInstance ) {
34- self . inputPort = . init( previousInstance: previousInstance. inputPort)
35- self . canvasItem = . init( previousInstance: previousInstance. canvasItem)
34+ self . init (
35+ inputPort: . init( previousInstance: previousInstance. inputPort) ,
36+ // TODO: fix canvas migration after v22, for v22 it needs to be nil to reset previous position port hack
37+ canvasItem: nil
38+ )
39+ }
40+
41+ // TODO: don't forget about outputs
42+ // MARK: delete this after v22
43+ mutating func createConnectedCanvas( nodes: [ NodeEntity_V22 . NodeEntity ] ) {
44+ switch self . inputPort {
45+ case . upstreamConnection( let connection) :
46+ guard let upstreamNode = nodes. first ( where: { $0. id == connection. nodeId } ) ,
47+ let upstreamCanvas = upstreamNode. getCanvas ( ) else {
48+ #if DEBUG
49+ fatalError ( )
50+ #endif
51+
52+ // If failure use zero position
53+ self . canvasItem = . init( position: . zero,
54+ zIndex: . zero,
55+ parentGroupNodeId: nil )
56+ return
57+ }
58+
59+ var layerInputCanvas = upstreamCanvas
60+ layerInputCanvas. zIndex += 1
61+
62+ // Create staggered location
63+ layerInputCanvas. position = CGPoint ( x: upstreamCanvas. position. x + 450 ,
64+ y: upstreamCanvas. position. y)
65+
66+ // Change parent group if upstream connected node is output splitter
67+ switch upstreamNode. nodeTypeEntity {
68+ case . patch( let patchNode) :
69+ if patchNode. splitterNode? . type == . output {
70+ guard let groupNodeId = upstreamCanvas. parentGroupNodeId,
71+ let groupNode = nodes. first ( where: { $0. id == groupNodeId } ) ,
72+ let groupCanvas = groupNode. getCanvas ( ) else {
73+ #if DEBUG
74+ fatalError ( )
75+ #endif
76+ self . canvasItem = layerInputCanvas
77+ return
78+ }
79+
80+ layerInputCanvas. parentGroupNodeId = groupCanvas. parentGroupNodeId
81+ layerInputCanvas. position = CGPoint ( x: groupCanvas. position. x + 450 ,
82+ y: groupCanvas. position. y)
83+ }
84+
85+ default :
86+ break
87+ }
88+
89+ self . canvasItem = layerInputCanvas
90+
91+ default :
92+ return
93+ }
3694 }
3795}
0 commit comments