Introduce Character
This commit is huge breaking change. The Entity class has been downgraded to some generic object which can be pushed onto the ObjectLayer, whereas the former "entity" concept has been replaced with Character class.
This commit is contained in:
@@ -14,8 +14,8 @@ import com.bartlomiejpluta.base.engine.project.config.ProjectConfiguration;
|
||||
import com.bartlomiejpluta.base.engine.project.serial.ProjectDeserializer;
|
||||
import com.bartlomiejpluta.base.engine.util.reflection.ClassLoader;
|
||||
import com.bartlomiejpluta.base.engine.world.animation.manager.AnimationManager;
|
||||
import com.bartlomiejpluta.base.engine.world.entity.manager.EntityManager;
|
||||
import com.bartlomiejpluta.base.engine.world.entity.manager.EntitySetManager;
|
||||
import com.bartlomiejpluta.base.engine.world.character.manager.CharacterManager;
|
||||
import com.bartlomiejpluta.base.engine.world.character.manager.CharacterSetManager;
|
||||
import com.bartlomiejpluta.base.engine.world.image.manager.ImageManager;
|
||||
import com.bartlomiejpluta.base.engine.world.map.manager.MapManager;
|
||||
import com.bartlomiejpluta.base.engine.world.tileset.manager.TileSetManager;
|
||||
@@ -35,9 +35,9 @@ public class DefaultContextManager implements ContextManager {
|
||||
private final TileSetManager tileSetManager;
|
||||
private final MapManager mapManager;
|
||||
private final ImageManager imageManager;
|
||||
private final EntitySetManager entitySetManager;
|
||||
private final CharacterSetManager characterSetManager;
|
||||
private final FontManager fontManager;
|
||||
private final EntityManager entityManager;
|
||||
private final CharacterManager characterManager;
|
||||
private final AnimationManager animationManager;
|
||||
private final ClassLoader classLoader;
|
||||
private final Inflater inflater;
|
||||
@@ -56,7 +56,7 @@ public class DefaultContextManager implements ContextManager {
|
||||
project.getTileSetAssets().forEach(tileSetManager::registerAsset);
|
||||
project.getMapAssets().forEach(mapManager::registerAsset);
|
||||
project.getImageAssets().forEach(imageManager::registerAsset);
|
||||
project.getEntitySetAssets().forEach(entitySetManager::registerAsset);
|
||||
project.getCharacterSetAssets().forEach(characterSetManager::registerAsset);
|
||||
project.getAnimationAssets().forEach(animationManager::registerAsset);
|
||||
project.getFontAssets().forEach(fontManager::registerAsset);
|
||||
project.getWidgetDefinitionAssets().forEach(widgetDefinitionManager::registerAsset);
|
||||
@@ -68,8 +68,8 @@ public class DefaultContextManager implements ContextManager {
|
||||
|
||||
log.info("Building context up");
|
||||
var context = DefaultContext.builder()
|
||||
.engine(engine)
|
||||
.entityManager(entityManager)
|
||||
.engine(engine)
|
||||
.characterManager(characterManager)
|
||||
.animationManager(animationManager)
|
||||
.imageManager(imageManager)
|
||||
.mapManager(mapManager)
|
||||
|
||||
@@ -3,9 +3,9 @@ package com.bartlomiejpluta.base.engine.context.model;
|
||||
import com.bartlomiejpluta.base.api.animation.Animation;
|
||||
import com.bartlomiejpluta.base.api.audio.Sound;
|
||||
import com.bartlomiejpluta.base.api.camera.Camera;
|
||||
import com.bartlomiejpluta.base.api.character.Character;
|
||||
import com.bartlomiejpluta.base.api.context.Context;
|
||||
import com.bartlomiejpluta.base.api.context.GamePauseEvent;
|
||||
import com.bartlomiejpluta.base.api.entity.Entity;
|
||||
import com.bartlomiejpluta.base.api.event.Event;
|
||||
import com.bartlomiejpluta.base.api.event.EventType;
|
||||
import com.bartlomiejpluta.base.api.gui.GUI;
|
||||
@@ -22,7 +22,7 @@ import com.bartlomiejpluta.base.engine.gui.manager.WidgetDefinitionManager;
|
||||
import com.bartlomiejpluta.base.engine.gui.render.NanoVGGUI;
|
||||
import com.bartlomiejpluta.base.engine.gui.xml.inflater.Inflater;
|
||||
import com.bartlomiejpluta.base.engine.world.animation.manager.AnimationManager;
|
||||
import com.bartlomiejpluta.base.engine.world.entity.manager.EntityManager;
|
||||
import com.bartlomiejpluta.base.engine.world.character.manager.CharacterManager;
|
||||
import com.bartlomiejpluta.base.engine.world.image.manager.ImageManager;
|
||||
import com.bartlomiejpluta.base.engine.world.map.manager.MapManager;
|
||||
import com.bartlomiejpluta.base.engine.world.map.model.DefaultGameMap;
|
||||
@@ -50,7 +50,7 @@ public class DefaultContext implements Context {
|
||||
private final GameEngine engine;
|
||||
|
||||
@NonNull
|
||||
private final EntityManager entityManager;
|
||||
private final CharacterManager characterManager;
|
||||
|
||||
@NonNull
|
||||
private final AnimationManager animationManager;
|
||||
@@ -146,9 +146,9 @@ public class DefaultContext implements Context {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Entity createEntity(String entitySetUid) {
|
||||
log.info("Creating new entity with UID: [{}]", entitySetUid);
|
||||
return entityManager.createEntity(entitySetUid);
|
||||
public Character createCharacter(String characterSetUid) {
|
||||
log.info("Creating new character with UID: [{}]", characterSetUid);
|
||||
return characterManager.createCharacter(characterSetUid);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -4,7 +4,7 @@ import com.bartlomiejpluta.base.engine.audio.asset.SoundAsset;
|
||||
import com.bartlomiejpluta.base.engine.gui.asset.FontAsset;
|
||||
import com.bartlomiejpluta.base.engine.gui.asset.WidgetDefinitionAsset;
|
||||
import com.bartlomiejpluta.base.engine.world.animation.asset.AnimationAsset;
|
||||
import com.bartlomiejpluta.base.engine.world.entity.asset.EntitySetAsset;
|
||||
import com.bartlomiejpluta.base.engine.world.character.asset.CharacterSetAsset;
|
||||
import com.bartlomiejpluta.base.engine.world.image.asset.ImageAsset;
|
||||
import com.bartlomiejpluta.base.engine.world.map.asset.GameMapAsset;
|
||||
import com.bartlomiejpluta.base.engine.world.tileset.asset.TileSetAsset;
|
||||
@@ -34,7 +34,7 @@ public class Project {
|
||||
private final List<ImageAsset> imageAssets;
|
||||
|
||||
@NonNull
|
||||
private final List<EntitySetAsset> entitySetAssets;
|
||||
private final List<CharacterSetAsset> characterSetAssets;
|
||||
|
||||
@NonNull
|
||||
private final List<AnimationAsset> animationAssets;
|
||||
|
||||
@@ -5,7 +5,7 @@ import com.bartlomiejpluta.base.engine.gui.asset.FontAsset;
|
||||
import com.bartlomiejpluta.base.engine.gui.asset.WidgetDefinitionAsset;
|
||||
import com.bartlomiejpluta.base.engine.project.model.Project;
|
||||
import com.bartlomiejpluta.base.engine.world.animation.asset.AnimationAsset;
|
||||
import com.bartlomiejpluta.base.engine.world.entity.asset.EntitySetAsset;
|
||||
import com.bartlomiejpluta.base.engine.world.character.asset.CharacterSetAsset;
|
||||
import com.bartlomiejpluta.base.engine.world.image.asset.ImageAsset;
|
||||
import com.bartlomiejpluta.base.engine.world.map.asset.GameMapAsset;
|
||||
import com.bartlomiejpluta.base.engine.world.tileset.asset.TileSetAsset;
|
||||
@@ -24,12 +24,12 @@ public class ProtobufProjectDeserializer extends ProjectDeserializer {
|
||||
var proto = ProjectProto.Project.parseFrom(input);
|
||||
|
||||
return Project.builder()
|
||||
.name(proto.getName())
|
||||
.runner(proto.getRunner())
|
||||
.tileSetAssets(proto.getTileSetsList().stream().map(this::parseTileSetAsset).collect(toList()))
|
||||
.mapAssets(proto.getMapsList().stream().map(this::parseGameMapAsset).collect(toList()))
|
||||
.imageAssets(proto.getImagesList().stream().map(this::parseImageAsset).collect(toList()))
|
||||
.entitySetAssets(proto.getEntitySetsList().stream().map(this::parseEntitySetAsset).collect(toList()))
|
||||
.name(proto.getName())
|
||||
.runner(proto.getRunner())
|
||||
.tileSetAssets(proto.getTileSetsList().stream().map(this::parseTileSetAsset).collect(toList()))
|
||||
.mapAssets(proto.getMapsList().stream().map(this::parseGameMapAsset).collect(toList()))
|
||||
.imageAssets(proto.getImagesList().stream().map(this::parseImageAsset).collect(toList()))
|
||||
.characterSetAssets(proto.getEntitySetsList().stream().map(this::parseEntitySetAsset).collect(toList()))
|
||||
.animationAssets(proto.getAnimationsList().stream().map(this::parseAnimationAsset).collect(toList()))
|
||||
.fontAssets(proto.getFontsList().stream().map(this::parseFontAsset).collect(toList()))
|
||||
.widgetDefinitionAssets(proto.getWidgetsList().stream().map(this::parseWidgetAsset).collect(toList()))
|
||||
@@ -49,8 +49,8 @@ public class ProtobufProjectDeserializer extends ProjectDeserializer {
|
||||
return new ImageAsset(proto.getUid(), proto.getSource());
|
||||
}
|
||||
|
||||
private EntitySetAsset parseEntitySetAsset(ProjectProto.EntitySetAsset proto) {
|
||||
return new EntitySetAsset(proto.getUid(), proto.getSource(), proto.getRows(), proto.getColumns());
|
||||
private CharacterSetAsset parseEntitySetAsset(ProjectProto.EntitySetAsset proto) {
|
||||
return new CharacterSetAsset(proto.getUid(), proto.getSource(), proto.getRows(), proto.getColumns());
|
||||
}
|
||||
|
||||
private FontAsset parseFontAsset(ProjectProto.FontAsset proto) {
|
||||
|
||||
@@ -46,7 +46,7 @@ public class DefaultAnimationManager implements AnimationManager {
|
||||
var asset = assets.get(uid);
|
||||
|
||||
if (asset == null) {
|
||||
throw new AppException("The entity set asset with UID: [%s] does not exist", uid);
|
||||
throw new AppException("The animation asset with UID: [%s] does not exist", uid);
|
||||
}
|
||||
|
||||
var animationFrames = frames.computeIfAbsent(asset.framesSignature(),
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
package com.bartlomiejpluta.base.engine.world.entity.asset;
|
||||
package com.bartlomiejpluta.base.engine.world.character.asset;
|
||||
|
||||
import com.bartlomiejpluta.base.engine.common.asset.Asset;
|
||||
import lombok.Getter;
|
||||
import lombok.NonNull;
|
||||
|
||||
@Getter
|
||||
public class EntitySetAsset extends Asset {
|
||||
public class CharacterSetAsset extends Asset {
|
||||
private final int rows;
|
||||
private final int columns;
|
||||
|
||||
public EntitySetAsset(@NonNull String uid, @NonNull String source, int rows, int columns) {
|
||||
public CharacterSetAsset(@NonNull String uid, @NonNull String source, int rows, int columns) {
|
||||
super(uid, source);
|
||||
this.rows = rows;
|
||||
this.columns = columns;
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.bartlomiejpluta.base.engine.world.entity.config;
|
||||
package com.bartlomiejpluta.base.engine.world.character.config;
|
||||
|
||||
import com.bartlomiejpluta.base.api.move.Direction;
|
||||
import lombok.Data;
|
||||
@@ -9,8 +9,8 @@ import java.util.Map;
|
||||
|
||||
@Data
|
||||
@Configuration
|
||||
@ConfigurationProperties(prefix = "app.sprite.entity")
|
||||
public class EntitySpriteConfiguration {
|
||||
@ConfigurationProperties(prefix = "app.sprite.character")
|
||||
public class CharacterSpriteConfiguration {
|
||||
private int defaultSpriteColumn;
|
||||
private Map<Direction, Integer> spriteDirectionRows;
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package com.bartlomiejpluta.base.engine.world.character.manager;
|
||||
|
||||
import com.bartlomiejpluta.base.api.character.Character;
|
||||
import com.bartlomiejpluta.base.engine.common.init.Initializable;
|
||||
import com.bartlomiejpluta.base.internal.gc.Cleanable;
|
||||
|
||||
public interface CharacterManager extends Initializable, Cleanable {
|
||||
Character createCharacter(String characterSetUid);
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package com.bartlomiejpluta.base.engine.world.character.manager;
|
||||
|
||||
import com.bartlomiejpluta.base.engine.common.manager.AssetManager;
|
||||
import com.bartlomiejpluta.base.engine.core.gl.object.material.Material;
|
||||
import com.bartlomiejpluta.base.engine.world.character.asset.CharacterSetAsset;
|
||||
|
||||
public interface CharacterSetManager extends AssetManager<CharacterSetAsset, Material> {
|
||||
}
|
||||
@@ -1,11 +1,11 @@
|
||||
package com.bartlomiejpluta.base.engine.world.entity.manager;
|
||||
package com.bartlomiejpluta.base.engine.world.character.manager;
|
||||
|
||||
import com.bartlomiejpluta.base.api.entity.Entity;
|
||||
import com.bartlomiejpluta.base.api.character.Character;
|
||||
import com.bartlomiejpluta.base.api.move.Direction;
|
||||
import com.bartlomiejpluta.base.engine.core.gl.object.mesh.Mesh;
|
||||
import com.bartlomiejpluta.base.engine.util.mesh.MeshManager;
|
||||
import com.bartlomiejpluta.base.engine.world.entity.config.EntitySpriteConfiguration;
|
||||
import com.bartlomiejpluta.base.engine.world.entity.model.DefaultEntity;
|
||||
import com.bartlomiejpluta.base.engine.world.character.config.CharacterSpriteConfiguration;
|
||||
import com.bartlomiejpluta.base.engine.world.character.model.DefaultCharacter;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.joml.Vector2f;
|
||||
import org.joml.Vector2fc;
|
||||
@@ -19,9 +19,9 @@ import static java.util.stream.Collectors.toUnmodifiableMap;
|
||||
|
||||
@Slf4j
|
||||
@Component
|
||||
public class DefaultEntityManager implements EntityManager {
|
||||
public class DefaultCharacterManager implements CharacterManager {
|
||||
private final MeshManager meshManager;
|
||||
private final EntitySetManager entitySetManager;
|
||||
private final CharacterSetManager characterSetManager;
|
||||
|
||||
private final int defaultSpriteColumn;
|
||||
private final Map<Direction, Integer> spriteDirectionRows;
|
||||
@@ -30,17 +30,17 @@ public class DefaultEntityManager implements EntityManager {
|
||||
private Mesh mesh;
|
||||
|
||||
@Autowired
|
||||
public DefaultEntityManager(MeshManager meshManager, EntitySetManager entitySetManager, EntitySpriteConfiguration configuration) {
|
||||
public DefaultCharacterManager(MeshManager meshManager, CharacterSetManager characterSetManager, CharacterSpriteConfiguration configuration) {
|
||||
this.meshManager = meshManager;
|
||||
this.entitySetManager = entitySetManager;
|
||||
this.characterSetManager = characterSetManager;
|
||||
|
||||
this.spriteDirectionRows = configuration.getSpriteDirectionRows();
|
||||
|
||||
defaultSpriteColumn = configuration.getDefaultSpriteColumn();
|
||||
this.spriteDefaultRows = spriteDirectionRows
|
||||
.entrySet()
|
||||
.stream()
|
||||
.collect(toUnmodifiableMap(Entry::getKey, entry -> new Vector2f(defaultSpriteColumn, entry.getValue())));
|
||||
.entrySet()
|
||||
.stream()
|
||||
.collect(toUnmodifiableMap(Entry::getKey, entry -> new Vector2f(defaultSpriteColumn, entry.getValue())));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -49,8 +49,8 @@ public class DefaultEntityManager implements EntityManager {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Entity createEntity(String entitySetUid) {
|
||||
return new DefaultEntity(mesh, entitySetManager, defaultSpriteColumn, spriteDirectionRows, spriteDefaultRows, entitySetUid);
|
||||
public Character createCharacter(String characterSetUid) {
|
||||
return new DefaultCharacter(mesh, characterSetManager, defaultSpriteColumn, spriteDirectionRows, spriteDefaultRows, characterSetUid);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -1,10 +1,10 @@
|
||||
package com.bartlomiejpluta.base.engine.world.entity.manager;
|
||||
package com.bartlomiejpluta.base.engine.world.character.manager;
|
||||
|
||||
import com.bartlomiejpluta.base.engine.core.gl.object.material.Material;
|
||||
import com.bartlomiejpluta.base.engine.core.gl.object.texture.TextureManager;
|
||||
import com.bartlomiejpluta.base.engine.error.AppException;
|
||||
import com.bartlomiejpluta.base.engine.project.config.ProjectConfiguration;
|
||||
import com.bartlomiejpluta.base.engine.world.entity.asset.EntitySetAsset;
|
||||
import com.bartlomiejpluta.base.engine.world.character.asset.CharacterSetAsset;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -16,14 +16,14 @@ import java.util.Map;
|
||||
@Slf4j
|
||||
@Component
|
||||
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
|
||||
public class DefaultEntitySetManager implements EntitySetManager {
|
||||
public class DefaultCharacterSetManager implements CharacterSetManager {
|
||||
private final TextureManager textureManager;
|
||||
private final Map<String, EntitySetAsset> assets = new HashMap<>();
|
||||
private final Map<String, CharacterSetAsset> assets = new HashMap<>();
|
||||
private final ProjectConfiguration configuration;
|
||||
|
||||
@Override
|
||||
public void registerAsset(EntitySetAsset asset) {
|
||||
log.info("Registering [{}] entity set asset under UID: [{}]", asset.getSource(), asset.getUid());
|
||||
public void registerAsset(CharacterSetAsset asset) {
|
||||
log.info("Registering [{}] character set asset under UID: [{}]", asset.getSource(), asset.getUid());
|
||||
assets.put(asset.getUid(), asset);
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ public class DefaultEntitySetManager implements EntitySetManager {
|
||||
var asset = assets.get(uid);
|
||||
|
||||
if (asset == null) {
|
||||
throw new AppException("The entity set asset with UID: [%s] does not exist", uid);
|
||||
throw new AppException("The character set asset with UID: [%s] does not exist", uid);
|
||||
}
|
||||
|
||||
var source = configuration.projectFile("entsets", asset.getSource());
|
||||
@@ -1,13 +1,13 @@
|
||||
package com.bartlomiejpluta.base.engine.world.entity.model;
|
||||
package com.bartlomiejpluta.base.engine.world.character.model;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
public class EntityInstantAnimation {
|
||||
public class CharacterInstantAnimation {
|
||||
public enum State {RUNNING, COMPLETED}
|
||||
|
||||
private final DefaultEntity entity;
|
||||
private final DefaultCharacter character;
|
||||
private final int firstFrame;
|
||||
private final int lastFrame;
|
||||
|
||||
@@ -16,19 +16,19 @@ public class EntityInstantAnimation {
|
||||
@Getter
|
||||
private final CompletableFuture<Void> future = new CompletableFuture<>();
|
||||
|
||||
EntityInstantAnimation(DefaultEntity entity, int firstFrame) {
|
||||
this.entity = entity;
|
||||
CharacterInstantAnimation(DefaultCharacter character, int firstFrame) {
|
||||
this.character = character;
|
||||
this.firstFrame = firstFrame;
|
||||
this.lastFrame = entity.getMaterial().getTexture().getColumns() - 1;
|
||||
this.lastFrame = character.getMaterial().getTexture().getColumns() - 1;
|
||||
}
|
||||
|
||||
public State update() {
|
||||
if (!finished && entity.currentFrame() == lastFrame) {
|
||||
if (!finished && character.currentFrame() == lastFrame) {
|
||||
finished = true;
|
||||
return State.RUNNING;
|
||||
}
|
||||
|
||||
if (finished && entity.currentFrame() == firstFrame) {
|
||||
if (finished && character.currentFrame() == firstFrame) {
|
||||
future.complete(null);
|
||||
|
||||
return State.COMPLETED;
|
||||
@@ -1,16 +1,16 @@
|
||||
package com.bartlomiejpluta.base.engine.world.entity.model;
|
||||
package com.bartlomiejpluta.base.engine.world.character.model;
|
||||
|
||||
import com.bartlomiejpluta.base.api.entity.Entity;
|
||||
import com.bartlomiejpluta.base.api.character.Character;
|
||||
import com.bartlomiejpluta.base.api.event.Event;
|
||||
import com.bartlomiejpluta.base.api.event.EventType;
|
||||
import com.bartlomiejpluta.base.api.map.layer.object.ObjectLayer;
|
||||
import com.bartlomiejpluta.base.api.move.CharacterMovement;
|
||||
import com.bartlomiejpluta.base.api.move.Direction;
|
||||
import com.bartlomiejpluta.base.api.move.EntityMovement;
|
||||
import com.bartlomiejpluta.base.api.move.Movement;
|
||||
import com.bartlomiejpluta.base.engine.core.gl.object.material.Material;
|
||||
import com.bartlomiejpluta.base.engine.core.gl.object.mesh.Mesh;
|
||||
import com.bartlomiejpluta.base.engine.error.AppException;
|
||||
import com.bartlomiejpluta.base.engine.world.entity.manager.EntitySetManager;
|
||||
import com.bartlomiejpluta.base.engine.world.character.manager.CharacterSetManager;
|
||||
import com.bartlomiejpluta.base.engine.world.movement.MovableSprite;
|
||||
import com.bartlomiejpluta.base.lib.event.EventHandler;
|
||||
import lombok.EqualsAndHashCode;
|
||||
@@ -18,7 +18,6 @@ import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.joml.Vector2f;
|
||||
import org.joml.Vector2fc;
|
||||
import org.joml.Vector2i;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.Map;
|
||||
@@ -29,9 +28,9 @@ import java.util.function.Consumer;
|
||||
import static java.util.Objects.requireNonNull;
|
||||
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class DefaultEntity extends MovableSprite implements Entity {
|
||||
public class DefaultCharacter extends MovableSprite implements Character {
|
||||
private final int defaultSpriteColumn;
|
||||
private final EntitySetManager entitySetManager;
|
||||
private final CharacterSetManager characterSetManager;
|
||||
private final Map<Direction, Integer> spriteDirectionRows;
|
||||
private final Map<Direction, Vector2fc> spriteDefaultRows;
|
||||
private final Vector2f entityScale = new Vector2f(1, 1);
|
||||
@@ -55,12 +54,12 @@ public class DefaultEntity extends MovableSprite implements Entity {
|
||||
|
||||
private boolean animationEnabled = true;
|
||||
|
||||
private final Queue<EntityInstantAnimation> instantAnimations = new LinkedList<>();
|
||||
private final Queue<CharacterInstantAnimation> instantAnimations = new LinkedList<>();
|
||||
|
||||
public DefaultEntity(Mesh mesh, EntitySetManager entitySetManager, int defaultSpriteColumn, Map<Direction, Integer> spriteDirectionRows, Map<Direction, Vector2fc> spriteDefaultRows, String entitySetUid) {
|
||||
super(mesh, createMaterial(entitySetManager, entitySetUid));
|
||||
public DefaultCharacter(Mesh mesh, CharacterSetManager characterSetManager, int defaultSpriteColumn, Map<Direction, Integer> spriteDirectionRows, Map<Direction, Vector2fc> spriteDefaultRows, String entitySetUid) {
|
||||
super(mesh, createMaterial(characterSetManager, entitySetUid));
|
||||
this.defaultSpriteColumn = defaultSpriteColumn;
|
||||
this.entitySetManager = entitySetManager;
|
||||
this.characterSetManager = characterSetManager;
|
||||
this.spriteDirectionRows = spriteDirectionRows;
|
||||
this.faceDirection = Direction.DOWN;
|
||||
this.spriteDefaultRows = spriteDefaultRows;
|
||||
@@ -72,17 +71,8 @@ public class DefaultEntity extends MovableSprite implements Entity {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void changeEntitySet(String entitySetUid) {
|
||||
this.material = createMaterial(entitySetManager, entitySetUid);
|
||||
var texture = this.material.getTexture();
|
||||
|
||||
if (texture != null) {
|
||||
this.entitySetSize = texture.getSpriteSize();
|
||||
super.setScale(entitySetSize.x() * entityScale.x, entitySetSize.y() * entityScale.y);
|
||||
} else {
|
||||
this.entitySetSize = null;
|
||||
}
|
||||
private static Material createMaterial(CharacterSetManager characterSetManager, String entitySetUid) {
|
||||
return entitySetUid != null ? characterSetManager.loadObject(requireNonNull(entitySetUid)) : Material.colored(0, 0, 0, 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -134,16 +124,24 @@ public class DefaultEntity extends MovableSprite implements Entity {
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Void> performInstantAnimation() {
|
||||
var animation = new EntityInstantAnimation(this, defaultSpriteColumn);
|
||||
instantAnimations.add(animation);
|
||||
public void changeCharacterSet(String entitySetUid) {
|
||||
this.material = createMaterial(characterSetManager, entitySetUid);
|
||||
var texture = this.material.getTexture();
|
||||
|
||||
return animation.getFuture();
|
||||
if (texture != null) {
|
||||
this.entitySetSize = texture.getSpriteSize();
|
||||
super.setScale(entitySetSize.x() * entityScale.x, entitySetSize.y() * entityScale.y);
|
||||
} else {
|
||||
this.entitySetSize = null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Movement prepareMovement(Direction direction) {
|
||||
return new EntityMovement(this, direction);
|
||||
public CompletableFuture<Void> performInstantAnimation() {
|
||||
var animation = new CharacterInstantAnimation(this, defaultSpriteColumn);
|
||||
instantAnimations.add(animation);
|
||||
|
||||
return animation.getFuture();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -162,21 +160,6 @@ public class DefaultEntity extends MovableSprite implements Entity {
|
||||
setDefaultAnimationFrame();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int chebyshevDistance(Entity other) {
|
||||
return chebyshevDistance(other.getCoordinates());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int manhattanDistance(Entity other) {
|
||||
return manhattanDistance(other.getCoordinates());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Direction getDirectionTowards(Entity target) {
|
||||
return Direction.ofVector(target.getCoordinates().sub(getCoordinates(), new Vector2i()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAdd(ObjectLayer layer) {
|
||||
this.layer = layer;
|
||||
@@ -187,10 +170,15 @@ public class DefaultEntity extends MovableSprite implements Entity {
|
||||
this.layer = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Movement prepareMovement(Direction direction) {
|
||||
return new CharacterMovement(this, direction);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setScaleX(float scaleX) {
|
||||
if (entitySetSize == null) {
|
||||
throw new AppException("Cannot change Entity scale if no Entity Set is provided");
|
||||
throw new AppException("Cannot change Character scale if no Character Set is provided");
|
||||
}
|
||||
|
||||
this.entityScale.x = scaleX;
|
||||
@@ -200,7 +188,7 @@ public class DefaultEntity extends MovableSprite implements Entity {
|
||||
@Override
|
||||
public void setScaleY(float scaleY) {
|
||||
if (entitySetSize == null) {
|
||||
throw new AppException("Cannot change Entity scale if no Entity Set is provided");
|
||||
throw new AppException("Cannot change Character scale if no Character Set is provided");
|
||||
}
|
||||
|
||||
this.entityScale.y = scaleY;
|
||||
@@ -210,7 +198,7 @@ public class DefaultEntity extends MovableSprite implements Entity {
|
||||
@Override
|
||||
public void setScale(float scale) {
|
||||
if (entitySetSize == null) {
|
||||
throw new AppException("Cannot change Entity scale if no Entity Set is provided");
|
||||
throw new AppException("Cannot change Character scale if no Character Set is provided");
|
||||
}
|
||||
|
||||
this.entityScale.x = scale;
|
||||
@@ -218,17 +206,6 @@ public class DefaultEntity extends MovableSprite implements Entity {
|
||||
super.setScale(entitySetSize.x() * scale, entitySetSize.y() * scale);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setScale(float scaleX, float scaleY) {
|
||||
if (entitySetSize == null) {
|
||||
throw new AppException("Cannot change Entity scale if no Entity Set is provided");
|
||||
}
|
||||
|
||||
this.entityScale.x = scaleX;
|
||||
this.entityScale.y = scaleY;
|
||||
super.setScale(entitySetSize.x() * scaleX, entitySetSize.y() * scaleY);
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getScaleX() {
|
||||
return entityScale.x;
|
||||
@@ -255,20 +232,27 @@ public class DefaultEntity extends MovableSprite implements Entity {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(float dt) {
|
||||
super.update(dt);
|
||||
|
||||
var instantAnimation = instantAnimations.peek();
|
||||
if (instantAnimation != null && instantAnimation.update() == EntityInstantAnimation.State.COMPLETED) {
|
||||
instantAnimations.poll();
|
||||
public void setScale(float scaleX, float scaleY) {
|
||||
if (entitySetSize == null) {
|
||||
throw new AppException("Cannot change Character scale if no Character Set is provided");
|
||||
}
|
||||
|
||||
this.entityScale.x = scaleX;
|
||||
this.entityScale.y = scaleY;
|
||||
super.setScale(entitySetSize.x() * scaleX, entitySetSize.y() * scaleY);
|
||||
}
|
||||
|
||||
int currentFrame() {
|
||||
return currentAnimationFrame;
|
||||
}
|
||||
|
||||
private static Material createMaterial(EntitySetManager entitySetManager, String entitySetUid) {
|
||||
return entitySetUid != null ? entitySetManager.loadObject(requireNonNull(entitySetUid)) : Material.colored(0, 0, 0, 0);
|
||||
@Override
|
||||
public void update(float dt) {
|
||||
super.update(dt);
|
||||
|
||||
var instantAnimation = instantAnimations.peek();
|
||||
if (instantAnimation != null && instantAnimation.update() == CharacterInstantAnimation.State.COMPLETED) {
|
||||
instantAnimations.poll();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
package com.bartlomiejpluta.base.engine.world.entity.manager;
|
||||
|
||||
import com.bartlomiejpluta.base.api.entity.Entity;
|
||||
import com.bartlomiejpluta.base.engine.common.init.Initializable;
|
||||
import com.bartlomiejpluta.base.internal.gc.Cleanable;
|
||||
|
||||
public interface EntityManager extends Initializable, Cleanable {
|
||||
Entity createEntity(String entitySetUid);
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
package com.bartlomiejpluta.base.engine.world.entity.manager;
|
||||
|
||||
import com.bartlomiejpluta.base.engine.common.manager.AssetManager;
|
||||
import com.bartlomiejpluta.base.engine.core.gl.object.material.Material;
|
||||
import com.bartlomiejpluta.base.engine.world.entity.asset.EntitySetAsset;
|
||||
|
||||
public interface EntitySetManager extends AssetManager<EntitySetAsset, Material> {
|
||||
}
|
||||
@@ -1,9 +1,9 @@
|
||||
package com.bartlomiejpluta.base.engine.world.location;
|
||||
|
||||
import com.bartlomiejpluta.base.api.location.Locationable;
|
||||
import com.bartlomiejpluta.base.api.move.Direction;
|
||||
import com.bartlomiejpluta.base.engine.core.gl.object.material.Material;
|
||||
import com.bartlomiejpluta.base.engine.core.gl.object.mesh.Mesh;
|
||||
import com.bartlomiejpluta.base.engine.world.movement.MovableSprite;
|
||||
import com.bartlomiejpluta.base.engine.world.object.Sprite;
|
||||
import com.bartlomiejpluta.base.util.math.Distance;
|
||||
import lombok.EqualsAndHashCode;
|
||||
@@ -88,6 +88,11 @@ public abstract class LocationableSprite extends Sprite implements Locationable
|
||||
adjustPosition();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Direction getDirectionTowards(Locationable target) {
|
||||
return Direction.ofVector(target.getCoordinates().sub(getCoordinates(), new Vector2i()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int chebyshevDistance(Vector2ic coordinates) {
|
||||
return Distance.chebyshev(this.coordinates, coordinates);
|
||||
@@ -97,4 +102,14 @@ public abstract class LocationableSprite extends Sprite implements Locationable
|
||||
public int manhattanDistance(Vector2ic coordinates) {
|
||||
return Distance.manhattan(this.coordinates, coordinates);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int chebyshevDistance(Locationable other) {
|
||||
return Distance.chebyshev(this.coordinates, other.getCoordinates());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int manhattanDistance(Locationable other) {
|
||||
return Distance.manhattan(this.coordinates, other.getCoordinates());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ import com.bartlomiejpluta.base.api.event.Event;
|
||||
import com.bartlomiejpluta.base.api.map.layer.object.ObjectLayer;
|
||||
import com.bartlomiejpluta.base.api.map.layer.object.PassageAbility;
|
||||
import com.bartlomiejpluta.base.api.map.model.GameMap;
|
||||
import com.bartlomiejpluta.base.api.move.Movable;
|
||||
import com.bartlomiejpluta.base.api.move.Movement;
|
||||
import com.bartlomiejpluta.base.api.screen.Screen;
|
||||
import com.bartlomiejpluta.base.engine.world.map.layer.base.BaseLayer;
|
||||
@@ -93,10 +94,12 @@ public class DefaultObjectLayer extends BaseLayer implements ObjectLayer {
|
||||
return false;
|
||||
}
|
||||
|
||||
// The tile is empty, however another entity is moving on it
|
||||
var otherMovement = entity.getMovement();
|
||||
if (otherMovement != null && otherMovement.getTo().equals(tileCoordinates)) {
|
||||
return false;
|
||||
if (entity instanceof Movable) {
|
||||
// The tile is empty, however another entity is moving on it
|
||||
var otherMovement = ((Movable) entity).getMovement();
|
||||
if (otherMovement != null && otherMovement.getTo().equals(tileCoordinates)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -140,16 +143,16 @@ public class DefaultObjectLayer extends BaseLayer implements ObjectLayer {
|
||||
|
||||
@Override
|
||||
public void render(Screen screen, Camera camera, ShaderManager shaderManager) {
|
||||
entities.sort(this::compareObjects);
|
||||
entities.sort(this::compareEntities);
|
||||
|
||||
for (var object : entities) {
|
||||
object.render(screen, camera, shaderManager);
|
||||
for (var entity : entities) {
|
||||
entity.render(screen, camera, shaderManager);
|
||||
}
|
||||
|
||||
super.render(screen, camera, shaderManager);
|
||||
}
|
||||
|
||||
private int compareObjects(Entity a, Entity b) {
|
||||
private int compareEntities(Entity a, Entity b) {
|
||||
var z = compare(a.getZIndex(), b.getZIndex());
|
||||
return z == 0 ? compare(a.getPosition().y(), b.getPosition().y()) : z;
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ app:
|
||||
database-script-file: /database/data.sql
|
||||
|
||||
sprite:
|
||||
entity:
|
||||
character:
|
||||
default-sprite-column: 0
|
||||
|
||||
sprite-direction-rows:
|
||||
|
||||
Reference in New Issue
Block a user