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

Support ron format maps as assets #180

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

MickHarrigan
Copy link

This is a Frankenstein way to force functionality with maps in ron to work with this library. This is due to #179.

Given what I needed this to be able to do it does that with only a minor modification required on the user side.
That change is wrapping the {} in () first, but this may be able to be worked around as well.

Feel free to touch up or change anything within this, its very far from being published or merged as it is just a proof of concept for now.

@MickHarrigan
Copy link
Author

Did more digging with this and with serde as a whole and from what I have been able to hack together, this isn't particularly easy to implement.

I did some testing with just serde and was only able to get a format that fit my needs partially. With just serde I was able to implement ron maps, lists, and regular structs as deserializable into

#[derive(Serialize, Deserialize, Debug)]
#[serde(untagged)]
enum Types {
    // individual types
    Image { path: String },
    Square { length: f32 },
    Sphere { radius: f32 },
    Data { data: String },
    Blank,

    // types for collections
    Map(HashMap<String, Types>),
    Vector(Vec<Types>),
}

This is so close to what I want, but I have been unable to get the conversion from just serde to everything that bevy_asset_loader requires. Even still, this format doesn't deserialize from exactly what I want (Which is that all the individual types are explicitly written in ron, but the map and vector are implied when deserialized).

Other than that issue, the code that I currently have provided on this PR has the issue that there are handles to each individual asset, as well as from the top level to the collection of lower assets. This means that having the top level does nothing but add complexity and useless bloat.

If somehow there is a way to get this to work such that the data can be defined in n levels of nested maps/arrays without having to directly specify them as such with a name, but leaving all the actual data fields to have it, that would be perfect. But until that comes I think this should at best be left at an idea and a draft if not closed altogether.

@NiklasEi
Copy link
Owner

I think you would need to split the tagged and untagged variants into different enums. In #151, untagged vectors are implemented using the latest main branch from ron.

@MickHarrigan
Copy link
Author

I think you would need to split the tagged and untagged variants into different enums. In #151, untagged vectors are implemented using the latest main branch from ron.

Wow, not sure how I completely missed that branch and issue. I did a bit of messing with it and I did get a very very simple example working how I expected to have it work. I will keep working on it until I feel that it is of a good enough caliber to contribute to the branch anyways.

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.

2 participants