Create Suspend move path segment
This commit is contained in:
@@ -6,6 +6,7 @@ import lombok.Getter;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
public class BasePath<T extends Movable> implements Path<T> {
|
||||
|
||||
@@ -41,4 +42,9 @@ public class BasePath<T extends Movable> implements Path<T> {
|
||||
path.add(new RunSegment<>(runnable));
|
||||
return this;
|
||||
}
|
||||
|
||||
public Path<T> suspend(Predicate<T> predicate) {
|
||||
path.add(new SuspendSegment<>(predicate));
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import lombok.Getter;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
public class CharacterPath<T extends Character> implements Path<T> {
|
||||
|
||||
@@ -51,4 +52,9 @@ public class CharacterPath<T extends Character> implements Path<T> {
|
||||
path.add(new RunSegment<>(runnable));
|
||||
return this;
|
||||
}
|
||||
|
||||
public CharacterPath<T> suspend(Predicate<T> predicate) {
|
||||
path.add(new SuspendSegment<>(predicate));
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
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.function.Predicate;
|
||||
|
||||
@RequiredArgsConstructor
|
||||
public class SuspendSegment<T extends Movable> implements PathSegment<T> {
|
||||
private final Predicate<T> predicate;
|
||||
|
||||
@Override
|
||||
public PathProgress perform(T movable, ObjectLayer layer, float dt) {
|
||||
if (predicate.test(movable)) {
|
||||
return PathProgress.SEGMENT_DONE;
|
||||
}
|
||||
|
||||
return PathProgress.ONGOING;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user