Open viridia opened 8 months ago
I ran into this recently when I wanted to use configuration or manifest-style files as assets. The use case would loosely be: if the file doesn't exist, create one. I'm using custom AssetLoader
s, but I would never be able to handle the case of something like std::io::ErrorKind::NotFound
because we fail before things even get to the loader.
What problem does this solve or what need does it fill?
I'd like a way to suppress the error when an asset file is not found. Two example use cases:
What solution would you like?
This could be a feature of the AssetLoader trait. One idea is to have a new method called
load_default()
which is called when the asset is not found - the default implementation would be to return an error. Users could then override this method to return a default version of the asset. Note that we have to return something, as the API for loading assets doesn't allow a handle to point to nothing. It would be up to the user to include a flag or property within the default asset to indicate that this is a missing asset.Another approach would be to have a special error code that indicates that the asset is not there, but the normal error message should be suppressed.
What alternative(s) have you considered?
One alternative is to scan the folder and check all the asset names, but this is expensive, especially if you are writing assets during play.