Skip to content

Commit

Permalink
Merge pull request #108 from kakaragame/engine_pre5
Browse files Browse the repository at this point in the history
Update Kakara to Pre5
  • Loading branch information
Wyatt J Herkamp authored Feb 28, 2021
2 parents ab76af9 + 24c1dde commit 1a90eb6
Show file tree
Hide file tree
Showing 20 changed files with 285 additions and 203 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ start.bat

# Ignore Gradle build output directory
build/
engine.jar
2 changes: 1 addition & 1 deletion client/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ dependencies {
implementation(group = "me.ryandw11", name = "ods", version = "1.0.4")
implementation(group = "me.ryandw11", name = "ODSCompressionPlus", version = "1.0.1")
//Engine
compileOnly (group = "org.kakara", name = "engine", version = engineVersion)
compileOnly(group = "org.kakara", name = "engine", version = engineVersion);
compileOnly("io.imgui.java:binding:1.77-0.17.2")
compileOnly("io.imgui.java:lwjgl3:1.77-0.17.2")
//Core
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package org.kakara.client.engine.item;

import org.kakara.engine.components.Component;
import org.kakara.engine.physics.collision.BoxCollider;

public class HorizontalRotationComponent extends Component {
@Override
public void start() {

}

@Override
public void update() {
getGameItem().transform.getRotation().rotateY(0.01f);

}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public void render(Inventory inventory, Texture inventoryBackground, Set<MenuEle
((MainGameScene) scene).add(inventoryCanvas);

//TODO render Inventory
scene.setCurserStatus(true);
scene.setCursorStatus(true);
}

@Override
Expand All @@ -41,7 +41,7 @@ public void redraw(Inventory inventory, Texture inventoryBackground, Set<MenuEle
public void close() {
Scene scene = GameHandler.getInstance().getSceneManager().getCurrentScene();
if (!(scene instanceof MainGameScene)) return;
scene.setCurserStatus(false);
scene.setCursorStatus(false);

//This will logically remove all UICanvas's by GameEngineInventoryController
//DONT BE STUPID!
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,21 @@
import org.kakara.engine.gameitems.mesh.AtlasMesh;
import org.kakara.engine.gameitems.mesh.Mesh;
import org.kakara.engine.math.Vector2;
import org.kakara.engine.renderobjects.RenderTexture;
import org.kakara.engine.renderobjects.renderlayouts.BlockLayout;
import org.kakara.engine.scene.Scene;
import org.kakara.engine.ui.UserInterface;
import org.kakara.engine.ui.canvases.ComponentCanvas;
import org.kakara.engine.ui.canvases.ObjectCanvas;
import org.kakara.engine.ui.components.Panel;
import org.kakara.engine.ui.components.Sprite;
import org.kakara.engine.ui.constraints.HorizontalCenterConstraint;
import org.kakara.engine.ui.constraints.VerticalCenterConstraint;
import org.kakara.engine.ui.events.UIClickEvent;
import org.kakara.engine.ui.events.UIReleaseEvent;
import org.kakara.engine.ui.font.Font;
import org.kakara.engine.ui.items.ComponentCanvas;
import org.kakara.engine.ui.items.ObjectCanvas;

import org.kakara.engine.ui.objectcanvas.UIObject;
import org.kakara.engine.voxels.VoxelTexture;
import org.kakara.engine.voxels.layouts.BlockLayout;
import org.kakara.game.items.blocks.AirBlock;
import org.kakara.game.resources.GameResourceManager;

Expand All @@ -56,7 +57,7 @@ public class InventoryCanvas extends ComponentCanvas {
public InventoryCanvas(Scene scene, Texture inventoryBackground, Set<MenuElement> elementList, Inventory inventory, Font font) {
super(scene);
if (!(scene instanceof MainGameScene)) throw new IllegalArgumentException("Must be a MainGameScene");

setTag("inventory_canvas");
this.inventoryBackground = inventoryBackground;
this.elements = elementList;
this.inventory = inventory;
Expand All @@ -65,7 +66,7 @@ public InventoryCanvas(Scene scene, Texture inventoryBackground, Set<MenuElement
panel = new Panel();
panel.addConstraint(new HorizontalCenterConstraint());
panel.addConstraint(new VerticalCenterConstraint());
panel.setScale(GameHandler.getInstance().getWindow().initalWidth, GameHandler.getInstance().getWindow().initalHeight);
panel.setScale(GameHandler.getInstance().getWindow().getWidth(), GameHandler.getInstance().getWindow().getHeight());
org.kakara.engine.gameitems.Texture texture = MoreUtils.coreTextureToEngineTexture(inventoryBackground);
Sprite sprite = new Sprite(texture);
sprite.addConstraint(new HorizontalCenterConstraint());
Expand All @@ -80,7 +81,7 @@ public InventoryCanvas(Scene scene, Texture inventoryBackground, Set<MenuElement
panel.setVisible(true);
sprite.setVisible(true);
add(panel);

setAutoScale(false);
}

public void renderItems() {
Expand All @@ -91,6 +92,10 @@ public void renderItems() {
if (objectCanvas == null) {
objectCanvas = new ObjectCanvas(scene);
numberCanvas = new ComponentCanvas(scene);
objectCanvas.setAutoScale(false);
numberCanvas.setAutoScale(false);
objectCanvas.setTag("inventory_object_canvas");
numberCanvas.setTag("inventory_number_canvas");

}
//TODO handle positioning
Expand All @@ -112,7 +117,7 @@ public void renderItems() {
if (item instanceof AirBlock) continue;
UIObject uiObject;
if (item instanceof Block) {
RenderTexture txt = getTexture(itemStack);
VoxelTexture txt = getTexture(itemStack);
AtlasMesh mesh = new AtlasMesh(txt, scene.getTextureAtlas(), new BlockLayout(), CubeData.vertex, CubeData.normal, CubeData.indices);
uiObject = new UIObject(mesh);
objectCanvas.add(uiObject);
Expand Down Expand Up @@ -153,7 +158,7 @@ public void renderItems() {

}

private RenderTexture getTexture(ItemStack is) {
private VoxelTexture getTexture(ItemStack is) {
return scene.getRenderResourceManager().get(GameResourceManager.correctPath(Kakara.getGameInstance().getResourceManager().getTexture(is.getItem().getTexture(), TextureResolution._16, is.getItem().getMod()).getLocalPath()));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class ClientChunk implements Chunk {
private List<GameBlock> gameBlockList;
private boolean updatedHappened = true;
@Nullable
private UUID renderChunkID;
private UUID voxel;
private Status status = Status.UNLOADED;

public ClientChunk(ChunkLocation location) {
Expand Down Expand Up @@ -63,12 +63,12 @@ public Optional<GameBlock> getGameBlock(Location location) {
return getGameBlock(location);
}

public Optional<UUID> getRenderChunkID() {
return Optional.ofNullable(renderChunkID);
public Optional<UUID> getVoxelID() {
return Optional.ofNullable(voxel);
}

public void setRenderChunkID(UUID renderChunkID) {
this.renderChunkID = renderChunkID;
public void setVoxelID(UUID renderChunkID) {
this.voxel = renderChunkID;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import org.kakara.engine.math.Vector2;
import org.kakara.engine.resources.ResourceManager;
import org.kakara.engine.scene.AbstractMenuScene;
import org.kakara.engine.ui.canvases.ComponentCanvas;
import org.kakara.engine.ui.components.Sprite;
import org.kakara.engine.ui.components.shapes.Rectangle;
import org.kakara.engine.ui.components.text.Text;
Expand All @@ -23,7 +24,6 @@
import org.kakara.engine.ui.events.UIHoverLeaveEvent;
import org.kakara.engine.ui.font.Font;
import org.kakara.engine.ui.font.TextAlign;
import org.kakara.engine.ui.items.ComponentCanvas;
import org.kakara.engine.utils.RGBA;
import org.kakara.engine.window.WindowIcon;

Expand Down Expand Up @@ -171,7 +171,7 @@ private void singlePlayerClick(Rectangle playButton) {
gameHandler.getSceneManager().setScene(kakaraGame.join(new LocalJoin(saveCreator.createSave(),UUID.fromString("069a79f4-44e9-4726-a5be-fca90e38aaf5") )));

} catch (Exception ex) {
setCurserStatus(true);
setCursorStatus(true);
KakaraGame.LOGGER.error("unable to start game", ex);
// gameHandler.getSceneManager().setScene();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package org.kakara.client.scenes.canvases;

import org.kakara.engine.scene.Scene;
import org.kakara.engine.ui.items.ComponentCanvas;
import org.kakara.engine.ui.canvases.ComponentCanvas;

public abstract class ActivateableCanvas extends ComponentCanvas {
private boolean activated = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,15 @@
import org.joml.Vector3f;
import org.kakara.client.scenes.maingamescene.MainGameScene;
import org.kakara.engine.GameHandler;
import org.kakara.engine.gameitems.MeshGameItem;
import org.kakara.engine.physics.collision.Collidable;
import org.kakara.engine.renderobjects.RenderBlock;

import org.kakara.engine.scene.AbstractGameScene;
import org.kakara.engine.scene.AbstractScene;
import org.kakara.engine.scene.Scene;
import org.kakara.engine.ui.UICanvas;
import org.kakara.engine.ui.UserInterface;
import org.kakara.engine.ui.items.ComponentCanvas;
import org.kakara.engine.ui.items.ObjectCanvas;

import org.kakara.engine.ui.canvases.ComponentCanvas;
import org.kakara.engine.ui.canvases.ObjectCanvas;
import org.kakara.engine.utils.Time;
import org.kakara.engine.weather.Fog;

Expand Down Expand Up @@ -73,6 +72,16 @@ public void cleanup(GameHandler handler) {
ImGui.destroyContext();
}

@Override
public boolean isAutoScale() {
return false;
}

@Override
public void setAutoScale(boolean b) {

}

private void renderFPSInfo(Scene scene){
ImGui.setNextWindowSize(300, 300, ImGuiCond.Once);
ImGui.setNextWindowPos(10, 300, ImGuiCond.Once);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ private DebugModeCanvas(KakaraGame kakaraGame, MainGameScene scene) {
super(scene);
gameScene = scene;
this.kakaraGame = kakaraGame;

setTag("debugmode_canvas");
ResourceManager resourceManager = GameHandler.getInstance().getResourceManager();

Font roboto = new Font("Roboto-Regular", resourceManager.getResource("Roboto-Regular.ttf"), scene);
Expand All @@ -47,12 +47,12 @@ private DebugModeCanvas(KakaraGame kakaraGame, MainGameScene scene) {
engineVersion = new Text("Engine: " + GameEngine.getEngineVersion(), roboto);
engineVersion.position = new Vector2(0, 75);
engineVersion.setTextAlign(TextAlign.LEFT);
engineVersion.setLineWidth(300);
engineVersion.setLineWidth(400);

kakaraVersion = new Text("Kakara: " + KakaraGame.getGameVersion().getProperty("version"), roboto);
kakaraVersion.position = new Vector2(0, 100);
kakaraVersion.setTextAlign(TextAlign.LEFT);
kakaraVersion.setLineWidth(300);
kakaraVersion.setLineWidth(400);


}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,25 @@
import org.kakara.core.common.game.Item;
import org.kakara.core.common.game.ItemStack;
import org.kakara.core.common.resources.TextureResolution;
import org.kakara.core.server.ServerGameInstance;
import org.kakara.core.server.gui.ServerBoxedInventoryContainer;
import org.kakara.engine.GameHandler;
import org.kakara.engine.engine.CubeData;
import org.kakara.engine.events.EventHandler;
import org.kakara.engine.events.event.KeyPressEvent;
import org.kakara.engine.gameitems.mesh.AtlasMesh;
import org.kakara.engine.gameitems.mesh.Mesh;
import org.kakara.engine.renderobjects.RenderTexture;
import org.kakara.engine.renderobjects.TextureAtlas;
import org.kakara.engine.renderobjects.renderlayouts.BlockLayout;
import org.kakara.engine.scene.Scene;
import org.kakara.engine.ui.UserInterface;
import org.kakara.engine.ui.canvases.ComponentCanvas;
import org.kakara.engine.ui.canvases.ObjectCanvas;
import org.kakara.engine.ui.components.Panel;
import org.kakara.engine.ui.components.shapes.Rectangle;
import org.kakara.engine.ui.components.text.Text;
import org.kakara.engine.ui.font.Font;
import org.kakara.engine.ui.items.ComponentCanvas;
import org.kakara.engine.ui.items.ObjectCanvas;
import org.kakara.engine.ui.objectcanvas.UIObject;
import org.kakara.engine.utils.RGBA;
import org.kakara.engine.voxels.TextureAtlas;
import org.kakara.engine.voxels.VoxelTexture;
import org.kakara.engine.voxels.layouts.BlockLayout;
import org.kakara.game.items.blocks.AirBlock;
import org.kakara.game.resources.GameResourceManager;

Expand Down Expand Up @@ -60,6 +58,7 @@ public HotBarCanvas(Scene scene, TextureAtlas atlas, RenderResourceManager rende
this.renderTextureCache = renderTextureCache;

mainPanel = new Panel();
mainPanel.setAllowOverflow(true);

for (int i = 0; i < 5; i++) {
Rectangle rect = new Rectangle();
Expand All @@ -73,10 +72,13 @@ public HotBarCanvas(Scene scene, TextureAtlas atlas, RenderResourceManager rende
rects[0].setColor(selected);

numberCanvas = new ComponentCanvas(scene);

numberCanvas.setAutoScale(false);
numberCanvas.setTag("hot_bar_number_canvas");
add(mainPanel);
this.roboto = roboto;
renderItems();
setAutoScale(false);
setTag("hotbar_canvas");
}

public void update() {
Expand Down Expand Up @@ -122,6 +124,8 @@ public void renderItems() {
try {
if (objectCanvas == null) {
objectCanvas = new ObjectCanvas(scene);
objectCanvas.setAutoScale(false);
objectCanvas.setTag("hotbar_object_canvas");
}
for (int i = 0; i < 5; i++) {
ItemStack itemStack = contentInventory.getHotBarContents()[i];
Expand All @@ -130,7 +134,7 @@ public void renderItems() {
if (item instanceof AirBlock) continue;
UIObject uiObject;
if (item instanceof Block) {
RenderTexture txt = getTexture(itemStack);
VoxelTexture txt = getTexture(itemStack);
AtlasMesh mesh = new AtlasMesh(txt, atlas, new BlockLayout(), CubeData.vertex, CubeData.normal, CubeData.indices);
uiObject = new UIObject(mesh);
objectCanvas.add(uiObject);
Expand Down Expand Up @@ -158,11 +162,18 @@ public void renderItems() {
}
}

private RenderTexture getTexture(ItemStack is) throws ExecutionException {
return renderTextureCache.get(GameResourceManager.correctPath(Kakara.getGameInstance().getResourceManager().getTexture(is.getItem().getTexture(), TextureResolution._16, is.getItem().getMod()).getLocalPath()));
private VoxelTexture getTexture(ItemStack is) throws ExecutionException {
return renderTextureCache.get(GameResourceManager.correctPath(
Kakara.getGameInstance().getResourceManager().getTexture(is.getItem().getTexture(),
TextureResolution._16, is.getItem().getMod()).getLocalPath()));
}

public RenderTexture getCurrentItem() {
/**
* Get the Voxel Texture for the current item.
*
* @return The voxel texture.
*/
public VoxelTexture getCurrentItem() {
if (contentInventory.getHotBarContents()[selectedIndex] instanceof AirBlock) {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ private PauseMenuCanvas(Scene scene) {
super(scene);
this.scene = scene;
Font roboto = new Font("Roboto", GameHandler.getInstance().getResourceManager().getResource("Roboto-Regular.ttf"), scene);

setTag("pausemenu_canvas");
resume = new Rectangle(new Vector2(0, 270), new Vector2(300, 60), new RGBA(255, 255, 255, 0.5f));
resume.addConstraint(new HorizontalCenterConstraint());

Expand Down Expand Up @@ -90,14 +90,14 @@ public static PauseMenuCanvas getInstance(KakaraGame kakaraGame, Scene scene) {
void add() {
add(quit);
add(resume);
scene.setCurserStatus(true);
scene.setCursorStatus(true);
}

@Override
void remove() {
removeComponent(quit);
removeComponent(resume);
scene.setCurserStatus(false);
scene.setCursorStatus(false);

}

Expand Down
Loading

0 comments on commit 1a90eb6

Please sign in to comment.