* @param idx If not specified, return the first one.
(mainType: ComponentMainType, idx?: number)
| 570 | * @param idx If not specified, return the first one. |
| 571 | */ |
| 572 | getComponent(mainType: ComponentMainType, idx?: number): ComponentModel { |
| 573 | const list = this._componentsMap.get(mainType); |
| 574 | if (list) { |
| 575 | const cmpt = list[idx || 0]; |
| 576 | if (cmpt) { |
| 577 | return cmpt; |
| 578 | } |
| 579 | else if (idx == null) { |
| 580 | for (let i = 0; i < list.length; i++) { |
| 581 | if (list[i]) { |
| 582 | return list[i]; |
| 583 | } |
| 584 | } |
| 585 | } |
| 586 | } |
| 587 | } |
| 588 | |
| 589 | /** |
| 590 | * @return Never be null/undefined. |