(engine: VisualNovelEngine, { userInitiated = false, skip = false, autoPlay = false })
| 540 | * can't proceed right now. |
| 541 | */ |
| 542 | export function shouldProceed (engine: VisualNovelEngine, { userInitiated = false, skip = false, autoPlay = false }): Promise<unknown[]> { |
| 543 | // TODO: This should be removed |
| 544 | const deprecatedBlocks = engine.global ('block') || engine.global ('_executing_sub_action'); |
| 545 | |
| 546 | // Check if the game is visible, if it's not, then it probably is not |
| 547 | // playing or is looking at some menu and thus the game should not |
| 548 | // proceed. The game will not proceed if it's blocked or if the distraction |
| 549 | // free mode is enabled. |
| 550 | if (!$_('.modal').isVisible () |
| 551 | && !engine.global ('distraction_free') |
| 552 | && !deprecatedBlocks |
| 553 | && !engine.global ('_engine_block')) { |
| 554 | const promises = []; |
| 555 | |
| 556 | engine.debug.groupCollapsed ('shouldProceed Check'); |
| 557 | try { |
| 558 | |
| 559 | engine.debug.debug ('Checking Actions'); |
| 560 | |
| 561 | // Check action by action if they will allow the game to proceed |
| 562 | for (const action of engine.actions ()) { |
| 563 | promises.push (action.shouldProceed ({ userInitiated, skip, autoPlay }).then (() => { |
| 564 | engine.debug.debug (`OK ${action.id}`); |
| 565 | }).catch ((e) => { |
| 566 | engine.debug.debug (`FAIL ${action.id}\nReason: ${e}`); |
| 567 | return Promise.reject (e); |
| 568 | })); |
| 569 | } |
| 570 | |
| 571 | engine.debug.debug ('Checking Components'); |
| 572 | |
| 573 | // Check component by component if they will allow the game to proceed |
| 574 | for (const component of engine.components ()) { |
| 575 | promises.push (component.shouldProceed ({ userInitiated, skip, autoPlay }).then (() => { |
| 576 | engine.debug.debug (`OK ${component.tag}`); |
| 577 | }).catch ((e) => { |
| 578 | engine.debug.debug (`FAIL ${component.tag}\nReason: ${e}`); |
| 579 | return Promise.reject (e); |
| 580 | })); |
| 581 | } |
| 582 | } catch (e) { |
| 583 | console.error (e); |
| 584 | const errorMessage = e instanceof Error ? e.message : String(e); |
| 585 | FancyError.show ('engine:lifecycle:should_proceed_error', { |
| 586 | errorMessage: errorMessage |
| 587 | }); |
| 588 | } |
| 589 | |
| 590 | engine.debug.debug ('Checking Extra Conditions'); |
| 591 | |
| 592 | return Promise.all (promises).then ((...args) => { |
| 593 | engine.debug.groupEnd (); |
| 594 | return Promise.resolve (...args); |
| 595 | }).catch ((e) => { |
| 596 | engine.debug.groupEnd (); |
| 597 | return Promise.reject (e); |
| 598 | }); |
| 599 | } else { |
no test coverage detected