@@ -3,11 +3,10 @@ import nullthrows from "nullthrows";
33import type { CCConnectionId } from "../../../../store/connection" ;
44import type CCStore from "../../../../store" ;
55import CCComponentEditorRendererNode from "./node" ;
6- import type {
7- ComponentEditorStore ,
8- EditorMode ,
9- SimulationValue ,
10- } from "../store" ;
6+ import type { EditorMode } from "../store" ;
7+ import CCComponentEditorRendererBase , {
8+ type CCComponentEditorRendererContext ,
9+ } from "./base" ;
1110
1211export type CCConnectionEndpoint = {
1312 nodeId : string ;
@@ -20,7 +19,7 @@ const lineColor = 0x000000;
2019/**
2120 * Class for rendering connection
2221 */
23- export default class CCComponentEditorRendererConnection {
22+ export default class CCComponentEditorRendererConnection extends CCComponentEditorRendererBase {
2423 #store: CCStore ;
2524
2625 #connectionId: CCConnectionId ;
@@ -42,12 +41,8 @@ export default class CCComponentEditorRendererConnection {
4241
4342 #offset: number ;
4443
45- #componentEditorStore: ComponentEditorStore ;
46-
4744 #onDragStart: ( e : PIXI . FederatedMouseEvent ) => void ;
4845
49- #getPinValue: ( ) => SimulationValue | undefined ;
50-
5146 /**
5247 * Constructor of CCComponentEditorRendererConnection
5348 * @param store store
@@ -62,14 +57,13 @@ export default class CCComponentEditorRendererConnection {
6257 store : CCStore ,
6358 connectionId : CCConnectionId ,
6459 pixiParentContainer : PIXI . Container ,
65- componentEditorStore : ComponentEditorStore ,
66- onDragStart : ( e : PIXI . FederatedMouseEvent ) => void ,
67- getPinValue : ( ) => SimulationValue | undefined
60+ context : CCComponentEditorRendererContext ,
61+ onDragStart : ( e : PIXI . FederatedMouseEvent ) => void
6862 ) {
63+ super ( context ) ;
6964 this . #store = store ;
7065 this . #connectionId = connectionId ;
7166 this . #onDragStart = onDragStart ;
72- this . #getPinValue = getPinValue ;
7367 this . #pixiGraphics = {
7468 from : CCComponentEditorRendererConnection . #createGraphics( ) ,
7569 middle : CCComponentEditorRendererConnection . #createGraphics( ) ,
@@ -103,23 +97,25 @@ export default class CCComponentEditorRendererConnection {
10397 } ) ;
10498 const editValueText = ( mode : EditorMode ) => {
10599 if ( mode === "play" ) {
106- const value = this . #getPinValue( )
107- ?. map ( ( v ) => ( v ? "1" : "0" ) )
108- . join ( "" ) ;
100+ const connection = this . #store. connections . get ( this . #connectionId) ! ;
101+ const inputValue = this . context . componentEditorStore
102+ . getState ( )
103+ . getNodePinValue ( connection . from ) ! ;
104+ const value = inputValue . map ( ( v ) => ( v ? "1" : "0" ) ) . join ( "" ) ;
109105 this . #pixiGraphics. value . text = value || "" ;
110106 this . #pixiGraphics. value . visible = true ;
111107 } else {
112108 this . #pixiGraphics. value . visible = false ;
113109 }
114110 } ;
115111 this . #pixiGraphics. from . on ( "mouseover" , ( ) => {
116- editValueText ( this . # componentEditorStore. getState ( ) . editorMode ) ;
112+ editValueText ( this . context . componentEditorStore . getState ( ) . editorMode ) ;
117113 } ) ;
118114 this . #pixiGraphics. to . on ( "mouseover" , ( ) => {
119- editValueText ( this . # componentEditorStore. getState ( ) . editorMode ) ;
115+ editValueText ( this . context . componentEditorStore . getState ( ) . editorMode ) ;
120116 } ) ;
121117 this . #pixiGraphics. middle . on ( "mouseover" , ( ) => {
122- editValueText ( this . # componentEditorStore. getState ( ) . editorMode ) ;
118+ editValueText ( this . context . componentEditorStore . getState ( ) . editorMode ) ;
123119 } ) ;
124120 this . #pixiGraphics. from . on ( "mouseout" , ( ) => {
125121 this . #pixiGraphics. value . visible = false ;
@@ -135,7 +131,6 @@ export default class CCComponentEditorRendererConnection {
135131 ) ! . bentPortion ;
136132 this . #temporaryBentPortion = this . #bentPortionCache;
137133 this . #offset = 0 ;
138- this . #componentEditorStore = componentEditorStore ;
139134 this . #render( ) ;
140135 this . #store. nodes . on ( "didUpdate" , this . #render) ;
141136 }
@@ -146,11 +141,11 @@ export default class CCComponentEditorRendererConnection {
146141 */
147142 onPointerDown ( e : PIXI . FederatedEvent ) {
148143 if (
149- ! this . # componentEditorStore
144+ ! this . context . componentEditorStore
150145 . getState ( )
151146 . selectedConnectionIds . has ( this . #connectionId)
152147 ) {
153- this . # componentEditorStore
148+ this . context . componentEditorStore
154149 . getState ( )
155150 . selectConnection ( [ this . #connectionId] , false ) ;
156151 }
@@ -204,7 +199,7 @@ export default class CCComponentEditorRendererConnection {
204199 /**
205200 * Destroy the connection
206201 */
207- destroy ( ) {
202+ override destroy ( ) {
208203 this . #pixiParentContainer. removeChild ( this . #pixiGraphics. from ) ;
209204 this . #pixiParentContainer. removeChild ( this . #pixiGraphics. middle ) ;
210205 this . #pixiParentContainer. removeChild ( this . #pixiGraphics. to ) ;
@@ -249,19 +244,17 @@ export default class CCComponentEditorRendererConnection {
249244 * Render the connection
250245 */
251246 #render = ( ) => {
247+ const connection = this . #store. connections . get ( this . #connectionId) ;
248+ if ( ! connection ) return ;
252249 this . #pixiGraphics. from . clear ( ) ;
253250 this . #pixiGraphics. middle . clear ( ) ;
254251 this . #pixiGraphics. to . clear ( ) ;
255252 this . #pixiGraphics. from . lineStyle ( lineWidth , lineColor ) ;
256253 this . #pixiGraphics. middle . lineStyle ( lineWidth , lineColor ) ;
257254 this . #pixiGraphics. to . lineStyle ( lineWidth , lineColor ) ;
258255 const endPointGap = 9 ;
259- const fromEndPoint = nullthrows (
260- this . #store. connections . get ( this . #connectionId) ?. from
261- ) ;
262- const toEndPoint = nullthrows (
263- this . #store. connections . get ( this . #connectionId) ?. to
264- ) ;
256+ const fromEndPoint = nullthrows ( connection . from ) ;
257+ const toEndPoint = nullthrows ( connection . to ) ;
265258 const fromPosition = CCComponentEditorRendererNode . getNodePinAbsolute (
266259 this . #store,
267260 fromEndPoint
0 commit comments