bevy_ecs_ldtk icon indicating copy to clipboard operation
bevy_ecs_ldtk copied to clipboard

Allow custom deserialization of ldtk files

Open StratusFearMe21 opened this issue 1 year ago • 2 comments

This PR makes it possible to load Ldtk files that you have preprocessed, for example by re-serializing the file using bincode and compressing it.

StratusFearMe21 avatar Feb 23 '24 18:02 StratusFearMe21

So this seems to me like it would actually be a good use-case for bevy's relatively new asset preprocessing features. I'm not an expert on it but I think basically what could work for this plugin is a new asset settings type. something like...

enum LdtkProjectFormat {
    Json,
    Bincode,
}

struct LdtkProjectLoaderSettings {
    format: LdtkProjectFormat
}

Then that would be the associated Settings type in LdtkProjectLoader's AssetLoader implementation.

Then we could write an AssetSaver implementation for some new type like LdtkProjectBincodeSaver, with associated types Asset = LdtkProject, OutputLoader = LdtkProjectLoader. It would write the bincode formatted bytes and return Ok(LdtkProjectLoaderSettings { format: LdtkProjecFormat::Bincode }). Then we register it as a preprocessor and bevy will transform the source json in assets/ to bincode bytes in imported_assets/ automatically if processed assets are enabled.

At least, I think that's the necessary steps to implementing a custom pre-processor. It seems like being able to use an enum of formats in a Settings type would be a good starting point at least that doesn't necessarily require the AssetSaver stuff. Thoughts?

Trouv avatar Mar 27 '24 06:03 Trouv

Ooooo. I like that idea! Instead of an enum tho, could you pass a function pointer to the LdtkProjectLoaderSettings? Something like fn(Vec<u8>) -> LdtkJson? That way any deserializer could work with this plugin

StratusFearMe21 avatar Apr 04 '24 11:04 StratusFearMe21