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

Method revert

src/actions/HideCharacterLayer.ts:135–165  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

133 }
134
135 override async revert(): Promise<void> {
136 for (let i = this.engine.history('characterLayer').length - 1; i >= 0; i--) {
137 const { parent, layers } = this.engine.history('characterLayer')[i];
138 const historyStatement = layers.find((s: any) => {
139 const { previous, statement } = s;
140 const [show, character, asset, name] = (statement || previous).split(' ');
141 const [id, layer] = asset.split(':');
142
143 return id === this.asset && layer === this.layer;
144 });
145
146 if (typeof historyStatement === 'object' && historyStatement !== null) {
147 const { statement, previous } = historyStatement as { statement: string | null; previous: string | null };
148 const [, , asset] = ((statement || previous) ?? '').split(' ');
149 const [id, layer] = asset?.split(':') ?? [];
150
151 if (id === this.asset && layer === this.layer) {
152 if (statement === null) {
153 return;
154 }
155 const revertAction = this.engine.prepareAction(statement, { cycle: 'Application' }) as ActionInstance | null;
156 if (revertAction !== null) {
157 await revertAction.apply();
158 await revertAction.didApply({ updateHistory: false, updateState: true });
159 }
160 return;
161 }
162 }
163 }
164 throw new Error('Failed to revert HideCharacterLayer');
165 }
166
167 override async didRevert(): Promise<ActionRevertResult> {
168 return { advance: true, step: true };

Callers

nothing calls this directly

Calls 4

historyMethod · 0.80
prepareActionMethod · 0.80
applyMethod · 0.45
didApplyMethod · 0.45

Tested by

no test coverage detected