MCPcopy Create free account
hub / github.com/Monogatari/Monogatari / shouldRollback

Function shouldRollback

src/engine/lifecycle.ts:692–744  ·  view source on GitHub ↗
(engine: VisualNovelEngine)

Source from the content-addressed store, hash-verified

690 * can't be reverted right now.
691 */
692export 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
746export function willRollback (engine: VisualNovelEngine): Promise<unknown[]> {
747 const promises = [];

Callers 1

rollbackFunction · 0.85

Calls 7

globalMethod · 0.80
debugMethod · 0.80
componentsMethod · 0.80
actionsMethod · 0.45
shouldRollbackMethod · 0.45
showMethod · 0.45
allMethod · 0.45

Tested by

no test coverage detected