merwaaan / bevy_spritesheet_animation

A Bevy plugin for animating sprites that are backed by spritesheets
MIT License
55 stars 3 forks source link

Add a method to get the name of the animation/clip/marker #18

Open mirsella opened 2 hours ago

mirsella commented 2 hours ago

Hello !

Something like get_name_from_animation(&self, animation_id: &AnimationId) -> Option<String> ?

I can do a pr with these changes if you find this to be useful

the code would just be

self
.animation_name_lookup
.iter()
.find_map(|(k, v)| if v == animation_id { Some(k) } else { None })

(find_map return an Option<String>)

merwaaan commented 2 hours ago

I think that we laready have that :)

https://github.com/merwaaan/bevy_spritesheet_animation/blob/32b23fb8f9f9496de03d9d01c1bc1e7d23e3d6d9/src/library.rs#L302

(same for clips and markers)

mirsella commented 2 hours ago

yeah my bad i confused my self lmao, i edited the title and message...

merwaaan commented 2 hours ago

Sure, I'd gladly accept a PR!

Now that I'm thinking about it, an animation/clip/marker can currently have multiple names. You can call name_XXX() multiple times with different names, and each name will reference the same item.

This means that with the current state of things, a get_animation/clip/marker_name() API should return a list of names.

BUT in practice I don't see any real use-case for having multiple names so this PR might be a good time to simplify everything, replace the current name instead of adding a new one when calling name_XXX(), and having get_XXX_name() return just an Option, as you suggested.

mirsella commented 1 hour ago

so:

but i don't think there are any gains on limiting the animation/marker/clip to have only one name, but only restrict the possibilities of this crate ?