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

Method apply

src/actions/ShowCharacter.ts:115–338  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

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') {

Callers 2

onLoadMethod · 0.45
revertMethod · 0.45

Calls 7

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

Tested by

no test coverage detected