Remove Movement interface - make DefaultMovement a final Movement class and move it to :API
This commit is contained in:
@@ -30,4 +30,6 @@ public interface Movable extends Placeable {
|
||||
int chebyshevDistance(Vector2ic coordinates);
|
||||
|
||||
int manhattanDistance(Vector2ic coordinates);
|
||||
|
||||
boolean move(Movement movement);
|
||||
}
|
||||
|
||||
@@ -1,17 +1,32 @@
|
||||
package com.bartlomiejpluta.base.api.move;
|
||||
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.Getter;
|
||||
import lombok.NonNull;
|
||||
import org.joml.Vector2i;
|
||||
import org.joml.Vector2ic;
|
||||
|
||||
public interface Movement {
|
||||
Movable getObject();
|
||||
@Getter
|
||||
@EqualsAndHashCode
|
||||
public final class Movement {
|
||||
private final Movable object;
|
||||
private final Direction direction;
|
||||
private final Vector2ic from;
|
||||
private final Vector2ic to;
|
||||
|
||||
boolean perform();
|
||||
public Movement(@NonNull Movable object, @NonNull Direction direction) {
|
||||
this.object = object;
|
||||
this.direction = direction;
|
||||
|
||||
Movement another();
|
||||
this.from = object.getCoordinates();
|
||||
this.to = direction.vector.add(object.getCoordinates(), new Vector2i());
|
||||
}
|
||||
|
||||
Vector2ic getFrom();
|
||||
public boolean perform() {
|
||||
return object.move(this);
|
||||
}
|
||||
|
||||
Vector2ic getTo();
|
||||
|
||||
Direction getDirection();
|
||||
public Movement another() {
|
||||
return object.prepareMovement(direction);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -147,7 +147,7 @@ public abstract class AnimationDelegate implements Animation {
|
||||
|
||||
@Override
|
||||
public Movement prepareMovement(Direction direction) {
|
||||
return animation.prepareMovement(direction);
|
||||
return new Movement(this, direction);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -195,6 +195,11 @@ public abstract class AnimationDelegate implements Animation {
|
||||
animation.setSpeed(speed);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean move(Movement movement) {
|
||||
return animation.move(movement);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAdd(Layer layer) {
|
||||
animation.onAdd(layer);
|
||||
|
||||
@@ -41,7 +41,7 @@ public abstract class EntityDelegate implements Entity {
|
||||
|
||||
@Override
|
||||
public Movement prepareMovement(Direction direction) {
|
||||
return entity.prepareMovement(direction);
|
||||
return new Movement(this, direction);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -229,6 +229,11 @@ public abstract class EntityDelegate implements Entity {
|
||||
entity.setZIndex(zIndex);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean move(Movement movement) {
|
||||
return entity.move(movement);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(float dt) {
|
||||
entity.update(dt);
|
||||
|
||||
@@ -87,7 +87,7 @@ public class DefaultEntity extends MovableSprite implements Entity {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean move(Movement movement) {
|
||||
public boolean move(Movement movement) {
|
||||
if (super.move(movement)) {
|
||||
faceDirection = movement.getDirection();
|
||||
return true;
|
||||
|
||||
@@ -1,35 +0,0 @@
|
||||
package com.bartlomiejpluta.base.engine.world.movement;
|
||||
|
||||
import com.bartlomiejpluta.base.api.move.Direction;
|
||||
import com.bartlomiejpluta.base.api.move.Movement;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.Getter;
|
||||
import org.joml.Vector2i;
|
||||
import org.joml.Vector2ic;
|
||||
|
||||
@Getter
|
||||
@EqualsAndHashCode
|
||||
public class DefaultMovement implements Movement {
|
||||
private final MovableSprite object;
|
||||
private final Direction direction;
|
||||
private final Vector2ic from;
|
||||
private final Vector2ic to;
|
||||
|
||||
DefaultMovement(MovableSprite object, Direction direction) {
|
||||
this.object = object;
|
||||
this.direction = direction;
|
||||
|
||||
this.from = object.getCoordinates();
|
||||
this.to = direction.vector.add(object.getCoordinates(), new Vector2i());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean perform() {
|
||||
return object.move(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Movement another() {
|
||||
return object.prepareMovement(direction);
|
||||
}
|
||||
}
|
||||
@@ -82,10 +82,11 @@ public abstract class MovableSprite extends AnimatedSprite implements Movable, U
|
||||
|
||||
@Override
|
||||
public Movement prepareMovement(Direction direction) {
|
||||
return new DefaultMovement(this, direction);
|
||||
return new Movement(this, direction);
|
||||
}
|
||||
|
||||
protected boolean move(Movement movement) {
|
||||
@Override
|
||||
public boolean move(Movement movement) {
|
||||
if (this.movement != null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user