Create CompletableFutureSegment move path segment
This commit is contained in:
@@ -6,7 +6,9 @@ import lombok.Getter;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public class BasePath<T extends Movable> implements Path<T> {
|
||||
|
||||
@@ -47,4 +49,9 @@ public class BasePath<T extends Movable> implements Path<T> {
|
||||
path.add(new SuspendSegment<>(predicate));
|
||||
return this;
|
||||
}
|
||||
|
||||
public Path<T> suspend(Supplier<CompletableFuture<?>> future) {
|
||||
path.add(new CompletableFutureSegment<>(future));
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,7 +6,9 @@ import lombok.Getter;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public class CharacterPath<T extends Character> implements Path<T> {
|
||||
|
||||
@@ -57,4 +59,9 @@ public class CharacterPath<T extends Character> implements Path<T> {
|
||||
path.add(new SuspendSegment<>(predicate));
|
||||
return this;
|
||||
}
|
||||
|
||||
public CharacterPath<T> suspend(Supplier<CompletableFuture<?>> future) {
|
||||
path.add(new CompletableFutureSegment<>(future));
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
package com.bartlomiejpluta.base.util.path;
|
||||
|
||||
import com.bartlomiejpluta.base.api.map.layer.object.ObjectLayer;
|
||||
import com.bartlomiejpluta.base.api.move.Movable;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
@RequiredArgsConstructor
|
||||
public class CompletableFutureSegment<T extends Movable> implements PathSegment<T> {
|
||||
private final Supplier<CompletableFuture<?>> futureSupplier;
|
||||
|
||||
@Override
|
||||
public PathProgress perform(T movable, ObjectLayer layer, float dt) {
|
||||
var future = futureSupplier.get();
|
||||
|
||||
if (future.isCancelled() || future.isCompletedExceptionally()) {
|
||||
return PathProgress.SEGMENT_FAILED;
|
||||
}
|
||||
|
||||
if (future.isDone()) {
|
||||
return PathProgress.SEGMENT_DONE;
|
||||
}
|
||||
|
||||
return PathProgress.ONGOING;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user