GitBrincie212 / Apel-Mod

Apel is a library that brings particle animations to the table with flexible behaviour and a clean developer interface. It promises also lots of predefined shapes & paths to help the developer on their particle scene
Other
2 stars 1 forks source link

Convert to object builders #39

Closed DarthSharkie closed 2 months ago

DarthSharkie commented 2 months ago

This provides the builder pattern for all ParticleObjects except ParticleImage. Circle and Cone were done as a preview for fully handling #35. The constructors become private, and the only method by which objects can be created is the static builder() method.

This does move to use setters everywhere when setting properties from within a constructor so we get the same validity checks in both constructors and changes from interceptors. That requires the setters called from constructors (and any further methods they call) that are public or protected to be made final so they cannot be overridden in a subclass and called before the subclass initializes.

Examples from the DebugParticleWand:

private ParticleCone getParticleCone() {
    DrawInterceptor<ParticleCone, ParticleCone.BeforeDrawData> beforeDraw = (data, obj) -> {
        obj.setRotation(obj.getRotation().add(0.01f, 0, 0));
        obj.setOffset(obj.getOffset().add(0, 0, 0.05f));
    };
    return ParticleCone.builder().particleEffect(ParticleTypes.CRIT).height(6f).radius(3f).amount(200)
                       .offset(new Vector3f(0, 10, 0)).beforeDraw(beforeDraw).build();
}

private @NotNull ParticleCircle getParticleCircle() {
    DrawInterceptor<ParticleCircle, ParticleCircle.BeforeDrawData> beforeDraw = (data, obj) -> obj.setOffset(
            new Vector3f(0, data.getCurrentStep() % 20 / 20f, (float) data.getCurrentStep() / 100));
    return ParticleCircle.builder().particleEffect(ParticleTypes.SOUL_FIRE_FLAME).radius(3f).amount(50)
                         .beforeDraw(beforeDraw).build();
}

Like the other one, let me know how this looks, and I can finish the conversion across all ParticleObjects. I do think it would make sense to do #30 before this one, so the beforeDraw and afterDraw interceptors move into the ParticleObject.Builder instead of being replicated about 16 times in our objects and require users to put them in their own Builder implementations.

This will also need a "How To: Create a new ParticleObject subclass" that explains the way these builders work so others can align with them. Ultimately, though, since they're owning their subclasses, Apel cannot control their precise implementations.

GitBrincie212 commented 2 months ago

Looks good

GitBrincie212 commented 2 months ago

Looks good to me

DarthSharkie commented 2 months ago

OK, will work on builder-izing the others. Thanks for the feedback!

DarthSharkie commented 2 months ago

Combiner and Image are yet to be done.

Docs still need to be moved/updated, too.

DarthSharkie commented 2 months ago

Code is done, I believe. I will hold off on dealing with ParticleImage -- it needs more than just a builder added.

Docs are still pending, will work on that next.