Pressing shift when playing path ignores time keyframes

This commit is contained in:
johni0702
2016-03-10 13:31:28 +01:00
parent 45c411fd90
commit 501b10406c
4 changed files with 31 additions and 3 deletions

View File

@@ -16,6 +16,7 @@ public class PathImpl implements Path {
private final Timeline timeline;
private Map<Long, Keyframe> keyframes = new TreeMap<>();
private List<PathSegment> segments = new LinkedList<>();
private boolean active = true;
public PathImpl(Timeline timeline) {
this.timeline = timeline;
@@ -164,6 +165,16 @@ public class PathImpl implements Path {
throw new AssertionError("No segment for keyframe found!");
}
@Override
public void setActive(boolean active) {
this.active = active;
}
@Override
public boolean isActive() {
return active;
}
private PathSegment getSegment(long time) {
for (PathSegment segment : segments) {
if (segment.getStartKeyframe().getTime() <= time && segment.getEndKeyframe().getTime() >= time) {

View File

@@ -30,9 +30,11 @@ public class TimelineImpl implements Timeline {
@Override
public <T> Optional<T> getValue(Property<T> property, long time) {
for (Path path : paths) {
Optional<T> value = path.getValue(property, time);
if (value.isPresent()) {
return value;
if (path.isActive()) {
Optional<T> value = path.getValue(property, time);
if (value.isPresent()) {
return value;
}
}
}
return Optional.absent();

View File

@@ -99,4 +99,18 @@ public interface Path {
* {@code false} if it inherits the one of the second segment
*/
void remove(Keyframe keyframe, boolean useFirstInterpolator);
/**
* Set whether this path is active.
* If this path is not active, it shouldn't be applied to the game during playback.
* @param active {@code true} if active, {@code false} otherwise
*/
void setActive(boolean active);
/**
* Returns whether this path is active.
* @return {@code true} if active, {@code false} otherwise
* @see #setActive(boolean)
*/
boolean isActive();
}