* @static onLoad - This is the main onStart function, it acts as an event * listener when a game is loaded. This function will call its action * counterparts so that each action is able to run any operations needed * when a game is loaded such as restoring their state. * * @return {Pr
()
| 674 | * was resolved and is rejected if any were rejected. |
| 675 | */ |
| 676 | static onLoad () { |
| 677 | const promises = []; |
| 678 | |
| 679 | this.global ('_restoring_state', true); |
| 680 | |
| 681 | const actions = this.actions (); |
| 682 | const orders = [...new Set(actions.map(action => action.loadingOrder))].sort(); |
| 683 | |
| 684 | const loadActions = (actions: StaticAction[], dependency = Promise.resolve()) => { |
| 685 | return dependency.then(() => { |
| 686 | const _promises: Promise<void>[] = []; |
| 687 | for (const action of actions) { |
| 688 | _promises.push (action.onLoad ()); |
| 689 | } |
| 690 | return Promise.all(_promises); |
| 691 | }); |
| 692 | }; |
| 693 | |
| 694 | let previous: Promise<unknown> = Promise.resolve(); |
| 695 | |
| 696 | for (const order of orders) { |
| 697 | previous = loadActions(actions.filter(a => a.loadingOrder === order), previous as Promise<void>); |
| 698 | } |
| 699 | |
| 700 | promises.push(previous); |
| 701 | |
| 702 | for (const component of this.components ()) { |
| 703 | promises.push (component.onLoad ()); |
| 704 | } |
| 705 | |
| 706 | return Promise.all (promises).then ((promises) => { |
| 707 | this.global ('_restoring_state', false); |
| 708 | return Promise.resolve (promises); |
| 709 | }); |
| 710 | } |
| 711 | |
| 712 | /** |
| 713 | * @static width - Determines the real width of the Monogatari element, pretty |
no test coverage detected