Add getMap() method to Layer interface
This commit is contained in:
@@ -1,8 +1,9 @@
|
||||
package com.bartlomiejpluta.base.api.game.map.layer.base;
|
||||
|
||||
import com.bartlomiejpluta.base.api.game.map.model.GameMap;
|
||||
import com.bartlomiejpluta.base.api.internal.logic.Updatable;
|
||||
import com.bartlomiejpluta.base.api.internal.render.Renderable;
|
||||
|
||||
public interface Layer extends Renderable, Updatable {
|
||||
|
||||
GameMap getMap();
|
||||
}
|
||||
|
||||
@@ -5,12 +5,17 @@ import com.bartlomiejpluta.base.api.game.map.model.GameMap;
|
||||
import com.bartlomiejpluta.base.engine.core.gl.object.material.Material;
|
||||
import com.bartlomiejpluta.base.engine.util.mesh.MeshManager;
|
||||
import com.bartlomiejpluta.base.engine.world.object.Sprite;
|
||||
import lombok.Getter;
|
||||
import lombok.NonNull;
|
||||
|
||||
public class DefaultColorLayer extends Sprite implements ColorLayer {
|
||||
|
||||
public DefaultColorLayer(@NonNull MeshManager meshManager, @NonNull GameMap map, float red, float green, float blue, float alpha) {
|
||||
@Getter
|
||||
private final GameMap map;
|
||||
|
||||
public DefaultColorLayer(@NonNull GameMap map, @NonNull MeshManager meshManager, float red, float green, float blue, float alpha) {
|
||||
super(meshManager.createQuad(1, 1, 0, 0), Material.colored(red, green, blue, alpha));
|
||||
this.map = map;
|
||||
setScale(map.getWidth(), map.getHeight());
|
||||
}
|
||||
|
||||
|
||||
@@ -15,6 +15,9 @@ public class DefaultImageLayer implements ImageLayer {
|
||||
private final float mapWidth;
|
||||
private final float mapHeight;
|
||||
|
||||
@Getter
|
||||
private final GameMap map;
|
||||
|
||||
@NonNull
|
||||
@Getter
|
||||
private Image image;
|
||||
@@ -37,6 +40,7 @@ public class DefaultImageLayer implements ImageLayer {
|
||||
private boolean parallax;
|
||||
|
||||
public DefaultImageLayer(GameMap map, Image image, float opacity, float x, float y, float scaleX, float scaleY, ImageLayerMode mode, boolean parallax) {
|
||||
this.map = map;
|
||||
this.mapWidth = map.getWidth();
|
||||
this.mapHeight = map.getHeight();
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@ import com.bartlomiejpluta.base.api.game.entity.Entity;
|
||||
import com.bartlomiejpluta.base.api.game.entity.Movement;
|
||||
import com.bartlomiejpluta.base.api.game.map.layer.object.ObjectLayer;
|
||||
import com.bartlomiejpluta.base.api.game.map.layer.object.PassageAbility;
|
||||
import com.bartlomiejpluta.base.api.game.map.model.GameMap;
|
||||
import com.bartlomiejpluta.base.api.game.rule.Rule;
|
||||
import com.bartlomiejpluta.base.api.game.window.Window;
|
||||
import com.bartlomiejpluta.base.api.internal.render.ShaderManager;
|
||||
@@ -20,6 +21,9 @@ import java.util.List;
|
||||
|
||||
public class DefaultObjectLayer implements ObjectLayer {
|
||||
|
||||
@Getter
|
||||
private final GameMap map;
|
||||
|
||||
@Getter
|
||||
private final List<Entity> entities;
|
||||
|
||||
@@ -34,7 +38,8 @@ public class DefaultObjectLayer implements ObjectLayer {
|
||||
private final int columns;
|
||||
private final Vector2f stepSize;
|
||||
|
||||
public DefaultObjectLayer(int rows, int columns, @NonNull Vector2f stepSize, List<Entity> entities, PassageAbility[][] passageMap) {
|
||||
public DefaultObjectLayer(@NonNull GameMap map, int rows, int columns, @NonNull Vector2f stepSize, List<Entity> entities, PassageAbility[][] passageMap) {
|
||||
this.map = map;
|
||||
this.rows = rows;
|
||||
this.columns = columns;
|
||||
this.stepSize = stepSize;
|
||||
|
||||
@@ -2,10 +2,12 @@ package com.bartlomiejpluta.base.engine.world.map.layer.tile;
|
||||
|
||||
import com.bartlomiejpluta.base.api.game.camera.Camera;
|
||||
import com.bartlomiejpluta.base.api.game.map.layer.tile.TileLayer;
|
||||
import com.bartlomiejpluta.base.api.game.map.model.GameMap;
|
||||
import com.bartlomiejpluta.base.api.game.window.Window;
|
||||
import com.bartlomiejpluta.base.api.internal.render.ShaderManager;
|
||||
import com.bartlomiejpluta.base.engine.world.tileset.model.Tile;
|
||||
import com.bartlomiejpluta.base.engine.world.tileset.model.TileSet;
|
||||
import lombok.Getter;
|
||||
import lombok.NonNull;
|
||||
|
||||
import java.util.Arrays;
|
||||
@@ -14,7 +16,11 @@ public class DefaultTileLayer implements TileLayer {
|
||||
private final TileSet tileSet;
|
||||
private final Tile[][] layer;
|
||||
|
||||
public DefaultTileLayer(@NonNull TileSet tileSet, int rows, int columns) {
|
||||
@Getter
|
||||
private final GameMap map;
|
||||
|
||||
public DefaultTileLayer(@NonNull GameMap map, @NonNull TileSet tileSet, int rows, int columns) {
|
||||
this.map = map;
|
||||
this.tileSet = tileSet;
|
||||
layer = new Tile[rows][columns];
|
||||
Arrays.stream(layer).forEach(tiles -> Arrays.fill(tiles, null));
|
||||
|
||||
@@ -104,7 +104,7 @@ public class DefaultGameMap implements Renderable, Updatable, GameMap {
|
||||
}
|
||||
|
||||
public TileLayer createTileLayer() {
|
||||
var layer = new DefaultTileLayer(tileSet, rows, columns);
|
||||
var layer = new DefaultTileLayer(this, tileSet, rows, columns);
|
||||
layers.add(layer);
|
||||
|
||||
return layer;
|
||||
@@ -118,7 +118,7 @@ public class DefaultGameMap implements Renderable, Updatable, GameMap {
|
||||
}
|
||||
|
||||
public ColorLayer createColorLayer(MeshManager meshManager, float red, float green, float blue, float alpha) {
|
||||
var layer = new DefaultColorLayer(meshManager, this, red, green, blue, alpha);
|
||||
var layer = new DefaultColorLayer(this, meshManager, red, green, blue, alpha);
|
||||
layers.add(layer);
|
||||
|
||||
return layer;
|
||||
@@ -130,7 +130,7 @@ public class DefaultGameMap implements Renderable, Updatable, GameMap {
|
||||
Arrays.fill(passageMap[i], 0, columns, PassageAbility.ALLOW);
|
||||
}
|
||||
|
||||
var layer = new DefaultObjectLayer(rows, columns, stepSize, new ArrayList<>(), passageMap);
|
||||
var layer = new DefaultObjectLayer(this, rows, columns, stepSize, new ArrayList<>(), passageMap);
|
||||
|
||||
layers.add(layer);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user