(engine: VisualNovelEngine)
| 690 | * can't be reverted right now. |
| 691 | */ |
| 692 | export function shouldRollback (engine: VisualNovelEngine): Promise<unknown[]> { |
| 693 | // Check if the game is visible, if it's not, then it probably is not |
| 694 | // playing or is looking at some menu and thus the game should not |
| 695 | // revert. The game will not revert if it's blocked or if the distraction |
| 696 | // free mode is enabled. |
| 697 | if (!engine.global ('distraction_free') |
| 698 | && !engine.global ('block') |
| 699 | && (!engine.global ('_engine_block') || engine.global ('_executing_sub_action'))) { |
| 700 | const promises = []; |
| 701 | |
| 702 | engine.debug.groupCollapsed ('shouldRollback Check'); |
| 703 | |
| 704 | try { |
| 705 | // Check action by action if they will allow the game to revert |
| 706 | for (const action of engine.actions ()) { |
| 707 | promises.push (action.shouldRollback ().then (() => { |
| 708 | engine.debug.debug (`OK ${action.id}`); |
| 709 | }).catch ((e) => { |
| 710 | engine.debug.debug (`FAIL ${action.id}\nReason: ${e}`); |
| 711 | return Promise.reject (e); |
| 712 | })); |
| 713 | } |
| 714 | |
| 715 | // Check component by component if they will allow the game to revert |
| 716 | for (const component of engine.components ()) { |
| 717 | promises.push (component.shouldRollback ().then (() => { |
| 718 | engine.debug.debug (`OK ${component.tag}`); |
| 719 | }).catch ((e) => { |
| 720 | engine.debug.debug (`FAIL ${component.tag}\nReason: ${e}`); |
| 721 | return Promise.reject (e); |
| 722 | })); |
| 723 | } |
| 724 | } catch (e) { |
| 725 | console.error (e); |
| 726 | |
| 727 | const errorMessage = e instanceof Error ? e.message : String(e); |
| 728 | |
| 729 | FancyError.show ('engine:lifecycle:should_rollback_error', { |
| 730 | errorMessage: errorMessage |
| 731 | }); |
| 732 | } |
| 733 | |
| 734 | return Promise.all (promises).then ((...args) => { |
| 735 | engine.debug.groupEnd (); |
| 736 | return Promise.resolve (...args); |
| 737 | }).catch ((e) => { |
| 738 | engine.debug.groupEnd (); |
| 739 | return Promise.reject (e); |
| 740 | }); |
| 741 | } else { |
| 742 | return Promise.reject ('Extra condition check failed.'); |
| 743 | } |
| 744 | } |
| 745 | |
| 746 | export function willRollback (engine: VisualNovelEngine): Promise<unknown[]> { |
| 747 | const promises = []; |
no test coverage detected