@@ -21,6 +21,7 @@ import type { ParticleTeleportInBlock } from "./Blocks/Teleport/particleTeleport
21
21
import { BoxShapeBlock } from "./Blocks/Emitters/boxShapeBlock" ;
22
22
import { CreateParticleBlock } from "./Blocks/Emitters/createParticleBlock" ;
23
23
import type { Color4 } from "core/Maths/math.color" ;
24
+ import type { Nullable } from "../../types" ;
24
25
25
26
// declare NODEPARTICLEEDITOR namespace for compilation issue
26
27
declare let NODEPARTICLEEDITOR : any ;
@@ -108,6 +109,56 @@ export class NodeParticleSystemSet {
108
109
return blocks ;
109
110
}
110
111
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
+ }
111
162
/**
112
163
* Creates a new set
113
164
* @param name defines the name of the set
0 commit comments