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

Function willRollback

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

Source from the content-addressed store, hash-verified

744}
745
746export function willRollback (engine: VisualNovelEngine): Promise<unknown[]> {
747 const promises = [];
748
749 engine.debug.groupCollapsed ('Should Rollback Check passed, game will roll back.');
750
751 try {
752 // Check action by action if they will allow the game to revert
753 for (const action of engine.actions ()) {
754 promises.push (action.willRollback ().then (() => {
755 engine.debug.debug (`OK ${action.id}`);
756 }).catch ((e) => {
757 engine.debug.debug (`FAIL ${action.id}\nReason: ${e}`);
758 return Promise.reject (e);
759 }));
760 }
761
762 // Check component by component if they will allow the game to revert
763 for (const component of engine.components ()) {
764 promises.push (component.willRollback ().then (() => {
765 engine.debug.debug (`OK ${component.tag}`);
766 }).catch ((e) => {
767 engine.debug.debug (`FAIL ${component.tag}\nReason: ${e}`);
768 return Promise.reject (e);
769 }));
770 }
771 } catch (e) {
772 console.error (e);
773 const errorMessage = e instanceof Error ? e.message : String(e);
774 FancyError.show ('engine:lifecycle:will_rollback_error', {
775 errorMessage: errorMessage
776 });
777 }
778
779 return Promise.all (promises).then ((...args) => {
780 engine.debug.groupEnd ();
781 return Promise.resolve (...args);
782 }).catch ((e) => {
783 engine.debug.groupEnd ();
784 return Promise.reject (e);
785 });
786}

Callers 1

rollbackFunction · 0.85

Calls 6

debugMethod · 0.80
componentsMethod · 0.80
actionsMethod · 0.45
willRollbackMethod · 0.45
showMethod · 0.45
allMethod · 0.45

Tested by

no test coverage detected