| 338 | } |
| 339 | |
| 340 | override async didApply({ updateHistory = true, updateState = true } = {}): Promise<ActionApplyResult> { |
| 341 | const experimentalFeatures = this.engine.setting('ExperimentalFeatures') === true; |
| 342 | if (updateHistory === true) { |
| 343 | const characterHistory = this.engine.history('character') as CharacterHistoryItem[]; |
| 344 | characterHistory.push({ |
| 345 | statement: this._statement as string, |
| 346 | previous: this.state || null |
| 347 | }); |
| 348 | |
| 349 | if (experimentalFeatures) { |
| 350 | const characterLayerHistory = this.engine.history('characterLayer') as import('../lib/types').CharacterLayerHistoryItem[]; |
| 351 | if (typeof this.image === 'object') { |
| 352 | const statements: { statement: string; previous: string | null }[] = []; |
| 353 | for (const layer in this.image) { |
| 354 | const previous = this.engine.state('characterLayers').find((statement: string) => { |
| 355 | const [, , asset] = statement.split(' '); |
| 356 | const [_identifier, _layer] = asset.split(':'); |
| 357 | return _identifier === this.asset && _layer == layer; |
| 358 | }) as string | undefined; |
| 359 | |
| 360 | statements.push({ |
| 361 | statement: `show character ${this.asset}:${layer} ${(this.image as Record<string, string>)[layer]}`, |
| 362 | previous: previous || null |
| 363 | }); |
| 364 | } |
| 365 | |
| 366 | characterLayerHistory.push({ |
| 367 | parent: this._statement as string, |
| 368 | layers: statements |
| 369 | }); |
| 370 | } else { |
| 371 | characterLayerHistory.push({ |
| 372 | parent: this._statement as string, |
| 373 | layers: this.engine.state('characterLayers').map((s: any) => { |
| 374 | return { |
| 375 | statement: null, |
| 376 | previous: s |
| 377 | }; |
| 378 | }) |
| 379 | }); |
| 380 | } |
| 381 | } |
| 382 | } |
| 383 | |
| 384 | if (updateState === true) { |
| 385 | this.engine.state({ |
| 386 | characters: [ |
| 387 | ...this.engine.state('characters').filter((item: any) => { |
| 388 | if (typeof item === 'string') { |
| 389 | const [, , asset] = item.split(' '); |
| 390 | return asset !== this.asset; |
| 391 | } |
| 392 | return false; |
| 393 | }), |
| 394 | this._statement as string |
| 395 | ] |
| 396 | }); |
| 397 | |