* Reconnects this connection to the input with the given name on the given * block. If there is already a connection connected to that input, that * connection is disconnected. * * @param block The block to connect this connection to. * @param inputName The name of the input to connec
(block: Block, inputName: string)
| 358 | * @returns True if this connection was able to connect, false otherwise. |
| 359 | */ |
| 360 | reconnect(block: Block, inputName: string): boolean { |
| 361 | // No need to reconnect if this connection's block is deleted. |
| 362 | if (this.getSourceBlock().isDeadOrDying()) return false; |
| 363 | |
| 364 | const connectionParent = block.getInput(inputName)?.connection; |
| 365 | const currentParent = this.targetBlock(); |
| 366 | if ( |
| 367 | (!currentParent || currentParent === block) && |
| 368 | connectionParent && |
| 369 | connectionParent.targetConnection !== this |
| 370 | ) { |
| 371 | if (connectionParent.isConnected()) { |
| 372 | // There's already something connected here. Get rid of it. |
| 373 | connectionParent.disconnect(); |
| 374 | } |
| 375 | connectionParent.connect(this); |
| 376 | return true; |
| 377 | } |
| 378 | return false; |
| 379 | } |
| 380 | |
| 381 | /** |
| 382 | * Returns the block that this connection connects to. |
no test coverage detected