(engine: VisualNovelEngine)
| 109 | // ============================================================================ |
| 110 | |
| 111 | export function resetGame (engine: VisualNovelEngine): Promise<unknown[]> { |
| 112 | // Stop autoplay |
| 113 | engine.autoPlay (false); |
| 114 | |
| 115 | const skipSetting = engine.setting ('Skip'); |
| 116 | |
| 117 | if (skipSetting > 0) { |
| 118 | engine.skip (false); |
| 119 | } |
| 120 | |
| 121 | // Reset Storage |
| 122 | const storageStructure = engine.global ('storageStructure'); |
| 123 | |
| 124 | engine.storage (JSON.parse(storageStructure)); |
| 125 | |
| 126 | // Reset Conditions |
| 127 | engine.state ({ |
| 128 | step: 0, |
| 129 | label: engine.setting ('Label') |
| 130 | }); |
| 131 | |
| 132 | engine.global ('block', false); |
| 133 | |
| 134 | // Reset History |
| 135 | for (const history of Object.keys (engine._history)) { |
| 136 | engine._history[history] = []; |
| 137 | } |
| 138 | |
| 139 | // Run the reset method of all the actions so each of them can reset |
| 140 | // their own elements correctly |
| 141 | const promises: Promise<unknown>[] = []; |
| 142 | |
| 143 | for (const action of engine.actions ()) { |
| 144 | promises.push (action.reset ()); |
| 145 | } |
| 146 | |
| 147 | for (const component of engine.components ()) { |
| 148 | promises.push (component.onReset ()); |
| 149 | } |
| 150 | |
| 151 | return Promise.all (promises); |
| 152 | } |
| 153 | |
| 154 | // ============================================================================ |
| 155 | // Upgrade |
no test coverage detected