It would be nice to add
EntityData.removeComponents(EntityId entityId, Class<T>... types) for ease of removing multiple components at once in Zay-ES.
Currently, I am doing something like:
Stream.of(ComponentA.class, ComponentB.class, ComponentC.class)
.forEach(component -> ed.removeComponent(eId, component));
I submitted a PR
@pspeed I would like to hear your opinion
It seems fine. I haven’t really had a chance to look at it yet.
…it’s just a convenience method, right? (No special complications in the implementation I assume.)
Edit: just looked… I prefer not to hide code in interfaces. It’s one thing when the method does basically nothing but this is real code. I’ll keep this discussion on the PR, though. Sorry.
Applied the requested changes.
public void removeComponents( EntityId entityId, Class<? extends EntityComponent>... types );
IDE shows an “Unchecked generics array creation for varargs parameter” hint when using ed.removeComponents().
Appears that I can not add
@SafeVarargs on interface method.
Do I need to do something about it?
This is a pain with generics. Isn’t there a similar setComponents() method? Does it have a similar issue or did I resolve it somehow?
It does not have this issue because it does not use generics
public void setComponents( EntityId entityId, EntityComponent... components );
Ah, so one approach would be just to take naked Class and cast internally… let the class cast exception bubble out.
I don’t know how I feel about that but generics leaves little good choice in this case… and at least this gets rid of the warnings for every caller.
Yeah, seems you are also doing this for other methods:
Updated PR to use the naked class as you suggested and this fixed the warning.
I think it is now ready to be merged.