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

Method revert

src/actions/ShowCharacter.ts:447–550  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

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 }

Callers

nothing calls this directly

Calls 8

settingMethod · 0.80
historyMethod · 0.80
prepareActionMethod · 0.80
stateMethod · 0.80
removeMethod · 0.65
elementMethod · 0.45
applyMethod · 0.45
didApplyMethod · 0.45

Tested by

no test coverage detected