Implement ColorLayer on the :game module side
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
package com.bartlomiejpluta.base.game.map.layer.color;
|
||||
|
||||
import com.bartlomiejpluta.base.core.gl.object.material.Material;
|
||||
import com.bartlomiejpluta.base.core.gl.shader.manager.ShaderManager;
|
||||
import com.bartlomiejpluta.base.core.ui.Window;
|
||||
import com.bartlomiejpluta.base.core.util.mesh.MeshManager;
|
||||
import com.bartlomiejpluta.base.core.world.camera.Camera;
|
||||
import com.bartlomiejpluta.base.core.world.object.Sprite;
|
||||
import com.bartlomiejpluta.base.game.map.layer.base.Layer;
|
||||
import com.bartlomiejpluta.base.game.map.model.GameMap;
|
||||
import lombok.NonNull;
|
||||
|
||||
public class ColorLayer extends Sprite implements Layer {
|
||||
private final float mapWidth;
|
||||
private final float mapHeight;
|
||||
|
||||
public ColorLayer(@NonNull MeshManager meshManager, @NonNull GameMap map, float r, float g, float b, float alpha) {
|
||||
super(meshManager.createQuad(1, 1, 0, 0), Material.colored(r, g, b, alpha));
|
||||
this.mapWidth = map.getWidth();
|
||||
this.mapHeight = map.getHeight();
|
||||
setScale(mapWidth, mapHeight);
|
||||
}
|
||||
|
||||
public void setColor(float r, float g, float b, float alpha) {
|
||||
material.setColor(r, g, b, alpha);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(Window window, Camera camera, ShaderManager shaderManager) {
|
||||
super.render(window, camera, shaderManager);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(float dt) {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -9,25 +9,17 @@ import com.bartlomiejpluta.base.game.map.layer.base.Layer;
|
||||
import com.bartlomiejpluta.base.game.map.model.GameMap;
|
||||
|
||||
public class ImageLayer implements Layer {
|
||||
|
||||
public enum Mode {
|
||||
NORMAL,
|
||||
FIT_SCREEN,
|
||||
FIT_MAP
|
||||
}
|
||||
|
||||
private final float mapWidth;
|
||||
private final float mapHeight;
|
||||
|
||||
private Image image;
|
||||
private float imageInitialWidth;
|
||||
private float imageInitialHeight;
|
||||
private final Mode mode;
|
||||
private final ImageLayerMode mode;
|
||||
|
||||
public ImageLayer(GameMap map, Image image, Mode mode) {
|
||||
var stepSize = map.getStepSize();
|
||||
this.mapWidth = map.getColumns() * stepSize.x;
|
||||
this.mapHeight = map.getRows() * stepSize.y;
|
||||
public ImageLayer(GameMap map, Image image, ImageLayerMode mode) {
|
||||
this.mapWidth = map.getWidth();
|
||||
this.mapHeight = map.getHeight();
|
||||
this.mode = mode;
|
||||
setImage(image);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
package com.bartlomiejpluta.base.game.map.layer.image;
|
||||
|
||||
public enum ImageLayerMode {
|
||||
NORMAL,
|
||||
FIT_SCREEN,
|
||||
FIT_MAP
|
||||
}
|
||||
@@ -4,10 +4,13 @@ import com.bartlomiejpluta.base.core.gl.render.Renderable;
|
||||
import com.bartlomiejpluta.base.core.gl.shader.manager.ShaderManager;
|
||||
import com.bartlomiejpluta.base.core.logic.Updatable;
|
||||
import com.bartlomiejpluta.base.core.ui.Window;
|
||||
import com.bartlomiejpluta.base.core.util.mesh.MeshManager;
|
||||
import com.bartlomiejpluta.base.core.world.camera.Camera;
|
||||
import com.bartlomiejpluta.base.game.image.model.Image;
|
||||
import com.bartlomiejpluta.base.game.map.layer.base.Layer;
|
||||
import com.bartlomiejpluta.base.game.map.layer.color.ColorLayer;
|
||||
import com.bartlomiejpluta.base.game.map.layer.image.ImageLayer;
|
||||
import com.bartlomiejpluta.base.game.map.layer.image.ImageLayerMode;
|
||||
import com.bartlomiejpluta.base.game.map.layer.object.ObjectLayer;
|
||||
import com.bartlomiejpluta.base.game.map.layer.object.PassageAbility;
|
||||
import com.bartlomiejpluta.base.game.map.layer.tile.TileLayer;
|
||||
@@ -35,6 +38,12 @@ public class GameMap implements Renderable, Updatable {
|
||||
@Getter
|
||||
private final int columns;
|
||||
|
||||
@Getter
|
||||
private final float width;
|
||||
|
||||
@Getter
|
||||
private final float height;
|
||||
|
||||
@Getter
|
||||
private final Vector2f stepSize;
|
||||
|
||||
@@ -43,6 +52,8 @@ public class GameMap implements Renderable, Updatable {
|
||||
this.rows = rows;
|
||||
this.columns = columns;
|
||||
this.stepSize = new Vector2f(tileSet.getTileSet().getSpriteSize());
|
||||
this.width = columns * stepSize.x;
|
||||
this.height = rows * stepSize.y;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -80,12 +91,36 @@ public class GameMap implements Renderable, Updatable {
|
||||
return layers.size() - 1;
|
||||
}
|
||||
|
||||
public int createImageLayer(Image image, ImageLayer.Mode imageDisplayMode) {
|
||||
public int createColorLayer(MeshManager meshManager, float r, float g, float b, float alpha) {
|
||||
layers.add(new ColorLayer(meshManager, this, r, g, b, alpha));
|
||||
|
||||
return layers.size() - 1;
|
||||
}
|
||||
|
||||
public int createImageLayer(Image image, ImageLayerMode imageDisplayMode) {
|
||||
layers.add(new ImageLayer(this, image, imageDisplayMode));
|
||||
|
||||
return layers.size() - 1;
|
||||
}
|
||||
|
||||
public GameMap setTile(int layerIndex, int row, int column, int tileId) {
|
||||
((TileLayer) layers.get(layerIndex)).setTile(row, column, tileSet.tileById(tileId));
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public GameMap setTile(int layerIndex, int row, int column, int tileSetRow, int tileSetColumn) {
|
||||
((TileLayer) layers.get(layerIndex)).setTile(row, column, tileSet.tileAt(tileSetRow, tileSetColumn));
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public GameMap clearTile(int layerIndex, int row, int column) {
|
||||
((TileLayer) layers.get(layerIndex)).setTile(row, column, null);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public GameMap addObject(int layerIndex, MovableSprite object) {
|
||||
((ObjectLayer) layers.get(layerIndex)).addObject(object);
|
||||
|
||||
@@ -104,20 +139,8 @@ public class GameMap implements Renderable, Updatable {
|
||||
return this;
|
||||
}
|
||||
|
||||
public GameMap setTile(int layerIndex, int row, int column, int tileId) {
|
||||
((TileLayer) layers.get(layerIndex)).setTile(row, column, tileSet.tileById(tileId));
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public GameMap setTile(int layerIndex, int row, int column, int tileSetRow, int tileSetColumn) {
|
||||
((TileLayer) layers.get(layerIndex)).setTile(row, column, tileSet.tileAt(tileSetRow, tileSetColumn));
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public GameMap clearTile(int layerIndex, int row, int column) {
|
||||
((TileLayer) layers.get(layerIndex)).setTile(row, column, null);
|
||||
public GameMap setColor(int layerIndex, float r, float g, float b, float alpha) {
|
||||
((ColorLayer) layers.get(layerIndex)).setColor(r, g, b, alpha);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.bartlomiejpluta.base.game.map.serial;
|
||||
|
||||
import com.bartlomiejpluta.base.core.error.AppException;
|
||||
import com.bartlomiejpluta.base.core.util.mesh.MeshManager;
|
||||
import com.bartlomiejpluta.base.game.map.layer.object.PassageAbility;
|
||||
import com.bartlomiejpluta.base.game.map.model.GameMap;
|
||||
import com.bartlomiejpluta.base.game.tileset.manager.TileSetManager;
|
||||
@@ -16,6 +17,7 @@ import java.io.InputStream;
|
||||
@Component
|
||||
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
|
||||
public class ProtobufMapDeserializer extends MapDeserializer {
|
||||
private final MeshManager meshManager;
|
||||
private final TileSetManager tileSetManager;
|
||||
|
||||
@Override
|
||||
@@ -77,7 +79,14 @@ public class ProtobufMapDeserializer extends MapDeserializer {
|
||||
}
|
||||
|
||||
private void deserializeColorLayer(GameMap map, GameMapProto.Layer proto) {
|
||||
// TODO(return new ColorLayer(...))
|
||||
var protoColorLayer = proto.getColorLayer();
|
||||
map.createColorLayer(
|
||||
meshManager,
|
||||
protoColorLayer.getRed() / 100.0f,
|
||||
protoColorLayer.getGreen() / 100.0f,
|
||||
protoColorLayer.getBlue() / 100.0f,
|
||||
protoColorLayer.getAlpha() / 100.0f
|
||||
);
|
||||
}
|
||||
|
||||
private void deserializeImageLayer(GameMap map, GameMapProto.Layer proto) {
|
||||
|
||||
Reference in New Issue
Block a user