Skip to content

Commit 952881b

Browse files
committed
Cleaned up code formatting and removed 'Random' node TODOs
1 parent 60eec1f commit 952881b

File tree

5 files changed

+64
-69
lines changed

5 files changed

+64
-69
lines changed

TODO.md

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,4 @@
1010
- [ ] Node labeling
1111

1212
- [ ] Add new node types:
13-
- [ ] Switch
14-
- [ ] Random
15-
- [ ] Types:
16-
- [ ] Number (with properties: min: 1, max: 100)
17-
- [ ] String (with properties: length: 10, charset: abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789)
18-
- [ ] Boolean (with properties: probability: 50)
13+
- [ ] Switch

src/VisualScripting.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -238,21 +238,21 @@ const VisualScripting = () => {
238238
// Check input ports
239239
for (let i = 0; i < nodeType.inputs.length; i++) {
240240
const portX = node.x - PORT_OFFSET - PORT_WIDTH; // Position of gray arrow
241-
const portY = node.y + portStartY + i * 20 - PORT_HEIGHT/2;
242-
241+
const portY = node.y + portStartY + i * 20 - PORT_HEIGHT / 2;
242+
243243
if (x >= portX && x <= portX + PORT_WIDTH * SCALE_MULTIPLIER &&
244-
y >= portY && y <= portY + PORT_HEIGHT * SCALE_MULTIPLIER) {
244+
y >= portY && y <= portY + PORT_HEIGHT * SCALE_MULTIPLIER) {
245245
return { nodeId: node.id, isInput: true, index: i };
246246
}
247247
}
248248

249249
// Check output ports
250250
for (let i = 0; i < nodeType.outputs.length; i++) {
251251
const portX = node.x + width + PORT_OFFSET; // Position of gray arrow
252-
const portY = node.y + portStartY + i * 20 - PORT_HEIGHT/2;
253-
252+
const portY = node.y + portStartY + i * 20 - PORT_HEIGHT / 2;
253+
254254
if (x >= portX && x <= portX + PORT_WIDTH * SCALE_MULTIPLIER &&
255-
y >= portY && y <= portY + PORT_HEIGHT * SCALE_MULTIPLIER) {
255+
y >= portY && y <= portY + PORT_HEIGHT * SCALE_MULTIPLIER) {
256256
return { nodeId: node.id, isInput: false, index: i };
257257
}
258258
}
@@ -566,12 +566,12 @@ const VisualScripting = () => {
566566
const newConfig = { ...prevConfig };
567567
const parts = path.split('.');
568568
let current = newConfig;
569-
569+
570570
for (let i = 0; i < parts.length - 1; i++) {
571571
current[parts[i]] = { ...current[parts[i]] };
572572
current = current[parts[i]];
573573
}
574-
574+
575575
current[parts[parts.length - 1]] = value;
576576
return newConfig;
577577
});

src/components/GraphInspector.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ import React from 'react';
22
import styles from './GraphInspector.module.css';
33
import { getIconForNodeType } from './ContextMenu';
44

