Open devnev opened 10 months ago
I guess that would fit here, yes. But in my opinion, typed assets should be the way to go in most cases.
With Bevy 0.13, asset loaders no longer are picked for loading a certain asset purely on their extensions. You could register the loader without an extension and then load like so:
let toml_doc: Handle<TomlAsset> = asset_server.load("my_toml_settings.toml");
That would at least prevent any conflicts of the generic loader with other asset loaders.
I will add to this that untyped assets are on rare occasions needed. I've just hand written one for toml for myself, but i think it might be useful for others. In my case, combining untyped values with serde-toml-merge is great for modding in games where mods might need to override files based on load order. I'm sure there's other usages too.
TL;DR
Could this repository include a common asset type and loader for loading generic
serde_json::Value
,toml_edit::Document
, etc. types from files with the generic format extension like.json
/.toml
rather than a specific extension?Background
I built something closely related to this for loading plugin settings from specific configuration files: https://github.com/devnev/bevy_settings_loader
But in my plugin, the settings are resource singletons and not identified by file extensions but by the full path to the file. So I add a generic
.json
/.toml
loader and then deserialise from the loaded value into the destination type for the asset matching the settings path.For that I've added generic
JsonAsset
andTomlAsset
types that wrapserde_json::Value
andtoml_edit::Document
loaded from arbitrary files with the corresponding extension. However, my repository/package/plugin is too specific for something that generic, whereas this repository seems more suitable and has most of the code for it already.The main missing pieces is a wrapper implementing
Asset
forserde_json::Value
etc, which would allow other plugins to avoid duplicate registration of loaders for the corresponding extension.