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

Method apply

src/actions/ShowCharacterLayer.ts:122–234  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

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

Callers 2

onLoadMethod · 0.45
revertMethod · 0.45

Calls 7

globalMethod · 0.80
matchMethod · 0.80
settingMethod · 0.80
getMethod · 0.65
onMethod · 0.65
removeMethod · 0.65
elementMethod · 0.45

Tested by

no test coverage detected