Get the cached texture by its key, or load from a file path and cache it.
(&mut self, path: &'static str)
| 320 | |
| 321 | /// Get the cached texture by its key, or load from a file path and cache it. |
| 322 | pub async fn get_or_load(&mut self, path: &'static str) -> &Texture2D { |
| 323 | if !self.textures.contains_key(path) { |
| 324 | let texture = load_texture(resolve_asset_path(path)).await.unwrap(); |
| 325 | self.textures.insert(path.to_owned(), CacheEntry { frames_not_used: 0, owner: texture.into() }); |
| 326 | } |
| 327 | let entry = self.textures.get_mut(path).unwrap(); |
| 328 | entry.frames_not_used = 0; |
| 329 | entry.owner.texture() |
| 330 | } |
| 331 | |
| 332 | /// Get the cached texture by its key, or create it using the provided function and cache it. |
| 333 | pub fn get_or_create<F>(&mut self, key: String, create_fn: F) -> &Texture2D |
no test coverage detected