Extract ColorLayer interface to :api
This commit is contained in:
@@ -0,0 +1,18 @@
|
||||
package com.bartlomiejpluta.base.api.game.map;
|
||||
|
||||
import com.bartlomiejpluta.base.api.internal.object.Placeable;
|
||||
import com.bartlomiejpluta.base.api.internal.render.Renderable;
|
||||
|
||||
public interface ColorLayer extends Placeable, Renderable, Layer {
|
||||
void setColor(float red, float green, float blue, float alpha);
|
||||
|
||||
void setColor(float red, float green, float blue);
|
||||
|
||||
void setRed(float red);
|
||||
|
||||
void setGreen(float green);
|
||||
|
||||
void setBlue(float blue);
|
||||
|
||||
void setAlpha(float alpha);
|
||||
}
|
||||
@@ -19,6 +19,8 @@ public interface GameMap {
|
||||
|
||||
ImageLayer getImageLayer(int layerIndex);
|
||||
|
||||
ColorLayer getColorLayer(int layerIndex);
|
||||
|
||||
void addEntity(int objectLayerIndex, Entity entity);
|
||||
|
||||
void removeEntity(int objectLayerIndex, Entity entity);
|
||||
@@ -26,6 +28,4 @@ public interface GameMap {
|
||||
boolean isMovementPossible(int objectLayerIndex, Movement movement);
|
||||
|
||||
void setPassageAbility(int objectLayerIndex, int row, int column, PassageAbility passageAbility);
|
||||
|
||||
void setColor(int colorLayerIndex, float r, float g, float b, float alpha);
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ import com.bartlomiejpluta.base.engine.core.gl.object.texture.Texture;
|
||||
import com.bartlomiejpluta.base.engine.core.gl.shader.constant.UniformName;
|
||||
import lombok.Getter;
|
||||
import org.joml.Vector2f;
|
||||
import org.joml.Vector3f;
|
||||
import org.joml.Vector4f;
|
||||
|
||||
@Getter
|
||||
@@ -16,16 +17,16 @@ public class Material implements Renderable {
|
||||
private final Vector2f spritePosition = new Vector2f(0, 0);
|
||||
private final Texture texture;
|
||||
|
||||
private Material(Texture texture, float r, float g, float b, float alpha) {
|
||||
private Material(Texture texture, float red, float green, float blue, float alpha) {
|
||||
this.texture = texture;
|
||||
setColor(r, g, b, alpha);
|
||||
setColor(red, green, blue, alpha);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(Window window, Camera camera, ShaderManager shaderManager) {
|
||||
shaderManager.setUniform(UniformName.UNI_OBJECT_COLOR, color);
|
||||
|
||||
if(texture != null) {
|
||||
if (texture != null) {
|
||||
shaderManager.setUniform(UniformName.UNI_HAS_OBJECT_TEXTURE, true);
|
||||
shaderManager.setUniform(UniformName.UNI_SPRITE_SIZE, texture.getSpriteFragment());
|
||||
shaderManager.setUniform(UniformName.UNI_SPRITE_POSITION, spritePosition);
|
||||
@@ -36,10 +37,6 @@ public class Material implements Renderable {
|
||||
}
|
||||
}
|
||||
|
||||
public void setAlpha(float alpha) {
|
||||
this.color.w = alpha;
|
||||
}
|
||||
|
||||
public void setColor(Vector4f color) {
|
||||
this.color.x = color.x;
|
||||
this.color.y = color.y;
|
||||
@@ -47,15 +44,43 @@ public class Material implements Renderable {
|
||||
this.color.w = color.w;
|
||||
}
|
||||
|
||||
public void setColor(float r, float g, float b, float alpha) {
|
||||
color.x = r;
|
||||
color.y = g;
|
||||
color.z = b;
|
||||
color.w = alpha;
|
||||
public void setColor(Vector3f color) {
|
||||
this.color.x = color.x;
|
||||
this.color.y = color.y;
|
||||
this.color.z = color.z;
|
||||
}
|
||||
|
||||
public void setColor(float red, float green, float blue, float alpha) {
|
||||
this.color.x = red;
|
||||
this.color.y = green;
|
||||
this.color.z = blue;
|
||||
this.color.w = alpha;
|
||||
}
|
||||
|
||||
public void setColor(float red, float green, float blue) {
|
||||
this.color.x = red;
|
||||
this.color.y = green;
|
||||
this.color.z = blue;
|
||||
}
|
||||
|
||||
public void setRed(float red) {
|
||||
this.color.x = red;
|
||||
}
|
||||
|
||||
public void setGreen(float green) {
|
||||
this.color.y = green;
|
||||
}
|
||||
|
||||
public void setBlue(float blue) {
|
||||
this.color.z = blue;
|
||||
}
|
||||
|
||||
public void setAlpha(float alpha) {
|
||||
this.color.w = alpha;
|
||||
}
|
||||
|
||||
public void setSpritePosition(Vector2f spritePosition) {
|
||||
if(texture != null) {
|
||||
if (texture != null) {
|
||||
var size = texture.getSpriteFragment();
|
||||
this.spritePosition.x = size.x * spritePosition.x;
|
||||
this.spritePosition.y = size.y * spritePosition.y;
|
||||
@@ -63,23 +88,23 @@ public class Material implements Renderable {
|
||||
}
|
||||
|
||||
public void setSpritePosition(float x, float y) {
|
||||
if(texture != null) {
|
||||
if (texture != null) {
|
||||
var size = texture.getSpriteFragment();
|
||||
this.spritePosition.x = size.x * x;
|
||||
this.spritePosition.y = size.y * y;
|
||||
}
|
||||
}
|
||||
|
||||
public static Material colored(float r, float g, float b, float alpha) {
|
||||
return new Material(null, r, g, b, alpha);
|
||||
public static Material colored(float red, float green, float blue, float alpha) {
|
||||
return new Material(null, red, green, blue, alpha);
|
||||
}
|
||||
|
||||
public static Material textured(Texture texture) {
|
||||
return new Material(texture, 1, 1, 1, 1);
|
||||
}
|
||||
|
||||
public static Material textured(Texture texture, float r, float g, float b, float alpha) {
|
||||
return new Material(texture, r, g, b, alpha);
|
||||
public static Material textured(Texture texture, float red, float green, float blue, float alpha) {
|
||||
return new Material(texture, red, green, blue, alpha);
|
||||
}
|
||||
|
||||
public static Material textured(Texture texture, float alpha) {
|
||||
|
||||
@@ -1,37 +0,0 @@
|
||||
package com.bartlomiejpluta.base.engine.world.map.layer.color;
|
||||
|
||||
import com.bartlomiejpluta.base.api.game.camera.Camera;
|
||||
import com.bartlomiejpluta.base.api.game.map.Layer;
|
||||
import com.bartlomiejpluta.base.api.game.window.Window;
|
||||
import com.bartlomiejpluta.base.api.internal.render.ShaderManager;
|
||||
import com.bartlomiejpluta.base.engine.core.gl.object.material.Material;
|
||||
import com.bartlomiejpluta.base.engine.util.mesh.MeshManager;
|
||||
import com.bartlomiejpluta.base.engine.world.map.model.DefaultGameMap;
|
||||
import com.bartlomiejpluta.base.engine.world.object.Sprite;
|
||||
import lombok.NonNull;
|
||||
|
||||
public class ColorLayer extends Sprite implements Layer {
|
||||
private final float mapWidth;
|
||||
private final float mapHeight;
|
||||
|
||||
public ColorLayer(@NonNull MeshManager meshManager, @NonNull DefaultGameMap 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) {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
package com.bartlomiejpluta.base.engine.world.map.layer.color;
|
||||
|
||||
import com.bartlomiejpluta.base.api.game.map.ColorLayer;
|
||||
import com.bartlomiejpluta.base.api.game.map.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.NonNull;
|
||||
|
||||
public class DefaultColorLayer extends Sprite implements ColorLayer {
|
||||
|
||||
public DefaultColorLayer(@NonNull MeshManager meshManager, @NonNull GameMap map, float red, float green, float blue, float alpha) {
|
||||
super(meshManager.createQuad(1, 1, 0, 0), Material.colored(red, green, blue, alpha));
|
||||
setScale(map.getWidth(), map.getHeight());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setColor(float red, float green, float blue, float alpha) {
|
||||
material.setColor(red, green, blue, alpha);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setColor(float red, float green, float blue) {
|
||||
material.setColor(red, green, blue);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setRed(float red) {
|
||||
material.setRed(red);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setGreen(float green) {
|
||||
material.setGreen(green);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBlue(float blue) {
|
||||
material.setBlue(blue);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAlpha(float alpha) {
|
||||
material.setAlpha(alpha);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(float dt) {
|
||||
// Do nothing
|
||||
}
|
||||
}
|
||||
@@ -10,7 +10,7 @@ import com.bartlomiejpluta.base.api.internal.render.Renderable;
|
||||
import com.bartlomiejpluta.base.api.internal.render.ShaderManager;
|
||||
import com.bartlomiejpluta.base.engine.util.mesh.MeshManager;
|
||||
import com.bartlomiejpluta.base.engine.world.entity.model.DefaultEntity;
|
||||
import com.bartlomiejpluta.base.engine.world.map.layer.color.ColorLayer;
|
||||
import com.bartlomiejpluta.base.engine.world.map.layer.color.DefaultColorLayer;
|
||||
import com.bartlomiejpluta.base.engine.world.map.layer.image.DefaultImageLayer;
|
||||
import com.bartlomiejpluta.base.engine.world.map.layer.object.ObjectLayer;
|
||||
import com.bartlomiejpluta.base.engine.world.map.layer.tile.DefaultTileLayer;
|
||||
@@ -88,6 +88,11 @@ public class DefaultGameMap implements Renderable, Updatable, GameMap {
|
||||
return (ImageLayer) layers.get(layerIndex);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ColorLayer getColorLayer(int layerIndex) {
|
||||
return (ColorLayer) layers.get(layerIndex);
|
||||
}
|
||||
|
||||
public int createObjectLayer() {
|
||||
var passageMap = new PassageAbility[rows][columns];
|
||||
for (int i = 0; i < rows; ++i) {
|
||||
@@ -106,10 +111,11 @@ public class DefaultGameMap implements Renderable, Updatable, GameMap {
|
||||
return layer;
|
||||
}
|
||||
|
||||
public int createColorLayer(MeshManager meshManager, float r, float g, float b, float alpha) {
|
||||
layers.add(new ColorLayer(meshManager, this, r, g, b, alpha));
|
||||
public ColorLayer createColorLayer(MeshManager meshManager, float red, float green, float blue, float alpha) {
|
||||
var layer = new DefaultColorLayer(meshManager, this, red, green, blue, alpha);
|
||||
layers.add(layer);
|
||||
|
||||
return layers.size() - 1;
|
||||
return layer;
|
||||
}
|
||||
|
||||
public ImageLayer createImageLayer(Image image, float opacity, float x, float y, float scaleX, float scaleY, ImageLayerMode mode, boolean parallax) {
|
||||
@@ -137,11 +143,6 @@ public class DefaultGameMap implements Renderable, Updatable, GameMap {
|
||||
((ObjectLayer) layers.get(objectLayerIndex)).setPassageAbility(row, column, passageAbility);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setColor(int colorLayerIndex, float r, float g, float b, float alpha) {
|
||||
((ColorLayer) layers.get(colorLayerIndex)).setColor(r, g, b, alpha);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isMovementPossible(int objectLayerIndex, Movement movement) {
|
||||
var target = movement.getTo();
|
||||
|
||||
Reference in New Issue
Block a user