()
| 66 | } |
| 67 | |
| 68 | override async apply(): Promise<void> { |
| 69 | const position = (this._statement as string).match(/at\s(\S*)/); |
| 70 | |
| 71 | // Check if image is cached |
| 72 | const cacheKey = `images/${this.asset}`; |
| 73 | const cachedImage = this.engine.imageCache(cacheKey); |
| 74 | |
| 75 | let image: HTMLImageElement; |
| 76 | if (cachedImage) { |
| 77 | // Clone the cached image element |
| 78 | image = cachedImage.cloneNode(true) as HTMLImageElement; |
| 79 | } else { |
| 80 | // Create new image element |
| 81 | image = document.createElement('img'); |
| 82 | $_(image).attribute('src', `${this.engine.setting('AssetsPath').root}/${this.engine.setting('AssetsPath').images}/${this.image}`); |
| 83 | } |
| 84 | |
| 85 | $_(image).addClass('animated'); |
| 86 | $_(image).data('image', this.asset); |
| 87 | |
| 88 | for (const className of this.classes) { |
| 89 | if (className) { |
| 90 | $_(image).addClass(className); |
| 91 | } |
| 92 | } |
| 93 | |
| 94 | if (position instanceof Array) { |
| 95 | // If it was, we'll set that position to the character |
| 96 | const [at, positionClass] = position; |
| 97 | $_(image).data('position', positionClass); |
| 98 | } else { |
| 99 | $_(image).addClass('center'); |
| 100 | $_(image).data('position', 'center'); |
| 101 | } |
| 102 | |
| 103 | const durationPosition = this.classes.indexOf('duration'); |
| 104 | |
| 105 | if (durationPosition > -1) { |
| 106 | $_(image).style('animation-duration', this.classes[durationPosition + 1]); |
| 107 | } |
| 108 | |
| 109 | this.engine.element().find('[data-screen="game"] [data-content="visuals"]').append(image.outerHTML); |
| 110 | } |
| 111 | |
| 112 | override async didApply({ updateHistory = true, updateState = true } = {}): Promise<ActionApplyResult> { |
| 113 | if (updateHistory === true) { |
no test coverage detected