| 445 | } |
| 446 | |
| 447 | override async revert(): Promise<void> { |
| 448 | const experimentalFeatures = this.engine.setting('ExperimentalFeatures'); |
| 449 | this.engine.element().find(`[data-character="${this.asset}"]`).remove(); |
| 450 | |
| 451 | // First, we get the last instance of the character from the history as |
| 452 | // that's the one being currently displayed. |
| 453 | for (let i = this.engine.history('character').length - 1; i >= 0; i--) { |
| 454 | const { statement, previous } = this.engine.history('character')[i]; |
| 455 | const [show, character, asset, name] = statement.split(' '); |
| 456 | if (asset === this.asset) { |
| 457 | this.engine.history('character').splice(i, 1); |
| 458 | |
| 459 | if (experimentalFeatures) { |
| 460 | const characterLayerHistory = this.engine.history('characterLayer') as import('../lib/types').CharacterLayerHistoryItem[]; |
| 461 | if (typeof previous !== 'undefined' && previous !== null) { |
| 462 | let previousLayers; |
| 463 | for (let j = characterLayerHistory.length - 1; j >= 0; j--) { |
| 464 | const { parent } = characterLayerHistory[j]; |
| 465 | if (typeof parent === 'string') { |
| 466 | const [, , _asset] = parent.split(' '); |
| 467 | |
| 468 | if (_asset === this.asset) { |
| 469 | previousLayers = characterLayerHistory[j]; |
| 470 | break; |
| 471 | } |
| 472 | } |
| 473 | } |
| 474 | |
| 475 | |
| 476 | const action = this.engine.prepareAction(previous, { cycle: 'Application', extras: { layerHistory: previousLayers } }) as ActionInstance | null; |
| 477 | if (action !== null) { |
| 478 | await action.apply(); |
| 479 | await action.didApply({ updateHistory: false, updateState: true }); |
| 480 | } |
| 481 | |
| 482 | for (let j = characterLayerHistory.length - 1; j >= 0; j--) { |
| 483 | const { parent } = characterLayerHistory[j]; |
| 484 | if (typeof parent === 'string') { |
| 485 | const [, , _asset] = parent.split(' '); |
| 486 | |
| 487 | if (_asset === this.asset) { |
| 488 | characterLayerHistory.splice(j, 1); |
| 489 | break; |
| 490 | } |
| 491 | } |
| 492 | } |
| 493 | return; |
| 494 | } else { |
| 495 | for (let j = characterLayerHistory.length - 1; j >= 0; j--) { |
| 496 | const { parent } = characterLayerHistory[j]; |
| 497 | if (typeof parent === 'string') { |
| 498 | const [, , _asset] = parent.split(' '); |
| 499 | |
| 500 | if (_asset === this.asset) { |
| 501 | characterLayerHistory.splice(j, 1); |
| 502 | break; |
| 503 | } |
| 504 | } |