Create lifecycle hooks in MapHandler and Entity
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
package com.bartlomiejpluta.base.api.game.entity;
|
||||
|
||||
import com.bartlomiejpluta.base.api.game.map.layer.object.ObjectLayer;
|
||||
import com.bartlomiejpluta.base.api.internal.logic.Updatable;
|
||||
import com.bartlomiejpluta.base.api.internal.object.Placeable;
|
||||
import com.bartlomiejpluta.base.api.internal.render.Renderable;
|
||||
@@ -31,4 +32,8 @@ public interface Entity extends Placeable, Renderable, Updatable {
|
||||
int manhattanDistance(Entity other);
|
||||
|
||||
Direction getDirectionTowards(Entity target);
|
||||
|
||||
void onAdd(ObjectLayer layer);
|
||||
|
||||
void onRemove(ObjectLayer layer);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.bartlomiejpluta.base.api.game.entity;
|
||||
|
||||
import com.bartlomiejpluta.base.api.game.camera.Camera;
|
||||
import com.bartlomiejpluta.base.api.game.map.layer.object.ObjectLayer;
|
||||
import com.bartlomiejpluta.base.api.game.window.Window;
|
||||
import com.bartlomiejpluta.base.api.internal.object.Placeable;
|
||||
import com.bartlomiejpluta.base.api.internal.render.ShaderManager;
|
||||
@@ -9,7 +10,7 @@ import org.joml.Vector2f;
|
||||
import org.joml.Vector2i;
|
||||
|
||||
public abstract class EntityDelegate implements Entity {
|
||||
private final Entity entity;
|
||||
protected final Entity entity;
|
||||
|
||||
protected EntityDelegate(Entity entity) {
|
||||
this.entity = entity;
|
||||
@@ -160,6 +161,16 @@ public abstract class EntityDelegate implements Entity {
|
||||
return entity.getModelMatrix();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAdd(ObjectLayer layer) {
|
||||
entity.onAdd(layer);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRemove(ObjectLayer layer) {
|
||||
entity.onRemove(layer);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(float dt) {
|
||||
entity.update(dt);
|
||||
|
||||
@@ -5,7 +5,9 @@ import com.bartlomiejpluta.base.api.game.map.model.GameMap;
|
||||
import com.bartlomiejpluta.base.api.game.window.Window;
|
||||
|
||||
public interface MapHandler {
|
||||
void init(Context context, GameMap map);
|
||||
void onCreate(Context context, GameMap map);
|
||||
|
||||
void onOpen(Context context, GameMap map);
|
||||
|
||||
void input(Window window);
|
||||
|
||||
|
||||
@@ -12,6 +12,8 @@ public interface ObjectLayer extends Layer {
|
||||
|
||||
void removeEntity(Entity entity);
|
||||
|
||||
void clearEntities();
|
||||
|
||||
List<Entity> getEntities();
|
||||
|
||||
void registerRule(Rule rule);
|
||||
|
||||
Reference in New Issue
Block a user