Wrap Texture with TexturedMaterial

This commit is contained in:
2025-07-22 15:32:26 +02:00
parent 4fede6a0fc
commit a66b450203
19 changed files with 453 additions and 46 deletions

View File

@@ -1,5 +1,6 @@
package com.bartlomiejpluta.base.api.animation;
import com.bartlomiejpluta.base.api.color.Colorful;
import com.bartlomiejpluta.base.api.map.layer.base.Layer;
import com.bartlomiejpluta.base.api.move.Movable;
import com.bartlomiejpluta.base.internal.program.Updatable;
@@ -8,7 +9,7 @@ import com.bartlomiejpluta.base.util.path.Path;
import java.util.concurrent.CompletableFuture;
public interface Animation extends Movable, Animated, Renderable, Updatable {
public interface Animation extends Movable, Animated, Colorful, Renderable, Updatable {
Integer getRepeat();

View File

@@ -1,6 +1,7 @@
package com.bartlomiejpluta.base.api.character;
import com.bartlomiejpluta.base.api.animation.Animated;
import com.bartlomiejpluta.base.api.color.Colorful;
import com.bartlomiejpluta.base.api.entity.Entity;
import com.bartlomiejpluta.base.api.move.Direction;
import com.bartlomiejpluta.base.api.move.Movable;
@@ -26,10 +27,10 @@ import java.util.concurrent.CompletableFuture;
* damaged box).
*
* <p>This interface combines movement capabilities ({@link Movable}), animation features
* ({@link Animated}), and entity properties ({@link Entity}) to create a complete
* ({@link Animated}), coloring capabilities ({@link Colorful}), and entity properties ({@link Entity}) to create a complete
* character system for 2D games.
*/
public interface Character extends Movable, Animated, Entity {
public interface Character extends Movable, Animated, Colorful, Entity {
/**
* Initiates movement in the specified direction.

View File

@@ -0,0 +1,123 @@
package com.bartlomiejpluta.base.api.color;
import org.joml.Vector3fc;
import org.joml.Vector4fc;
/**
* Interface for objects that can be colored and have their color properties modified.
* This interface provides a comprehensive API for managing RGBA color values using
* various input formats including JOML vectors, individual float components, and
* packed integer values.
*
* <p>Color components are expected to be in the range [0.0, 1.0] for float values,
* where 0.0 represents no intensity and 1.0 represents full intensity.</p>
*/
public interface Colorful {
/**
* Returns the current color of this object.
*
* @return a Vector4fc containing the RGBA color components, where:
* x = red, y = green, z = blue, w = alpha.
* All components are in the range [0.0, 1.0].
*/
Vector4fc getColor();
/**
* Sets the color of this object using a 4D vector.
*
* @param color a Vector4fc containing the RGBA color components, where:
* x = red, y = green, z = blue, w = alpha.
* All components should be in the range [0.0, 1.0].
* @throws NullPointerException if color is null
*/
void setColor(Vector4fc color);
/**
* Sets the RGB color components of this object using a 3D vector.
* The alpha component will remain unchanged or be set to a default value.
*
* @param color a Vector3fc containing the RGB color components, where:
* x = red, y = green, z = blue.
* All components should be in the range [0.0, 1.0].
* @throws NullPointerException if color is null
*/
void setColor(Vector3fc color);
/**
* Sets the RGBA color components of this object using individual float values.
*
* @param red the red component in the range [0.0, 1.0]
* @param green the green component in the range [0.0, 1.0]
* @param blue the blue component in the range [0.0, 1.0]
* @param alpha the alpha component in the range [0.0, 1.0]
*/
void setColor(float red, float green, float blue, float alpha);
/**
* Sets the RGB color components of this object using individual float values.
* The alpha component will remain unchanged or be set to a default value.
*
* @param red the red component in the range [0.0, 1.0]
* @param green the green component in the range [0.0, 1.0]
* @param blue the blue component in the range [0.0, 1.0]
*/
void setColor(float red, float green, float blue);
/**
* Sets the color of this object using a packed RGBA integer value.
* The integer is expected to be in RGBA format where each component
* occupies 8 bits in the range [0, 255] and is automatically converted
* to the [0.0, 1.0] range by dividing by 255.
*
* <p>The bit layout is as follows:</p>
* <ul>
* <li>Bits 24-31: Red component</li>
* <li>Bits 16-23: Green component</li>
* <li>Bits 8-15: Blue component</li>
* <li>Bits 0-7: Alpha component</li>
* </ul>
*
* <p>For example, {@code 0xFF0000FF} represents full red with full alpha,
* while green and blue are zero.</p>
*
* @param rgba the packed RGBA color value
*/
default void setColor(int rgba) {
setColor(
((rgba >>> 24) & 0xFF) / 255f,
((rgba >>> 16) & 0xFF) / 255f,
((rgba >>> 8) & 0xFF) / 255f,
(rgba & 0xFF) / 255f
);
}
/**
* Sets only the red color component of this object.
*
* @param red the red component in the range [0.0, 1.0]
*/
void setRed(float red);
/**
* Sets only the green color component of this object.
*
* @param green the green component in the range [0.0, 1.0]
*/
void setGreen(float green);
/**
* Sets only the blue color component of this object.
*
* @param blue the blue component in the range [0.0, 1.0]
*/
void setBlue(float blue);
/**
* Sets only the alpha (transparency) component of this object.
*
* @param alpha the alpha component in the range [0.0, 1.0], where
* 0.0 is fully transparent and 1.0 is fully opaque
*/
void setAlpha(float alpha);
}

View File

@@ -1,8 +1,9 @@
package com.bartlomiejpluta.base.api.icon;
import com.bartlomiejpluta.base.api.color.Colorful;
import com.bartlomiejpluta.base.api.entity.Entity;
public interface Icon extends Entity {
public interface Icon extends Colorful, Entity {
void changeIcon(int row, int column);
void changeIcon(String iconSetUid, int row, int column);

View File

@@ -11,9 +11,7 @@ import com.bartlomiejpluta.base.api.screen.Screen;
import com.bartlomiejpluta.base.internal.object.Placeable;
import com.bartlomiejpluta.base.internal.render.ShaderManager;
import com.bartlomiejpluta.base.util.path.Path;
import org.joml.Matrix4fc;
import org.joml.Vector2fc;
import org.joml.Vector2ic;
import org.joml.*;
import java.util.concurrent.CompletableFuture;
@@ -294,6 +292,51 @@ public abstract class AnimationDelegate implements Animation {
return animation.getLayer();
}
@Override
public Vector4fc getColor() {
return animation.getColor();
}
@Override
public void setColor(Vector4fc color) {
animation.setColor(color);
}
@Override
public void setColor(Vector3fc color) {
animation.setColor(color);
}
@Override
public void setColor(float red, float green, float blue, float alpha) {
animation.setColor(red, green, blue, alpha);
}
@Override
public void setColor(float red, float green, float blue) {
animation.setColor(red, green, blue);
}
@Override
public void setRed(float red) {
animation.setRed(red);
}
@Override
public void setGreen(float green) {
animation.setGreen(green);
}
@Override
public void setBlue(float blue) {
animation.setBlue(blue);
}
@Override
public void setAlpha(float alpha) {
animation.setAlpha(alpha);
}
@Override
public void render(Screen screen, Camera camera, ShaderManager shaderManager) {
animation.render(screen, camera, shaderManager);

View File

@@ -12,9 +12,7 @@ import com.bartlomiejpluta.base.api.move.Movement;
import com.bartlomiejpluta.base.api.screen.Screen;
import com.bartlomiejpluta.base.internal.object.Placeable;
import com.bartlomiejpluta.base.internal.render.ShaderManager;
import org.joml.Matrix4fc;
import org.joml.Vector2fc;
import org.joml.Vector2ic;
import org.joml.*;
import java.util.concurrent.CompletableFuture;
import java.util.function.Consumer;
@@ -328,6 +326,51 @@ public abstract class CharacterDelegate implements Character {
character.abortMove();
}
@Override
public Vector4fc getColor() {
return character.getColor();
}
@Override
public void setColor(Vector4fc color) {
character.setColor(color);
}
@Override
public void setColor(Vector3fc color) {
character.setColor(color);
}
@Override
public void setColor(float red, float green, float blue, float alpha) {
character.setColor(red, green, blue, alpha);
}
@Override
public void setColor(float red, float green, float blue) {
character.setColor(red, green, blue);
}
@Override
public void setRed(float red) {
character.setRed(red);
}
@Override
public void setGreen(float green) {
character.setGreen(green);
}
@Override
public void setBlue(float blue) {
character.setBlue(blue);
}
@Override
public void setAlpha(float alpha) {
character.setAlpha(alpha);
}
@Override
public void update(float dt) {
character.update(dt);

View File

@@ -11,9 +11,7 @@ import com.bartlomiejpluta.base.api.screen.Screen;
import com.bartlomiejpluta.base.internal.object.Placeable;
import com.bartlomiejpluta.base.internal.render.ShaderManager;
import lombok.NonNull;
import org.joml.Matrix4fc;
import org.joml.Vector2fc;
import org.joml.Vector2ic;
import org.joml.*;
import java.util.function.Consumer;
@@ -249,6 +247,51 @@ public abstract class IconDelegate implements Icon {
icon.handleEvent(event);
}
@Override
public Vector4fc getColor() {
return icon.getColor();
}
@Override
public void setColor(Vector4fc color) {
icon.setColor(color);
}
@Override
public void setColor(Vector3fc color) {
icon.setColor(color);
}
@Override
public void setColor(float red, float green, float blue, float alpha) {
icon.setColor(red, green, blue, alpha);
}
@Override
public void setColor(float red, float green, float blue) {
icon.setColor(red, green, blue);
}
@Override
public void setRed(float red) {
icon.setRed(red);
}
@Override
public void setGreen(float green) {
icon.setGreen(green);
}
@Override
public void setBlue(float blue) {
icon.setBlue(blue);
}
@Override
public void setAlpha(float alpha) {
icon.setAlpha(alpha);
}
@Override
public void update(float dt) {
icon.update(dt);