* start the SO main loop * @ignore
(stateId: number)
| 173 | * @ignore |
| 174 | */ |
| 175 | function _switchState(stateId: number): void { |
| 176 | // clear previous interval if any |
| 177 | _stopRunLoop(); |
| 178 | |
| 179 | // call the stage destroy method |
| 180 | // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition |
| 181 | if (_stages[_state]) { |
| 182 | _stages[_state].stage.destroy(_app); |
| 183 | } |
| 184 | |
| 185 | // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition |
| 186 | if (_stages[stateId]) { |
| 187 | // set the global variable |
| 188 | _state = stateId; |
| 189 | |
| 190 | // call the reset function with the app reference and any extra args |
| 191 | if (_extraArgs) { |
| 192 | _stages[_state].stage.reset(_app, ..._extraArgs); |
| 193 | } else { |
| 194 | _stages[_state].stage.reset(_app); |
| 195 | } |
| 196 | |
| 197 | // and start the main loop of the |
| 198 | // new requested state |
| 199 | _startRunLoop(); |
| 200 | |
| 201 | // publish the pause event |
| 202 | emit(STATE_CHANGE); |
| 203 | |
| 204 | // execute callback if defined |
| 205 | if (_onSwitchComplete) { |
| 206 | _onSwitchComplete(); |
| 207 | _onSwitchComplete = null; |
| 208 | } |
| 209 | } |
| 210 | } |
| 211 | |
| 212 | // the active application instance |
| 213 | let _app: Application; |
no test coverage detected