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

Method didApply

src/actions/ShowCharacterLayer.ts:236–305  ·  view source on GitHub ↗
({ updateHistory = true, updateState = true } = {})

Source from the content-addressed store, hash-verified

234 }
235
236 override async didApply({ updateHistory = true, updateState = true } = {}): Promise<ActionApplyResult> {
237 if (updateHistory === true) {
238 const characterLayerHistory = this.engine.history('characterLayer') as CharacterLayerHistoryItem[];
239 let previousHistory: CharacterLayerHistoryItem | undefined;
240 for (let j = characterLayerHistory.length - 1; j >= 0; j--) {
241 const historyItem = characterLayerHistory[j];
242 if (historyItem.parent) {
243 const [, , _asset] = historyItem.parent.split(' ');
244
245 if (_asset === this.asset) {
246 previousHistory = historyItem;
247 break;
248 }
249 }
250 }
251
252 const parent = this.engine.state('characters').find((s: string) => {
253 const [, , asset] = s.split(' ');
254 return asset === this.asset;
255 }) || null;
256
257 if (typeof previousHistory !== 'undefined') {
258 characterLayerHistory.push({
259 parent,
260 layers: [
261 ...previousHistory.layers.filter(({ statement }: { statement: string | null; previous: string | null }) => {
262 if (statement !== null && parent !== null) {
263 const [, , _asset] = parent.split(' ');
264 const [_identifier, _layer] = _asset.split(':');
265 return _identifier !== this.asset && _layer !== this.layer;
266 }
267 return false;
268 }),
269 {
270 statement: this._statement as string,
271 previous: this.state || null
272 }
273 ]
274 });
275 } else {
276 characterLayerHistory.push({
277 parent,
278 layers: [
279 {
280 statement: this._statement as string,
281 previous: this.state || null
282 }
283 ]
284 });
285 }
286
287 }
288
289 if (updateState === true) {
290 this.engine.state({
291 characterLayers: [
292 ...this.engine.state('characterLayers').filter((item: any) => {
293 if (typeof item === 'string') {

Callers 2

onLoadMethod · 0.45
revertMethod · 0.45

Calls 2

historyMethod · 0.80
stateMethod · 0.80

Tested by

no test coverage detected