(engine: VisualNovelEngine)
| 501 | } |
| 502 | |
| 503 | export async function rollback (engine: VisualNovelEngine): Promise<void> { |
| 504 | const allowRollback = engine.setting ('AllowRollback') === true; |
| 505 | |
| 506 | if (!allowRollback) { |
| 507 | return; |
| 508 | } |
| 509 | |
| 510 | const stateObj = engine.state() as { step: number; label: string }; |
| 511 | |
| 512 | if (stateObj.step === 0) { |
| 513 | const jumpHistory = engine.history ('jump') as { destination: { label: string; step: number } }[]; |
| 514 | const jump = [...jumpHistory].reverse ().find (o => { |
| 515 | return o.destination.label === stateObj.label && o.destination.step === 0; |
| 516 | }); |
| 517 | |
| 518 | if (typeof jump === 'undefined') { |
| 519 | engine.debug.debug ('Will not attempt rollback since this is the beginning of the game.'); |
| 520 | return; |
| 521 | } |
| 522 | } |
| 523 | |
| 524 | await shouldRollback (engine); |
| 525 | |
| 526 | engine.global ('_engine_block', true); |
| 527 | |
| 528 | await willRollback (engine); |
| 529 | await engine.previous (); |
| 530 | } |
| 531 | |
| 532 | // ============================================================================ |
| 533 | // Proceed/Rollback Checks |
nothing calls this directly
no test coverage detected