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

Inputs serialization #620

Open
Shatur opened this issue Sep 9, 2024 · 3 comments
Open

Inputs serialization #620

Shatur opened this issue Sep 9, 2024 · 3 comments
Labels
enhancement New feature or request
Milestone

Comments

@Shatur
Copy link
Collaborator

Shatur commented Sep 9, 2024

What problem does this solve?

I would like to be able to serialize inputs to a config file and deserialize it back. But there are a 2 problems:

  1. Boxes can't be serialized / deserialized without additional effort.
  2. All insertion methods on InputMap accept concrete type, not a fat pointer.

What solution would you like?

Not exactly sure how to solve this...

For 1 we can use something like https://github.com/dtolnay/erased-serde, but it require a separate crate for such a common use case is not very nice. It's also possible to use Bevy's reflection. But it requires manual ser/de implementation for user which is hard to write.
For 2 we can accept Into<Box<dyn Trait>> since all methods internally do Box::new.

[Optional] What alternatives have you considered?

Maybe using traits wasn't the right call... Maybe we could have better enums? Like keep all insert, insert_axislike etc., but use enums instead of boxes.

Related work

Caused by #534.

@Shatur Shatur added the enhancement New feature or request label Sep 9, 2024
@alice-i-cecile alice-i-cecile added this to the 0.15.2 milestone Sep 9, 2024
@Shatur
Copy link
Collaborator Author

Shatur commented Sep 9, 2024

Looks like the crate already uses https://github.com/Gohla/serde_flexitos, we just need include an example for it.

@alice-i-cecile
Copy link
Contributor

Adding a generic insert_boxed method to InputMap is an easy PR, and something I'm firmly in favor of.

@Shatur
Copy link
Collaborator Author

Shatur commented Sep 10, 2024

Another option would be consider enum dispatch. I.e. keep all the separation like Buttonlike, Axislike, but make them enums.

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

No branches or pull requests

2 participants