Skip to content

Commit af2a1fb

Browse files
committed
use getPinValue instead of calling simulation
1 parent 6db280f commit af2a1fb

3 files changed

Lines changed: 10 additions & 80 deletions

File tree

src/pages/edit/Editor/renderer/componentPin.ts

Lines changed: 4 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ type CCComponentEditorRendererComponentPinProps = {
2020
nodeId: CCNodeId; // TODO: this might be unnecessary
2121
pinId: CCComponentPinId;
2222
position: PIXI.Point;
23-
// simulation: () => Map<CCComponentPinId, boolean[]> | null;
23+
getPinValue: () => boolean[] | undefined;
2424
};
2525

2626
/**
@@ -43,7 +43,7 @@ export default class CCComponentEditorRendererComponentPin extends CCComponentEd
4343

4444
readonly #unsubscribeComponentEditorStore: () => void;
4545

46-
// readonly #simulation: () => Map<CCComponentPinId, boolean[]> | null;
46+
readonly #getPinValue: () => boolean[] | undefined;
4747

4848
#valueBoxWidth: number;
4949

@@ -65,7 +65,6 @@ export default class CCComponentEditorRendererComponentPin extends CCComponentEd
6565
super(props.context);
6666
this.#componentPinId = props.pinId;
6767
this.position = props.position;
68-
// this.#simulation = props.simulation;
6968
this.#pixiParentContainer = props.pixiParentContainer;
7069
this.#pixiContainer = new PIXI.Container();
7170
this.#pixiParentContainer.addChild(this.#pixiContainer);
@@ -116,6 +115,7 @@ export default class CCComponentEditorRendererComponentPin extends CCComponentEd
116115
this.context.store.componentPins.on("didUpdate", (pin) => {
117116
if (pin.id === this.#componentPinId) this.render();
118117
});
118+
this.#getPinValue = props.getPinValue;
119119
this.render();
120120
}
121121

@@ -189,9 +189,7 @@ export default class CCComponentEditorRendererComponentPin extends CCComponentEd
189189
}
190190
return valueText;
191191
};
192-
const outputValue = editorState.getComponentPinValue(
193-
this.#componentPinId
194-
);
192+
const outputValue = this.#getPinValue();
195193
if (outputValue) {
196194
this.#pixiValueText.text = createValueText(outputValue);
197195
this.#valueBoxWidth =
@@ -202,30 +200,6 @@ export default class CCComponentEditorRendererComponentPin extends CCComponentEd
202200
this.#pixiValueText.text = "";
203201
this.#pixiGraphics.beginFill(errorColor);
204202
}
205-
206-
// const output = this.#simulation();
207-
// if (output) {
208-
// const createValueText = (values: boolean[]) => {
209-
// let valueText = "";
210-
// for (let i = 0; i < values.length; i += 1) {
211-
// valueText += values[i] ? "1" : "0";
212-
// }
213-
// return valueText;
214-
// };
215-
// for (const [key, values] of output) {
216-
// if (key === this.#componentPinId) {
217-
// this.#pixiValueText.text = createValueText(values);
218-
// this.#valueBoxWidth =
219-
// c.valueBoxWidthUnit +
220-
// ((values.length - 1) * c.valueBoxWidthUnit) / 4;
221-
// break;
222-
// }
223-
// }
224-
// this.#pixiGraphics.beginFill(grayColor.darken2);
225-
// } else {
226-
// this.#pixiValueText.text = "";
227-
// this.#pixiGraphics.beginFill(errorColor);
228-
// }
229203
}
230204
this.#pixiLabelTextBox.alignment =
231205
pin.type === "input" ? "right" : "left";

src/pages/edit/Editor/renderer/index.tsx

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -390,55 +390,13 @@ export default class CCComponentEditorRenderer extends CCComponentEditorRenderer
390390
this.#dragState = null;
391391
};
392392

393-
// const simulation = (targetNodeId: CCNodeId) => {
394-
// const editorState = this.context.componentEditorStore.getState();
395-
// const nodePins =
396-
// this.context.store.nodePins.getManyByNodeId(targetNodeId);
397-
// const input = new Map<CCComponentPinId, boolean[]>();
398-
// for (const nodePin of nodePins) {
399-
// const componentPin = this.context.store.componentPins.get(
400-
// nodePin.componentPinId
401-
// )!;
402-
// if (componentPin.type === "input") {
403-
// // is pin implemented by user
404-
// if (componentPin.implementation !== null) {
405-
// if (this.context.store.connections.hasNoConnectionOf(nodePin.id)) {
406-
// const multiplexability =
407-
// this.context.store.nodePins.getNodePinMultiplexability(
408-
// nodePin.id
409-
// );
410-
// const bits = multiplexability.isMultiplexable
411-
// ? 1
412-
// : multiplexability.multiplicity;
413-
// const inputValue = editorState.getInputValue(nodePin.id);
414-
// input.set(pinId, inputValue);
415-
// }
416-
// }
417-
// }
418-
// }
419-
// const output = this.#simulator.simulation(input, editorState.timeStep);
420-
// if (output == null) return null;
421-
// const nodeOutput = new Map<CCComponentPinId, boolean[]>();
422-
// for (const [outputPinId, outputValue] of output) {
423-
// const pin = this.context.store.componentPins.get(outputPinId)!;
424-
// if (
425-
// pin.implementation.type === "user" &&
426-
// pin.implementation.nodeId === targetNodeId
427-
// ) {
428-
// nodeOutput.set(pin.implementation.pinId, outputValue);
429-
// }
430-
// }
431-
// return nodeOutput;
432-
// };
433-
434393
const newNodeRenderer = new CCComponentEditorRendererNode({
435394
context: this.context,
436395
nodeId,
437396
pixiParentContainer: this.#pixiWorld,
438397
onDragStart,
439398
onDragStartPin,
440399
onDragEndPin,
441-
// simulation,
442400
});
443401
this.#nodeRenderers.set(nodeId, newNodeRenderer);
444402
}

src/pages/edit/Editor/renderer/node.ts

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ export type CCComponentEditorRendererNodeProps = {
2121
onDragStart(e: PIXI.FederatedMouseEvent): void;
2222
onDragStartPin(e: PIXI.FederatedMouseEvent, nodePinId: CCNodePinId): void;
2323
onDragEndPin(e: PIXI.FederatedMouseEvent, nodePinId: CCNodePinId): void;
24-
// simulation(nodeId: CCNodeId): Map<CCComponentPinId, boolean[]> | null;
2524
};
2625

2726
type PixiTexts = {
@@ -68,8 +67,6 @@ export default class CCComponentEditorRendererNode extends CCComponentEditorRend
6867

6968
#pixiWorld: PIXI.Container;
7069

71-
// #simulation: (nodeId: CCNodeId) => Map<CCComponentPinId, boolean[]> | null;
72-
7370
/**
7471
* Constructor of CCComponentEditorRendererNode
7572
* @param props
@@ -78,7 +75,6 @@ export default class CCComponentEditorRendererNode extends CCComponentEditorRend
7875
super(props.context);
7976
this.#nodeId = props.nodeId;
8077
this.#pixiParentContainer = props.pixiParentContainer;
81-
// this.#simulation = props.simulation;
8278
this.#pixiGraphics = new PIXI.Graphics();
8379
this.#pixiGraphics.eventMode = "dynamic";
8480
this.#pixiTexts = this.#createText();
@@ -283,9 +279,11 @@ export default class CCComponentEditorRendererNode extends CCComponentEditorRend
283279
);
284280
existingComponentPinRenderers.delete(componentPin.id);
285281
} else {
286-
// const simulation = () => {
287-
// return this.#simulation(this.#nodeId);
288-
// };
282+
const getPinValue = () => {
283+
return this.context.componentEditorStore
284+
.getState()
285+
.getNodePinValue(nodePin.id);
286+
};
289287
const componentPinRenderer =
290288
new CCComponentEditorRendererComponentPin({
291289
context: this.context,
@@ -296,7 +294,7 @@ export default class CCComponentEditorRendererNode extends CCComponentEditorRend
296294
this.context.store,
297295
nodePin.id
298296
),
299-
// simulation,
297+
getPinValue,
300298
});
301299
newComponentPinRenderers.set(componentPin.id, componentPinRenderer);
302300
}

0 commit comments

Comments
 (0)