Add layer field to animation | enable animation customization in runners
This commit is contained in:
@@ -25,4 +25,6 @@ public interface Animation extends Movable, Animated, Renderable, Updatable {
|
||||
void finish();
|
||||
|
||||
boolean finished();
|
||||
|
||||
Layer getLayer();
|
||||
}
|
||||
|
||||
@@ -289,6 +289,11 @@ public abstract class AnimationDelegate implements Animation {
|
||||
return animation.getFuture();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Layer getLayer() {
|
||||
return animation.getLayer();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(Screen screen, Camera camera, ShaderManager shaderManager) {
|
||||
animation.render(screen, camera, shaderManager);
|
||||
|
||||
@@ -36,6 +36,7 @@ public class BulletAnimationRunner implements AnimationRunner {
|
||||
private Path<Animation> path;
|
||||
private BiConsumer<Movable, Entity> onHit;
|
||||
private BiConsumer<Movable, Animation> onMiss;
|
||||
private Consumer<Animation> customizer;
|
||||
private float offsetX = 0;
|
||||
private float offsetY = 0;
|
||||
|
||||
@@ -126,6 +127,11 @@ public class BulletAnimationRunner implements AnimationRunner {
|
||||
return this;
|
||||
}
|
||||
|
||||
public BulletAnimationRunner customize(@NonNull Consumer<Animation> customizer) {
|
||||
this.customizer = customizer;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Void> run(Context context, Layer layer, Vector2fc origin) {
|
||||
var animation = new BulletAnimation(context.createAnimation(animationUid), delay, direction, null, onHit, onMiss);
|
||||
@@ -142,6 +148,10 @@ public class BulletAnimationRunner implements AnimationRunner {
|
||||
|
||||
layer.pushAnimation(animation);
|
||||
|
||||
if(customizer != null) {
|
||||
customizer.accept(animation);
|
||||
}
|
||||
|
||||
return animation.getFuture().thenApply(a -> null);
|
||||
}
|
||||
|
||||
@@ -161,6 +171,10 @@ public class BulletAnimationRunner implements AnimationRunner {
|
||||
|
||||
layer.pushAnimation(animation);
|
||||
|
||||
if(customizer != null) {
|
||||
customizer.accept(animation);
|
||||
}
|
||||
|
||||
return animation.getFuture().thenApply(a -> null);
|
||||
}
|
||||
|
||||
|
||||
@@ -4,16 +4,17 @@ import com.bartlomiejpluta.base.api.animation.Animation;
|
||||
import com.bartlomiejpluta.base.api.context.Context;
|
||||
import com.bartlomiejpluta.base.api.map.layer.base.Layer;
|
||||
import com.bartlomiejpluta.base.api.move.Movable;
|
||||
import lombok.NonNull;
|
||||
import org.apache.commons.math3.distribution.NormalDistribution;
|
||||
import org.apache.commons.math3.distribution.RealDistribution;
|
||||
import org.apache.commons.math3.distribution.UniformRealDistribution;
|
||||
import org.joml.Vector2fc;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.function.BiConsumer;
|
||||
|
||||
import static java.lang.Math.max;
|
||||
|
||||
@@ -41,6 +42,8 @@ public class RandomAnimationsRunner implements AnimationRunner {
|
||||
private float offsetX = 0;
|
||||
private float offsetY = 0;
|
||||
|
||||
private BiConsumer<Integer, Animation> customizer;
|
||||
|
||||
public RandomAnimationsRunner(int count) {
|
||||
this.count = max(count, 0);
|
||||
}
|
||||
@@ -132,6 +135,11 @@ public class RandomAnimationsRunner implements AnimationRunner {
|
||||
return this;
|
||||
}
|
||||
|
||||
public RandomAnimationsRunner customize(@NonNull BiConsumer<Integer, Animation> customizer) {
|
||||
this.customizer = customizer;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Void> run(Context context, Layer layer, Vector2fc origin) {
|
||||
var futures = new CompletableFuture[count];
|
||||
@@ -152,6 +160,10 @@ public class RandomAnimationsRunner implements AnimationRunner {
|
||||
|
||||
layer.pushAnimation(new DelayedAnimation(animation, (int) (delayDistribution != null ? delayDistribution.sample() : delay)));
|
||||
|
||||
if (customizer != null) {
|
||||
customizer.accept(i, animation);
|
||||
}
|
||||
|
||||
futures[i] = animation.getFuture();
|
||||
}
|
||||
|
||||
@@ -181,6 +193,10 @@ public class RandomAnimationsRunner implements AnimationRunner {
|
||||
|
||||
layer.pushAnimation(new DelayedAnimation(animation, (int) (delayDistribution != null ? delayDistribution.sample() : delay)));
|
||||
|
||||
if (customizer != null) {
|
||||
customizer.accept(i, animation);
|
||||
}
|
||||
|
||||
futures[i] = animation.getFuture();
|
||||
}
|
||||
|
||||
|
||||
@@ -5,9 +5,11 @@ import com.bartlomiejpluta.base.api.context.Context;
|
||||
import com.bartlomiejpluta.base.api.map.layer.base.Layer;
|
||||
import com.bartlomiejpluta.base.api.move.Movable;
|
||||
import com.bartlomiejpluta.base.util.path.Path;
|
||||
import lombok.NonNull;
|
||||
import org.joml.Vector2fc;
|
||||
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public class SimpleAnimationRunner implements AnimationRunner {
|
||||
private final String animationUid;
|
||||
@@ -24,6 +26,7 @@ public class SimpleAnimationRunner implements AnimationRunner {
|
||||
private boolean finishOnPathFail;
|
||||
private float offsetX = 0;
|
||||
private float offsetY = 0;
|
||||
private Consumer<Animation> customizer;
|
||||
|
||||
public SimpleAnimationRunner(String animationUid) {
|
||||
this.animationUid = animationUid;
|
||||
@@ -82,6 +85,11 @@ public class SimpleAnimationRunner implements AnimationRunner {
|
||||
return this;
|
||||
}
|
||||
|
||||
public SimpleAnimationRunner customize(@NonNull Consumer<Animation> customizer) {
|
||||
this.customizer = customizer;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Void> run(Context context, Layer layer, Vector2fc origin) {
|
||||
var animation = new DelayedAnimation(context.createAnimation(animationUid), delay);
|
||||
@@ -99,6 +107,11 @@ public class SimpleAnimationRunner implements AnimationRunner {
|
||||
}
|
||||
|
||||
layer.pushAnimation(animation);
|
||||
|
||||
if (customizer != null) {
|
||||
customizer.accept(animation);
|
||||
}
|
||||
|
||||
return animation.getFuture().thenApply(a -> null);
|
||||
}
|
||||
|
||||
@@ -120,6 +133,10 @@ public class SimpleAnimationRunner implements AnimationRunner {
|
||||
|
||||
layer.pushAnimation(animation);
|
||||
|
||||
if (customizer != null) {
|
||||
customizer.accept(animation);
|
||||
}
|
||||
|
||||
return animation.getFuture().thenApply(a -> null);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,6 +43,8 @@ public class DefaultAnimation extends MovableSprite implements Animation {
|
||||
private PathExecutor<Animation> pathExecutor = new PathExecutor<>(this);
|
||||
private boolean finishOnEnd;
|
||||
private boolean finishOnFail;
|
||||
|
||||
@Getter
|
||||
private Layer layer;
|
||||
private boolean isObjectLayer = false;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user