bevy_pkv icon indicating copy to clipboard operation
bevy_pkv copied to clipboard

Automatic resource tracking

Open wainwrightmark opened this issue 2 years ago • 3 comments

Hi. Thanks for making this plugin - it's unbelievably useful.

For my game I've built quite an ergonomic wrapper around it and I think might be worth adding something like it to this crate. Basically, you call app.init_tracked_resource<T>() for some Resource, and then that resource gets initialized with the value in the PkvStore and every time the resource changes, the store updates. You never need to use the PkvStore directly.

Happy to contribute code / examples / documentation if this is considered worth adding.

wainwrightmark avatar Jul 14 '23 12:07 wainwrightmark

@wainwrightmark any chance of sharing (part of) your implementation here for others to use, even if it isn't upstreamed into bevy_pkv?

JeanMertz avatar Dec 17 '24 13:12 JeanMertz

Yes sounds very useful. Happy to accept a pr if the implementation is clean. Sorry i forgot to respond to this

johanhelsing avatar Dec 17 '24 13:12 johanhelsing

Hi. I'm afraid I don't have a ton of time this week to write a PR but I might be able to soon.

If you want to use the code, I believe its all in these two files:

https://github.com/wainwrightmark/nice_bevy_utils/blob/main/src/lib.rs https://github.com/wainwrightmark/nice_bevy_utils/blob/main/src/tracked_resource.rs

Just looking at it now, it might also be worth adding:

  • A way to control which schedule the changes are tracked in (currently PostUpdate)
  • A way to handle store errors more gracefully
  • A derive macro for TrackableResource

wainwrightmark avatar Dec 19 '24 13:12 wainwrightmark