@@ -2,7 +2,7 @@ import * as PIXI from "pixi.js";
2
2
import invariant from "tiny-invariant" ;
3
3
import type { EditorModePlay } from "../store" ;
4
4
import type { CCNodeId } from "../../../../store/node" ;
5
- import type { CCPinId } from "../../../../store/pin " ;
5
+ import type { CCComponentPinId } from "../../../../store/componentPin " ;
6
6
import {
7
7
activeColor ,
8
8
editorGridColor ,
@@ -18,18 +18,15 @@ type CCComponentEditorRendererComponentPinProps = {
18
18
context : CCComponentEditorRendererContext ;
19
19
pixiParentContainer : PIXI . Container ;
20
20
nodeId : CCNodeId ; // TODO: this might be unnecessary
21
- pinId : CCPinId ;
21
+ pinId : CCComponentPinId ;
22
22
position : PIXI . Point ;
23
- simulation : ( ) => Map < CCPinId , boolean [ ] > | null ;
24
23
} ;
25
24
26
25
/**
27
26
* Class for rendering component pin
28
27
*/
29
28
export default class CCComponentEditorRendererComponentPin extends CCComponentEditorRendererBase {
30
- readonly #nodeId: CCNodeId ;
31
-
32
- readonly #pinId: CCPinId ;
29
+ readonly #componentPinId: CCComponentPinId ;
33
30
34
31
position : PIXI . Point ;
35
32
@@ -45,8 +42,6 @@ export default class CCComponentEditorRendererComponentPin extends CCComponentEd
45
42
46
43
readonly #unsubscribeComponentEditorStore: ( ) => void ;
47
44
48
- readonly #simulation: ( ) => Map < CCPinId , boolean [ ] > | null ;
49
-
50
45
#valueBoxWidth: number ;
51
46
52
47
private static readonly drawingConstants = {
@@ -65,15 +60,16 @@ export default class CCComponentEditorRendererComponentPin extends CCComponentEd
65
60
*/
66
61
constructor ( props : CCComponentEditorRendererComponentPinProps ) {
67
62
super ( props . context ) ;
68
- this . #nodeId = props . nodeId ;
69
- this . #pinId = props . pinId ;
63
+ this . #componentPinId = props . pinId ;
70
64
this . position = props . position ;
71
- this . #simulation = props . simulation ;
72
65
this . #pixiParentContainer = props . pixiParentContainer ;
73
66
this . #pixiContainer = new PIXI . Container ( ) ;
74
67
this . #pixiParentContainer. addChild ( this . #pixiContainer) ;
75
68
this . #pixiGraphics = new PIXI . Graphics ( ) ;
76
- if ( this . context . store . pins . get ( this . #pinId) ! . type === "input" ) {
69
+ if (
70
+ this . context . store . componentPins . get ( this . #componentPinId) ! . type ===
71
+ "input"
72
+ ) {
77
73
// this.#pixiGraphics.interactive = true;
78
74
this . #pixiGraphics. eventMode = "dynamic" ;
79
75
this . #pixiGraphics. cursor = "pointer" ;
@@ -85,7 +81,9 @@ export default class CCComponentEditorRendererComponentPin extends CCComponentEd
85
81
pixiParentContainer : this . #pixiContainer,
86
82
} ) ;
87
83
this . #pixiLabelTextBox. onChange = ( value ) => {
88
- this . context . store . pins . update ( this . #pinId, { name : value } ) ;
84
+ this . context . store . componentPins . update ( this . #componentPinId, {
85
+ name : value ,
86
+ } ) ;
89
87
} ;
90
88
this . registerChildRenderer ( this . #pixiLabelTextBox) ;
91
89
this . #pixiLabelTextBox. fontSize =
@@ -96,7 +94,10 @@ export default class CCComponentEditorRendererComponentPin extends CCComponentEd
96
94
this . #pixiValueText. style . fill =
97
95
CCComponentEditorRendererComponentPin . drawingConstants . valueColor ;
98
96
this . #pixiValueText. anchor . set ( 0.5 , 0.5 ) ;
99
- if ( this . context . store . pins . get ( this . #pinId) ! . type === "input" ) {
97
+ if (
98
+ this . context . store . componentPins . get ( this . #componentPinId) ! . type ===
99
+ "input"
100
+ ) {
100
101
// this.#pixiValueText.interactive = true;
101
102
this . #pixiValueText. eventMode = "dynamic" ;
102
103
this . #pixiValueText. cursor = "pointer" ;
@@ -108,8 +109,8 @@ export default class CCComponentEditorRendererComponentPin extends CCComponentEd
108
109
this . context . componentEditorStore . subscribe ( this . render ) ;
109
110
this . #valueBoxWidth =
110
111
CCComponentEditorRendererComponentPin . drawingConstants . valueBoxWidthUnit ;
111
- this . context . store . pins . on ( "didUpdate" , ( pin ) => {
112
- if ( pin . id === this . #pinId ) this . render ( ) ;
112
+ this . context . store . componentPins . on ( "didUpdate" , ( pin ) => {
113
+ if ( pin . id === this . #componentPinId ) this . render ( ) ;
113
114
} ) ;
114
115
this . render ( ) ;
115
116
}
@@ -119,12 +120,14 @@ export default class CCComponentEditorRendererComponentPin extends CCComponentEd
119
120
* @param e event
120
121
*/
121
122
onClick = ( e : PIXI . FederatedPointerEvent ) => {
122
- const editorState = this . context . componentEditorStore . getState ( ) ;
123
- const previousValue = editorState . getInputValue (
124
- this . #nodeId,
125
- this . #pinId,
126
- this . context . store . pins . get ( this . #pinId) ! . bits
123
+ const componentPin = this . context . store . componentPins . get (
124
+ this . #componentPinId
127
125
) ;
126
+ invariant ( componentPin ) ;
127
+ invariant ( componentPin . implementation ) ;
128
+ const editorState = this . context . componentEditorStore . getState ( ) ;
129
+ const previousValue = editorState . getInputValue ( this . #componentPinId) ;
130
+ invariant ( previousValue ) ;
128
131
const increaseValue = ( value : boolean [ ] ) => {
129
132
const newValue = [ ...value ] ;
130
133
for ( let i = newValue . length - 1 ; i >= 0 ; i -= 1 ) {
@@ -134,8 +137,7 @@ export default class CCComponentEditorRendererComponentPin extends CCComponentEd
134
137
return newValue ;
135
138
} ;
136
139
editorState . setInputValue (
137
- this . #nodeId,
138
- this . #pinId,
140
+ this . #componentPinId,
139
141
increaseValue ( previousValue )
140
142
) ;
141
143
e . preventDefault ( ) ;
@@ -145,7 +147,7 @@ export default class CCComponentEditorRendererComponentPin extends CCComponentEd
145
147
* Render the pin
146
148
*/
147
149
render = ( ) => {
148
- const pin = this . context . store . pins . get ( this . #pinId ) ;
150
+ const pin = this . context . store . componentPins . get ( this . #componentPinId ) ;
149
151
if ( ! pin ) return ;
150
152
151
153
this . #pixiGraphics. clear ( ) ;
@@ -171,34 +173,26 @@ export default class CCComponentEditorRendererComponentPin extends CCComponentEd
171
173
this . #pixiLabelTextBox. isEditable = false ;
172
174
if ( pin . type === "input" ) {
173
175
this . #valueBoxWidth = c . valueBoxWidthUnit ;
174
- const input = editorState . getInputValue (
175
- this . #nodeId,
176
- this . #pinId,
177
- pin . bits
178
- ) ;
176
+ const input = editorState . getInputValue ( this . #componentPinId) ;
177
+ invariant ( input ) ;
179
178
this . #pixiValueText. text = input . map ( ( v ) => ( v ? "1" : "0" ) ) . join ( "" ) ;
180
179
this . #pixiGraphics. beginFill ( activeColor ) ;
181
180
} else {
182
- const output = this . #simulation( ) ;
183
- if ( output ) {
184
- const createValueText = ( values : boolean [ ] ) => {
185
- let valueText = "" ;
186
- for ( let i = 0 ; i < values . length ; i += 1 ) {
187
- valueText += values [ i ] ? "1" : "0" ;
188
- }
189
- return valueText ;
190
- } ;
191
- invariant ( pin . implementation . type === "user" ) ;
192
- const implementationPinId = pin . implementation . pinId ;
193
- for ( const [ key , values ] of output ) {
194
- if ( key === implementationPinId ) {
195
- this . #pixiValueText. text = createValueText ( values ) ;
196
- this . #valueBoxWidth =
197
- c . valueBoxWidthUnit +
198
- ( ( values . length - 1 ) * c . valueBoxWidthUnit ) / 4 ;
199
- break ;
200
- }
181
+ const createValueText = ( values : boolean [ ] ) => {
182
+ let valueText = "" ;
183
+ for ( let i = 0 ; i < values . length ; i += 1 ) {
184
+ valueText += values [ i ] ? "1" : "0" ;
201
185
}
186
+ return valueText ;
187
+ } ;
188
+ const outputValue = editorState . getComponentPinValue (
189
+ this . #componentPinId
190
+ ) ;
191
+ if ( outputValue ) {
192
+ this . #pixiValueText. text = createValueText ( outputValue ) ;
193
+ this . #valueBoxWidth =
194
+ c . valueBoxWidthUnit +
195
+ ( ( outputValue . length - 1 ) * c . valueBoxWidthUnit ) / 4 ;
202
196
this . #pixiGraphics. beginFill ( grayColor . darken2 ) ;
203
197
} else {
204
198
this . #pixiValueText. text = "" ;
0 commit comments