| 113 | } |
| 114 | |
| 115 | override async apply(): Promise<void> { |
| 116 | // show [character] [expression] at [position] with [animation] [infinite] |
| 117 | // 0 1 2 3 4 5 6 7 |
| 118 | |
| 119 | // show [character] [expression] with [animation] [infinite] |
| 120 | // 0 1 2 3 4 5 |
| 121 | |
| 122 | // show [character] [expression] |
| 123 | // 0 1 2 |
| 124 | |
| 125 | let directory = this.character.directory; |
| 126 | if (typeof directory == 'undefined') { |
| 127 | directory = ''; |
| 128 | } else { |
| 129 | directory += '/'; |
| 130 | } |
| 131 | |
| 132 | let oneSpriteOnly = true; |
| 133 | |
| 134 | const sprite = this.engine.element().find(`[data-character="${this.asset}"]:not([data-visibility="invisible"])`); |
| 135 | |
| 136 | const spriteEl = sprite.get(0); |
| 137 | if (sprite.exists() && spriteEl) { |
| 138 | const oldClasses = [...spriteEl.classList]; |
| 139 | |
| 140 | // Check if there is any end-animation, here's what this matches: |
| 141 | // 'end-fadeIn'.match (/end-([A-Za-z]+)/) => [ "end-fadeIn", "fadeIn" ] |
| 142 | const endAnimation = oldClasses.find((c: string) => c.match(/end-([A-Za-z]+)/) !== null); |
| 143 | |
| 144 | if (typeof endAnimation !== 'undefined') { |
| 145 | // If there was, get the animation-only part |
| 146 | const [end, animation] = endAnimation.split('-'); |
| 147 | const watchAnimation = oldClasses[oldClasses.indexOf(endAnimation) - 1]; |
| 148 | sprite.removeClass(watchAnimation); |
| 149 | sprite.addClass(animation); |
| 150 | sprite.data('visibility', 'invisible'); |
| 151 | sprite.on('animationend', (e: any) => { |
| 152 | e.target.remove(); |
| 153 | }); |
| 154 | |
| 155 | oneSpriteOnly = false; |
| 156 | } |
| 157 | |
| 158 | for (const oldClass of oldClasses) { |
| 159 | if (this.classes.indexOf(oldClass) === -1) { |
| 160 | sprite.removeClass(oldClass); |
| 161 | } |
| 162 | } |
| 163 | } |
| 164 | |
| 165 | const imgSrc = `${this.engine.setting('AssetsPath').root}/${this.engine.setting('AssetsPath').characters}/${directory}`; |
| 166 | const position = (this._statement as string).match(/at\s(\S*)/); |
| 167 | |
| 168 | if (oneSpriteOnly && sprite.exists()) { |
| 169 | |
| 170 | if (this.engine.setting('ExperimentalFeatures') === true) { |
| 171 | // If its another layered sprite |
| 172 | if (sprite.matches('character-sprite') && typeof this.image === 'object') { |