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

Method apply

src/actions/ShowImage.ts:68–110  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

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

Callers 1

onLoadMethod · 0.45

Calls 4

matchMethod · 0.80
imageCacheMethod · 0.80
settingMethod · 0.80
elementMethod · 0.45

Tested by

no test coverage detected