@@ -7,33 +7,10 @@ import type {
77} from "../pages/edit/Editor/store/slices/core" ;
88import type { CCComponentId } from "./component" ;
99import type { CCComponentPin , CCComponentPinId } from "./componentPin" ;
10- import * as intrinsics from "./intrinsics" ;
11- import {
12- aggregate ,
13- and ,
14- decompose ,
15- definitionByComponentId ,
16- flipflop ,
17- input ,
18- not ,
19- or ,
20- xor ,
21- } from "./intrinsics/definitions" ;
10+ import { definitionByComponentId , flipflop } from "./intrinsics/definitions" ;
2211import type { CCNodeId } from "./node" ;
2312import type { CCNodePin , CCNodePinId } from "./nodePin" ;
2413
25- function getNodePinIdByComponentPinId (
26- nodePins : CCNodePin [ ] ,
27- componentPinId : CCComponentPinId ,
28- ) : CCNodePin {
29- const nodePin = nullthrows (
30- nodePins . find (
31- ( nodePin : CCNodePin ) => nodePin . componentPinId === componentPinId ,
32- ) ,
33- ) ;
34- return nodePin ;
35- }
36-
3714function createInput (
3815 nodePins : CCNodePin [ ] ,
3916 inputPin : Record < string , CCComponentPin > ,
@@ -57,26 +34,22 @@ function createInput(
5734function createOutputShape (
5835 store : CCStore ,
5936 nodePins : CCNodePin [ ] ,
60- outputPin : Record < string , CCComponentPin > ,
61- ) : Record < string , { multiplicity : number } [ ] > {
62- const outputShape : Record < string , { multiplicity : number } [ ] > = { } ;
63- for ( const key in outputPin ) {
64- const componentPin = nullthrows ( outputPin [ key ] ) ;
65- const targetNodePins = nodePins . filter (
66- ( nodePin : CCNodePin ) => componentPin . id === nodePin . componentPinId ,
37+ outputPin : CCComponentPin ,
38+ ) : { multiplicity : number } [ ] {
39+ const targetNodePins = nodePins . filter (
40+ ( nodePin : CCNodePin ) => outputPin . id === nodePin . componentPinId ,
41+ ) ;
42+ targetNodePins . sort ( ( a , b ) => a . order - b . order ) ;
43+ const multiplicity = targetNodePins . map ( ( nodePin : CCNodePin ) => {
44+ const multiplexability = store . nodePins . getNodePinMultiplexability (
45+ nodePin . id ,
6746 ) ;
68- targetNodePins . sort ( ( a , b ) => a . order - b . order ) ;
69- const multiplicity = targetNodePins . map ( ( nodePin : CCNodePin ) => {
70- const multiplexability = store . nodePins . getNodePinMultiplexability (
71- nodePin . id ,
72- ) ;
73- if ( multiplexability . isMultiplexable ) {
74- return 1 ;
75- }
76- return multiplexability . multiplicity ;
77- } ) ;
78- outputShape [ key ] = multiplicity . map ( ( multiplicity ) => ( { multiplicity } ) ) ;
79- }
47+ if ( multiplexability . isMultiplexable ) {
48+ return 1 ;
49+ }
50+ return multiplexability . multiplicity ;
51+ } ) ;
52+ const outputShape = multiplicity . map ( ( multiplicity ) => ( { multiplicity } ) ) ;
8053 return outputShape ;
8154}
8255
@@ -111,9 +84,8 @@ function simulateIntrinsic(
11184 previousInput ,
11285 ) ;
11386 const outputValues = new Map < CCNodePinId , SimulationValue > ( ) ;
114- const componentPin = nullthrows ( outputPin [ "Out" as any ] ) ;
11587 const targetNodePins = nodePins . filter (
116- ( nodePin : CCNodePin ) => componentPin . id === nodePin . componentPinId ,
88+ ( nodePin : CCNodePin ) => outputPin . id === nodePin . componentPinId ,
11789 ) ;
11890 targetNodePins . sort ( ( a , b ) => a . order - b . order ) ;
11991 for ( let i = 0 ; i < output . length ; i ++ ) {
@@ -263,17 +235,13 @@ function simulateNode(
263235 ) ;
264236 outputValues . set ( parentNodePin . id , outputValue ) ;
265237 }
266- if (
267- currentComponentId ===
268- intrinsics . flipFlopIntrinsicComponentDefinition . component . id
269- ) {
238+ if ( currentComponentId === flipflop . id ) {
270239 visitedFlipFlops . add ( currentNodeId ) ;
271240 }
272241 }
273242 }
274243 } else if (
275- currentComponentId ===
276- intrinsics . flipFlopIntrinsicComponentDefinition . component . id &&
244+ currentComponentId === flipflop . id &&
277245 ! visitedFlipFlops . has ( currentNodeId )
278246 ) {
279247 const frame = previousFrame
@@ -319,10 +287,7 @@ function simulateNode(
319287 ) ;
320288 outputValues . set ( parentNodePin . id , outputValue ) ;
321289 }
322- if (
323- currentComponentId ===
324- intrinsics . flipFlopIntrinsicComponentDefinition . component . id
325- ) {
290+ if ( currentComponentId === flipflop . outputPin . componentId ) {
326291 visitedFlipFlops . add ( currentNodeId ) ;
327292 }
328293 }
@@ -466,10 +431,7 @@ export default function simulateComponent(
466431 ) ;
467432 outputValues . set ( parentComponentPin . id , outputValue ) ;
468433 }
469- if (
470- currentComponentId ===
471- intrinsics . flipFlopIntrinsicComponentDefinition . component . id
472- ) {
434+ if ( currentComponentId === flipflop . outputPin . componentId ) {
473435 visitedFlipFlops . add ( currentNodeId ) ;
474436 }
475437 }
0 commit comments