Skip to content

Commit 29d429a

Browse files
deltakoshDavid Catuhe
andauthored
Add missing API to NPE (#17022)
Co-authored-by: David Catuhe <[email protected]>
1 parent 993698c commit 29d429a

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

packages/dev/core/src/Particles/Node/nodeParticleSystemSet.ts

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import type { ParticleTeleportInBlock } from "./Blocks/Teleport/particleTeleport
2121
import { BoxShapeBlock } from "./Blocks/Emitters/boxShapeBlock";
2222
import { CreateParticleBlock } from "./Blocks/Emitters/createParticleBlock";
2323
import type { Color4 } from "core/Maths/math.color";
24+
import type { Nullable } from "../../types";
2425

2526
// declare NODEPARTICLEEDITOR namespace for compilation issue
2627
declare let NODEPARTICLEEDITOR: any;
@@ -108,6 +109,56 @@ export class NodeParticleSystemSet {
108109
return blocks;
109110
}
110111

112+
/**
113+
* Get a block by its name
114+
* @param name defines the name of the block to retrieve
115+
* @returns the required block or null if not found
116+
*/
117+
public getBlockByName(name: string) {
118+
let result = null;
119+
for (const block of this.attachedBlocks) {
120+
if (block.name === name) {
121+
if (!result) {
122+
result = block;
123+
} else {
124+
Tools.Warn("More than one block was found with the name `" + name + "`");
125+
return result;
126+
}
127+
}
128+
}
129+
130+
return result;
131+
}
132+
133+
/**
134+
* Get a block using a predicate
135+
* @param predicate defines the predicate used to find the good candidate
136+
* @returns the required block or null if not found
137+
*/
138+
public getBlockByPredicate(predicate: (block: NodeParticleBlock) => boolean) {
139+
for (const block of this.attachedBlocks) {
140+
if (predicate(block)) {
141+
return block;
142+
}
143+
}
144+
145+
return null;
146+
}
147+
148+
/**
149+
* Get an input block using a predicate
150+
* @param predicate defines the predicate used to find the good candidate
151+
* @returns the required input block or null if not found
152+
*/
153+
public getInputBlockByPredicate(predicate: (block: ParticleInputBlock) => boolean): Nullable<ParticleInputBlock> {
154+
for (const block of this.attachedBlocks) {
155+
if (block.isInput && predicate(block as ParticleInputBlock)) {
156+
return block as ParticleInputBlock;
157+
}
158+
}
159+
160+
return null;
161+
}
111162
/**
112163
* Creates a new set
113164
* @param name defines the name of the set

0 commit comments

Comments
 (0)