5-
const GraphInspector = ({
6-
selectedNodes,
7-
nodeTypes,
8-
updateNodeProperty,
9-
config
5+
const GraphInspector = ({
6+
selectedNodes,
7+
nodeTypes,
8+
updateNodeProperty,
9+
config
1010
}) => {
1111
if (selectedNodes.length === 0) {
1212
return (
@@ -33,7 +33,7 @@ const GraphInspector = ({
3333
{/* Header */}
3434
<div className={`${styles.header} ${config.isDarkTheme ? styles.headerDark : styles.headerLight}`}>
3535
<div className={styles.headerContent}>
36-
<i
36+
<i
3737
className={`fas ${getIconForNodeType(node.type)} ${styles.nodeIcon}`}
3838
style={{ color: nodeType.color }}
3939
/>
@@ -87,7 +87,7 @@ const GraphInspector = ({
8787
)}
8888

8989
<hr></hr>
90-
90+
9191
{/* Ports */}
9292
<div className={styles.section}>
9393
{/* Input Ports */}
@@ -104,7 +104,7 @@ const GraphInspector = ({
104104

105105
{/* Output Ports */}
106106
<div className={`${styles.sectionTitle} ${config.isDarkTheme ? styles.sectionTitleDark : styles.sectionTitleLight}`}
107-
style={{ marginTop: '20px' }}>
107+
style={{ marginTop: '20px' }}>
108108
Output Ports
109109
</div>
110110
{nodeType.outputs.map((output, index) => (

src/engine/Renderer.js

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,9 @@ class Renderer {
5555
const inputsHeight = nodeType.inputs.length * 20;
5656
const outputsHeight = nodeType.outputs.length * 20;
5757
const propertiesHeight = nodeType.properties ? nodeType.properties.reduce((height, prop) => {
58-
const isVisible = prop.visible === undefined ||
59-
(typeof prop.visible === 'function' ?
60-
prop.visible(node.properties) :
58+
const isVisible = prop.visible === undefined ||
59+
(typeof prop.visible === 'function' ?
60+
prop.visible(node.properties) :
6161
prop.visible);
6262
return height + (isVisible ? 20 : 0);
6363
}, 0) : 0;
@@ -117,17 +117,17 @@ class Renderer {
117117
edges.forEach(edge => {
118118
const startNode = nodes.find(n => n.id === edge.start.nodeId);
119119
const endNode = nodes.find(n => n.id === edge.end.nodeId);
120-
120+
121121
if (!startNode || !endNode) return;
122122

123123
// Quick bounds check for edge endpoints
124124
const startDims = this.getNodeDimensions(startNode, ctx);
125125
const endDims = this.getNodeDimensions(endNode, ctx);
126-
126+
127127
// Skip if both nodes are completely outside view (with padding)
128128
const padding = 200; // Larger padding for edges due to curves
129129
if (!this.isRectInView(startNode.x, startNode.y, startDims.width, startDims.height, ctx.canvas.width, ctx.canvas.height, padding) &&
130-
!this.isRectInView(endNode.x, endNode.y, endDims.width, endDims.height, ctx.canvas.width, ctx.canvas.height, padding)) {
130+
!this.isRectInView(endNode.x, endNode.y, endDims.width, endDims.height, ctx.canvas.width, ctx.canvas.height, padding)) {
131131
return;
132132
}
133133

@@ -173,7 +173,7 @@ class Renderer {
173173
drawPortIcon(ctx, x, y, isInput) {
174174
const offset = 5; // Distance from node border
175175
const arrowX = isInput ? x - offset : x + offset;
176-
176+
177177
ctx.beginPath();
178178
if (isInput) {
179179
ctx.moveTo(arrowX - 6, y - 5);
@@ -193,7 +193,7 @@ class Renderer {
193193
drawLabelArrow(ctx, x, y, isControl) {
194194
if (isControl) {
195195
const lineLength = 10;
196-
196+
197197
// Draw line
198198
ctx.beginPath();
199199
ctx.moveTo(x, y);
@@ -222,7 +222,7 @@ class Renderer {
222222
drawNodes(ctx, nodes, edges, selectedNodes) {
223223
nodes.forEach(node => {
224224
const { width, height } = this.getNodeDimensions(node, ctx);
225-
225+
226226
if (!this.isRectInView(node.x, node.y, width, height, ctx.canvas.width, ctx.canvas.height)) {
227227
return;
228228
}
@@ -276,18 +276,18 @@ class Renderer {
276276
nodeType.inputs.forEach((input, i) => {
277277
const portY = node.y + currentHeight + i * 20;
278278
const isControl = input.type === 'control';
279-
279+
280280
// Check if port is connected
281-
const isPortConnected = edges.some(edge =>
282-
edge.end.nodeId === node.id &&
283-
edge.end.index === i &&
281+
const isPortConnected = edges.some(edge =>
282+
edge.end.nodeId === node.id &&
283+
edge.end.index === i &&
284284
edge.end.isInput
285285
);
286-
286+
287287
if (!isPortConnected) {
288288
this.drawPortIcon(ctx, node.x, portY, true);
289289
}
290-
290+
291291
this.drawLabelArrow(ctx, node.x + 15, portY, isControl);
292292
ctx.fillStyle = 'white';
293293
ctx.fillText(input.name, node.x + 35, portY + 5);
@@ -297,17 +297,17 @@ class Renderer {
297297
nodeType.outputs.forEach((output, i) => {
298298
const portY = node.y + currentHeight + i * 20;
299299
const isControl = output.type === 'control';
300-
301-
const isPortConnected = edges.some(edge =>
302-
edge.start.nodeId === node.id &&
303-
edge.start.index === i &&
300+
301+
const isPortConnected = edges.some(edge =>
302+
edge.start.nodeId === node.id &&
303+
edge.start.index === i &&
304304
!edge.start.isInput
305305
);
306-
306+
307307
if (!isPortConnected) {
308308
this.drawPortIcon(ctx, node.x + width, portY, false);
309309
}
310-
310+
311311
ctx.fillStyle = 'white';
312312
const textWidth = ctx.measureText(output.name).width;
313313
ctx.fillText(output.name, node.x + width - textWidth - 35, portY + 5);
@@ -323,9 +323,9 @@ class Renderer {
323323

324324
nodeType.properties.forEach((prop, index) => {
325325
// Check if property should be visible
326-
const isVisible = prop.visible === undefined ||
327-
(typeof prop.visible === 'function' ?
328-
prop.visible(node.properties) :
326+
const isVisible = prop.visible === undefined ||
327+
(typeof prop.visible === 'function' ?
328+
prop.visible(node.properties) :
329329
prop.visible);
330330

331331
if (isVisible) {
@@ -384,9 +384,9 @@ class Renderer {
384384
};
385385

386386
return !(x + width < viewBounds.left - padding ||
387-
x > viewBounds.right + padding ||
388-
y + height < viewBounds.top - padding ||
389-
y > viewBounds.bottom + padding);
387+
x > viewBounds.right + padding ||
388+
y + height < viewBounds.top - padding ||
389+
y > viewBounds.bottom + padding);
390390
}
391391
}
392392

src/nodeDefinitions.js

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -242,40 +242,40 @@ export const nodeTypes = {
242242
],
243243
description: 'Generates random values of different types',
244244
properties: [
245-
{
246-
name: 'type',
247-
type: 'select',
248-
options: ['number', 'string', 'boolean'],
245+
{
246+
name: 'type',
247+
type: 'select',
248+
options: ['number', 'string', 'boolean'],
249249
default: 'number',
250-
visible: true
250+
visible: true
251251
},
252-
{
253-
name: 'min',
254-
type: 'number',
252+
{
253+
name: 'min',
254+
type: 'number',
255255
default: 1,
256256
visible: (props) => props.type === 'number'
257257
},
258-
{
259-
name: 'max',
260-
type: 'number',
258+
{
259+
name: 'max',
260+
type: 'number',
261261
default: 100,
262262
visible: (props) => props.type === 'number'
263263
},
264-
{
265-
name: 'length',
266-
type: 'number',
264+
{
265+
name: 'length',
266+
type: 'number',
267267
default: 10,
268268
visible: (props) => props.type === 'string'
269269
},
270-
{
271-
name: 'charset',
272-
type: 'string',
270+
{
271+
name: 'charset',
272+
type: 'string',
273273
default: 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789',
274274
visible: (props) => props.type === 'string'
275275
},
276-
{
277-
name: 'probability',
278-
type: 'number',
276+
{
277+
name: 'probability',
278+
type: 'number',
279279
default: 50,
280280
visible: (props) => props.type === 'boolean'
281281
}

0 commit comments

Comments
 (0)