fishfolk / bones

An easy-to-use game engine for making real games.
https://fishfolk.org/development/bones/introduction/
Other
210 stars 20 forks source link

feat: single & first entity queries #386

Closed nelson137 closed 1 month ago

nelson137 commented 4 months ago

Closes #289.

Changes

Summary

Add convenience methods to get a single entity (and optionally its components) when there should only be one of the thing you're looking for. This could be useful, for example, to check if there is only one player alive in the game. You could use Entities::get_single_with which would allow you to detect when there is only one player (Ok) or when there are none/multiple (Err).

All methods have a panicking and non-panicking variant -- e.g. get_single_with returns a Result<_, QuerySingleError>, while single_with panics if the return value would not be Ok. The *first_with* methods either return an Option or panic.

MaxCWhitehead commented 1 month ago

Merged this but I think there may have been a conflict or something that caused CI to fail in main - I couldn't for the life of me figure out how to re-run CI for some reason (possibly because it was cancelled on hung Miri last time).

Anywho sorry for the chaos - reverted in main, I will re-open this PR once I figure out best way to do that / fix and merge.

MaxCWhitehead commented 1 month ago

@nelson137 seems I can't revert/re-open merged PR, if you want to re-open a new PR from your branch so you get attributed with commit I can handle the rest, otherwise I'll go ahead and re-open. Sorry about that.