Create MapHandler API scaffolding
This commit is contained in:
@@ -47,13 +47,17 @@ public class GameMap implements Renderable, Updatable {
|
||||
@Getter
|
||||
private final Vector2f stepSize;
|
||||
|
||||
public GameMap(TileSet tileSet, int rows, int columns) {
|
||||
@Getter
|
||||
private final String handler;
|
||||
|
||||
public GameMap(TileSet tileSet, int rows, int columns, String handler) {
|
||||
this.tileSet = tileSet;
|
||||
this.rows = rows;
|
||||
this.columns = columns;
|
||||
this.stepSize = new Vector2f(tileSet.getTileSet().getSpriteSize());
|
||||
this.width = columns * stepSize.x;
|
||||
this.height = rows * stepSize.y;
|
||||
this.handler = handler;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -27,7 +27,7 @@ public class ProtobufMapDeserializer extends MapDeserializer {
|
||||
protected GameMap parse(InputStream input) throws Exception {
|
||||
var proto = GameMapProto.GameMap.parseFrom(input);
|
||||
var tileSet = tileSetManager.loadTileSet(proto.getTileSetUID());
|
||||
var map = new GameMap(tileSet, proto.getRows(), proto.getColumns());
|
||||
var map = new GameMap(tileSet, proto.getRows(), proto.getColumns(), proto.getHandler());
|
||||
|
||||
proto.getLayersList().forEach(layer -> deserializeLayer(map, layer));
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.bartlomiejpluta.base.game.project.model;
|
||||
|
||||
import com.bartlomiejpluta.base.api.context.Context;
|
||||
import com.bartlomiejpluta.base.api.map.MapHandler;
|
||||
import com.bartlomiejpluta.base.core.gl.object.texture.TextureManager;
|
||||
import com.bartlomiejpluta.base.core.gl.render.Renderable;
|
||||
import com.bartlomiejpluta.base.core.gl.shader.manager.ShaderManager;
|
||||
@@ -11,9 +12,11 @@ import com.bartlomiejpluta.base.core.world.camera.Camera;
|
||||
import com.bartlomiejpluta.base.game.image.manager.ImageManager;
|
||||
import com.bartlomiejpluta.base.game.map.manager.MapManager;
|
||||
import com.bartlomiejpluta.base.game.map.model.GameMap;
|
||||
import com.bartlomiejpluta.base.game.project.loader.ClassLoader;
|
||||
import com.bartlomiejpluta.base.game.tileset.manager.TileSetManager;
|
||||
import com.bartlomiejpluta.base.game.world.entity.manager.EntityManager;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.SneakyThrows;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@@ -26,12 +29,19 @@ public class RenderableContext implements Context, Updatable, Renderable {
|
||||
private final EntityManager entityManager;
|
||||
private final ImageManager imageManager;
|
||||
private final MapManager mapManager;
|
||||
private final ClassLoader classLoader;
|
||||
|
||||
private GameMap map;
|
||||
|
||||
@SneakyThrows
|
||||
@Override
|
||||
public void openMap(String mapUid) {
|
||||
map = mapManager.loadMap(mapUid);
|
||||
|
||||
var handlerClass = classLoader.<MapHandler>loadClass(map.getHandler());
|
||||
var handler = handlerClass.getConstructor().newInstance();
|
||||
|
||||
handler.init(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user