Skip to content

Commit

Permalink
Added importing via the editor
Browse files Browse the repository at this point in the history
  • Loading branch information
Pegacraft committed Jan 10, 2021
1 parent 472e7a4 commit e060b57
Show file tree
Hide file tree
Showing 9 changed files with 59 additions and 11 deletions.
1 change: 1 addition & 0 deletions src/main/java/engine/Entity.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

public abstract class Entity {
public int x = 0, y = 0;
public int width = 0, height = 0;
public double rotation = 0;
public Point rotatePos;

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/engine/mechanics/Bossbar.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import static engine.rendering.Graphics.g;

public class Bossbar extends Entity {
private int width, height, maxValue = 100, currentValue = 50;
private int maxValue = 100, currentValue = 50;
private BufferedImage backgroundImage, barImage, overlayImage;
private Color backgroundColor = Color.GRAY, barColor = Color.green;

Expand Down
2 changes: 0 additions & 2 deletions src/main/java/engine/mechanics/Button.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ public class Button extends Entity {
private final Mouse mouseListener;
private final Hitbox h;
private final Map<MouseButtons, Predicate<MouseEvent>> events = new EnumMap<>(MouseButtons.class);
private final int width;
private final int height;
private boolean inside;
private Color color = Color.black;
private Color hoverColor = Color.darkGray;
Expand Down
2 changes: 0 additions & 2 deletions src/main/java/engine/mechanics/EntityList.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ public class EntityList extends Entity {
* This is an entity list. It can be used like a <code>ArrayList</code>. The advantage is, that you can add it to
* the entity list of a scene.
*/
public EntityList() {
}

@Override
public void init() {
Expand Down
2 changes: 0 additions & 2 deletions src/main/java/engine/mechanics/Grid.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
public class Grid extends Entity {
private boolean show = false;
private Color color;
private int width;
private int height;
private int row;
private int column;

Expand Down
57 changes: 57 additions & 0 deletions src/main/java/engine/mechanics/ImportLvl.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package engine.mechanics;

import engine.Entity;

import java.io.*;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.util.Scanner;

public class ImportLvl {

public static EntityList importLvl(String path) {
Scanner reader = null;
EntityList entityList = new EntityList();
try {
File f = new File((ImportLvl.class.getResource(path)).getPath());
reader = new Scanner(f);

while (reader.hasNextLine()) {
Entity entity;
String input = reader.nextLine();
String className, x, y, width, height, params;
className = input.split("[~]")[0];
x = input.split("[~]")[1];
y = input.split("[~]")[2];
width = input.split("[~]")[3];
height = input.split("[~]")[4];
params = input.split("[~]")[5];

if (!params.equals("NONE")) {
Class cl = Class.forName(className);
Constructor con = cl.getConstructor(String.class);
entity = (Entity) con.newInstance(params);
entity.x = Integer.parseInt(x);
entity.y = Integer.parseInt(y);
entity.width = Integer.parseInt(width);
entity.height = Integer.parseInt(height);

} else {
Class cl = Class.forName(className);
Constructor con = cl.getConstructor();
entity = (Entity) con.newInstance();
entity.x = Integer.parseInt(x);
entity.y = Integer.parseInt(y);
entity.width = Integer.parseInt(width);
entity.height = Integer.parseInt(height);
}

entityList.add(entity);

}
} catch (FileNotFoundException | ClassNotFoundException | NoSuchMethodException | IllegalAccessException | InstantiationException | InvocationTargetException e) {
e.printStackTrace();
}
return entityList;
}
}
1 change: 0 additions & 1 deletion src/main/java/engine/mechanics/Slider.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ public class Slider extends Entity {
private int sliderHeight = 20;
private double sliderPosition = 0;
private boolean slide = false;

private int sliderX;
private int sliderY;
private final Mouse mouseListener;
Expand Down
2 changes: 0 additions & 2 deletions src/main/java/engine/mechanics/TextBox.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ public class TextBox extends Entity {
private final Hitbox h;
private TextField textField;
private String displayText = "";
private int width;
private int height;
private boolean selected = false;
private Color fontColor = Color.BLACK;
private Color borderColor = Color.BLACK;
Expand Down
1 change: 0 additions & 1 deletion src/main/java/engine/mechanics/TickBox.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

public class TickBox extends Entity {

private int width, height;
private Color borderColor = Color.black;
private Color tickColor = Color.green;
private Hitbox clickArea;
Expand Down

0 comments on commit e060b57

Please sign in to comment.