Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow custom deserialization of ldtk files #304

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

StratusFearMe21
Copy link

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.

@Trouv
Copy link
Owner

Trouv commented Mar 27, 2024

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?

@StratusFearMe21
Copy link
Author

StratusFearMe21 commented Apr 4, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants