Skip to content

Allow custom deserialization of ldtk files - #304

Open
StratusFearMe21 wants to merge 1 commit into
Trouv:mainfrom
StratusFearMe21:main
Open

Allow custom deserialization of ldtk files#304
StratusFearMe21 wants to merge 1 commit into
Trouv:mainfrom
StratusFearMe21:main

Conversation

@StratusFearMe21

Copy link
Copy Markdown

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

Trouv commented Mar 27, 2024

Copy link
Copy Markdown
Owner

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

StratusFearMe21 commented Apr 4, 2024

Copy link
Copy Markdown
Author

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

@Trouv Trouv added A-Asset Area: regarding assets and asset loaders added by this plugin D-Modest Difficulty: new features, refactors, and challenging bug fixes. C-Feature Category: a new feature, making something new possible. S-Needs-Review Status: this PR needs reviewer attention to move forward. labels Nov 27, 2025
@Trouv

Trouv commented Nov 27, 2025

Copy link
Copy Markdown
Owner

Potentially related to #334

@Trouv

Trouv commented Jan 4, 2026

Copy link
Copy Markdown
Owner

Hi @StratusFearMe21, sorry for taking so long to return to you here. Are you still interested in this?

To be honest, I'm a little hesitant. It's a simple enough change, but it doesn't feel to me that many users are interested in changing their data format. I was thinking about the best way to support this with preprocessing, but either way it gets complicated to support in an official capacity with the existence of external levels. We'd want to save the bincodified external level files to a different location, but that breaks the paths to external levels specified in the LDtk project file.

@Trouv Trouv added S-Waiting-On-Author Status: the author needs to make changes to this PR before it can be approved. and removed S-Needs-Review Status: this PR needs reviewer attention to move forward. labels Jan 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-Asset Area: regarding assets and asset loaders added by this plugin C-Feature Category: a new feature, making something new possible. D-Modest Difficulty: new features, refactors, and challenging bug fixes. S-Waiting-On-Author Status: the author needs to make changes to this PR before it can be approved.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants