MCPcopy Create free account
hub / github.com/melonjs/melonJS / get

Method get

packages/melonjs/src/video/texture/cache.js:166–206  ·  view source on GitHub ↗

* @ignore * return the textureAltas for the given image

(image, atlas)

Source from the content-addressed store, hash-verified

164 * return the textureAltas for the given image
165 */
166 get(image, atlas) {
167 let entry = this.cache.get(image)[0];
168
169 if (typeof entry !== "undefined" && typeof atlas !== "undefined") {
170 this.cache.forEach((value, key) => {
171 const _atlas = value.getAtlas();
172 if (
173 key === image &&
174 _atlas.width === atlas.framewidth &&
175 _atlas.height === atlas.frameheight
176 ) {
177 entry = value;
178 }
179 });
180 }
181
182 if (typeof entry === "undefined") {
183 if (!atlas) {
184 atlas = createAtlas(
185 image.width || image.videoWidth,
186 image.height || image.videoHeight,
187 image.src ? getBasename(image.src) : undefined,
188 );
189 }
190 entry = new TextureAtlas(atlas, image, false);
191 this.set(image, entry);
192 }
193
194 // "activate" the corresponding sources (in case of multi texture atlas)
195 if (typeof entry.sources !== "undefined" && entry.sources.size > 1) {
196 // manage cases where a specific atlas is specified
197 for (const [key, value] of entry.sources.entries()) {
198 // Check if the imageData matches the provided image
199 if (value === image) {
200 entry.activeAtlas = key;
201 }
202 }
203 }
204
205 return entry;
206 }
207
208 /**
209 * @ignore

Callers

nothing calls this directly

Calls 6

setMethod · 0.95
createAtlasFunction · 0.90
getBasenameFunction · 0.90
getAtlasMethod · 0.80
getMethod · 0.65
forEachMethod · 0.45

Tested by

no test coverage detected