Suggestion of adding ed.removeComponents()

Hi

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.

1 Like
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.

1 Like