@@ -8,32 +8,36 @@ import { CCConnectionStore } from "../../../../store/connection";
88import type { CCNodePinId } from "../../../../store/nodePin" ;
99import { useStore } from "../../../../store/react" ;
1010import { useComponentEditorStore } from "../store" ;
11- import type { SimulationValue } from "../store/slices/core" ;
1211import { CCComponentEditorRendererConnectionCore } from "./Connection" ;
12+ import CCComponentEditorRendererInputValue from "./InputValue" ;
1313import getCCComponentEditorRendererNodeGeometry from "./Node.geometry" ;
1414
1515const NODE_PIN_POSITION_SENSITIVITY = 10 ;
1616
1717export type CCComponentEditorRendererNodePinProps = {
1818 nodePinId : CCNodePinId ;
19- position : Vector2 ;
2019} ;
2120export const CCComponentEditorRendererNodePinConstants = {
2221 SIZE : 10 ,
2322} ;
2423export default function CCComponentEditorRendererNodePin ( {
2524 nodePinId,
26- position,
2725} : CCComponentEditorRendererNodePinProps ) {
2826 const { store } = useStore ( ) ;
2927 const componentEditorState = useComponentEditorStore ( ) ( ) ;
3028 const nodePin = nullthrows ( store . nodePins . get ( nodePinId ) ) ;
3129 const node = nullthrows ( store . nodes . get ( nodePin . nodeId ) ) ;
32- const nodePins = store . nodePins . getManyByNodeId ( node . id ) ;
3330 const componentPin = nullthrows (
3431 store . componentPins . get ( nodePin . componentPinId ) ,
3532 ) ;
3633
34+ const position = nullthrows (
35+ getCCComponentEditorRendererNodeGeometry (
36+ store ,
37+ nodePin . nodeId ,
38+ ) . nodePinPositionById . get ( nodePinId ) ,
39+ ) ;
40+
3741 const [ draggingState , setDraggingState ] = useState < {
3842 cursorPosition : Vector2 ;
3943 nodePinPositionKDTree : KDTree < CCNodePinId > ;
@@ -133,63 +137,13 @@ export default function CCComponentEditorRendererNodePin({
133137 const isSimulationMode = useComponentEditorStore ( ) (
134138 ( s ) => s . editorMode === "play" ,
135139 ) ;
136- const hasNoConnection =
137- store . connections . getConnectionsByNodePinId ( nodePinId ) . length === 0 ;
138-
139- const pinType = componentPin . type ;
140- const simulationValueToString = ( simulationValue : SimulationValue ) => {
141- return simulationValue . reduce (
142- ( acm , currentValue ) => acm + ( currentValue === true ? "1" : "0" ) ,
143- "" ,
144- ) ;
145- } ;
146- const implementationComponentPin =
140+ const interfaceComponentPin =
147141 store . componentPins . getByImplementation ( nodePinId ) ;
148- let nodePinValue : SimulationValue ;
149- let nodePinValueAsString : string | null = null ;
150- if ( isSimulationMode && hasNoConnection ) {
151- if (
152- implementationComponentPin &&
153- implementationComponentPin . type === "input"
154- ) {
155- nodePinValue = nullthrows (
156- componentEditorState . getInputValue (
157- implementationComponentPin . id ,
158- nodePins ,
159- ) ,
160- ) ;
161- } else {
162- nodePinValue = nullthrows (
163- componentEditorState . getNodePinValue ( nodePinId ) ,
164- ) ;
165- }
166- nodePinValueAsString = simulationValueToString ( nodePinValue ) ;
167- }
168- const updateInputValue = ( ) => {
169- if (
170- ! implementationComponentPin ||
171- implementationComponentPin . type !== "input"
172- )
173- return ;
174- const updatedPinValue = [ ...nodePinValue ] ;
175- updatedPinValue [ 0 ] = ! updatedPinValue [ 0 ] ;
176- componentEditorState . setInputValue (
177- implementationComponentPin ?. id ,
178- updatedPinValue ,
179- ) ;
180- } ;
181142
182143 return (
183144 < >
184- { nodePinValueAsString && (
185- < text
186- x = { position . x - ( pinType === "input" ? 15 : - 8 ) }
187- y = { position . y }
188- onPointerDown = { updateInputValue }
189- fill = { theme . palette . textPrimary }
190- >
191- { nodePinValueAsString }
192- </ text >
145+ { isSimulationMode && interfaceComponentPin && (
146+ < CCComponentEditorRendererInputValue nodePinId = { nodePinId } />
193147 ) }
194148 < g { ...draggableProps } style = { { cursor : "pointer" } } >
195149 < rect
@@ -229,10 +183,10 @@ export default function CCComponentEditorRendererNodePin({
229183 {
230184 input : CCComponentEditorRendererNodePinConstants . SIZE ,
231185 output : - CCComponentEditorRendererNodePinConstants . SIZE ,
232- } [ pinType ]
186+ } [ componentPin . type ]
233187 }
234188 y = { position . y }
235- textAnchor = { { input : "start" , output : "end" } [ pinType ] }
189+ textAnchor = { { input : "start" , output : "end" } [ componentPin . type ] }
236190 dominantBaseline = "central"
237191 fontSize = { 12 }
238192 fill = { theme . palette . textPrimary }
0 commit comments