Well, I sure want to keep it simple.
But this doesn't quite answer my question. I know how to extract the name or the extension from the URL path. And how to later use that name to retrieve the concrete asset to use it somewhere.
But I'm trying to create a generic system here, a game framework, that can load, unload or verify the loaded status of a dynamic set of assets, based solely on a list of URLs.
I get a list of URLs, I load them all, that's fine. Now later I get another list of URLs and I want to ask:
- how many of these URLs are already loaded in my AssetManager and exist there as concrete assets?
- please unload the concrete assets that correspond to these URLs
Do you see my problem? In case of name collisions, you might have 2 assets with the same name but of different types, and at retrieval you must know which type you want to retrieve and I can determine that only based on the extension I read from the URL. So I need a way to map every URL to the corresponding concrete asset that comes out of it after loading.
Anyway, I can find a way to do it, I just wondered if this could be of interest for others too, such that the AssetsManager itself could be improved to support this use-case more easily.
Thanks for the input!
Thanks for the answer Daniel!
Yes, that's what I did so far, just that I'm having a bit of trouble with the texture atlases, since there I have 2 assets (the PNG/ATF and the XML), that fall into 2 separate categories/types, but have the same name. I will decide based on the extension, but as I said I can't easily reuse the extension information found in the factory classes for that purpose, so I have to hard-code it myself.
The fact that getNameFromUrl() is protected if fine for me at this time, as I'm actually extending your AssetManager, so I can access it in my custom subclass, but others might find it useful to have that method public, yes.
I did check the Asset Caching extension, it's super-awesome, in fact that's the whole purpose of switching to the new AssetManager for me. I'm doing this in Haxe actually, so I plan to port your extension to Haxe first, then use it for my game framework. I will try to contribute that port to https://github.com/openfl/starling when it's ready.
If you'll have ideas on how to trace back that URL from the final concrete asset, please let me know.