Commit fd441de2 authored by Florian Grabowski's avatar Florian Grabowski
Browse files

Treemap in Bug fixing

parent d1ea8129
......@@ -19,8 +19,8 @@ public class SetPreset implements CommandExecutor {
@Override
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
Builder builder = new Builder();
Server server = sender.getServer();
Builder builder = new Builder(server);
Player player = server.getPlayer(sender.getName());
if (player != null) {
Location location = player.getLocation();
......@@ -31,11 +31,11 @@ public class SetPreset implements CommandExecutor {
Runnable t = () -> {
DataHolder.foundation.setLocation(location);
DataHolder.generateSimpleData(Integer.parseInt(args[0]));
builder.setFoundation(server, location, DataHolder.foundation.getWidth().x, DataHolder.foundation.getWidth().y, DataHolder.foundation.getMaterial());
builder.setFoundation(location, DataHolder.foundation.getWidth().x, DataHolder.foundation.getWidth().y, DataHolder.foundation.getMaterial());
for (Structure structure : DataHolder.foundation.getChildren()) {
Building building = (Building) structure;
sender.sendMessage("bau" + building.toString());
builder.fillQube(server, building.getLocation(), building.getWidth().x, building.getHeight(), building.getWidth().y, building.getMaterial());//Not yet ready to print foundations
builder.fillQube(building.getLocation(), building.getWidth().x, building.getHeight(), building.getWidth().y, building.getMaterial());//Not yet ready to print foundations
}
};
t.run();
......
......@@ -2,9 +2,13 @@ package de._82grfl1bif.KPI_Visualizer.commands;
import de._82grfl1bif.KPI_Visualizer.data.DataHolder;
import de._82grfl1bif.KPI_Visualizer.data.JsonParser;
import de._82grfl1bif.KPI_Visualizer.layouts.TreeMap.Rectangle;
import de._82grfl1bif.KPI_Visualizer.layouts.TreeMap.Row;
import de._82grfl1bif.KPI_Visualizer.layouts.TreeMap.SquarifiedTreemapLayout;
import de._82grfl1bif.KPI_Visualizer.structures.*;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.Server;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
......@@ -13,56 +17,75 @@ import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitRunnable;
import org.jetbrains.annotations.NotNull;
import java.awt.*;
import java.util.Map;
import java.util.logging.Level;
public class generateLayout implements CommandExecutor {
Builder builder = new Builder();
@Override
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
if (args.length < 2){
if (args.length < 2) {
sender.sendMessage("please type or select the needed Arguments with tab.");
return false;
}
sender.sendMessage("generating Layout");
sender.sendMessage("generating SimpleSquareLayout");
Server server = sender.getServer();
Builder builder = new Builder(server);
Player player = server.getPlayer(sender.getName());
JsonParser jsonParser = new JsonParser();
if (!jsonParser.evalJson(args[0])){
if (!jsonParser.evalJson(args[0])) {
sender.sendMessage("failed to parse Json");
return false;
}
if(player != null) {
if (player != null) { //check if Player exists for getting Start coordinates.
Location location = player.getLocation();
if (args[1].equals("SquarifiedTreemap")) { //check 2. Argument whether to use SquarifiedTreemap or SimpleSquare Layout.
BukkitRunnable t = new BukkitRunnable() {
@Override
public void run() {
SquarifiedTreemapLayout squarifiedTreemapLayout = new SquarifiedTreemapLayout();
squarifiedTreemapLayout.generateLayout(DataHolder.foundation, new Rectangle(DataHolder.foundation.getArea(), Math.sqrt(DataHolder.foundation.getArea()), new Point(0, 0)));
builder.setFoundation(location,(int)Math.round(Math.sqrt(DataHolder.foundation.getArea())),(int)Math.round(Math.sqrt(DataHolder.foundation.getArea())), Material.COBBLESTONE);
for (Row row : squarifiedTreemapLayout.getRows()) {
for (Map.Entry<Rectangle, Structure> entry : row.getRectangles().entrySet()) {
Rectangle r = entry.getKey();
Structure s = entry.getValue();
if(s.getClass() == Foundation.class){
builder.setFoundation(location.clone().add(r.getOrigin().x,s.getDepth(),r.getOrigin().y),(int)(r.getWidth()),(int)(r.getHeight()),s.getMaterial());
}else{
builder.fillQube(location.clone().add(r.getOrigin().x,s.getDepth()+100,r.getOrigin().y),(int)(r.getWidth()),((Building)s).getHeight(),(int)(r.getHeight()),s.getMaterial());
}
if(r.getHeight() >= 5 && r.getWidth() >= 5){
BukkitRunnable t = new BukkitRunnable() {
@Override
public void run() {
//DataHolder.ComplexData();
DataHolder.foundation.setLocation(location);
DataHolder.foundation.organizeFoundation();
DataHolder.foundation.correctAllLocations(location);
builder.setFoundation(server, DataHolder.foundation.getLocation().clone().add(0, DataHolder.foundation.getDepth(), 0), DataHolder.foundation.getWidth().x, DataHolder.foundation.getWidth().x, DataHolder.foundation.getMaterial());
setAllChildren(server, DataHolder.foundation);
}
};
t.run();
return true;
}else{
}else{
Bukkit.getLogger().log(Level.SEVERE,"the rectangle is too small");
}
}
}
}
};
t.run();
return true;
} else {
BukkitRunnable t = new BukkitRunnable() {
@Override
public void run() {
DataHolder.foundation.setLocation(location);
DataHolder.foundation.organizeFoundation();
DataHolder.foundation.correctAllLocations(location);
builder.setFoundation(DataHolder.foundation.getLocation().clone().add(0, DataHolder.foundation.getDepth(), 0), DataHolder.foundation.getWidth().x, DataHolder.foundation.getWidth().x, DataHolder.foundation.getMaterial());
builder.setAllChildren(DataHolder.foundation);
}
};
t.run();
return true;
}
} else {
Bukkit.getLogger().log(Level.SEVERE, "Kein Spieler gefunden.");
return false;
}
}
private void setAllChildren(Server server, Foundation foundation) {
for (Structure s : foundation.getChildren()) {
if (s.getClass() == Foundation.class) {//TODO must be revisited to draw rectangular Foundations
builder.setFoundation(server, s.getLocation().clone().add(0, s.getDepth(), 0), s.getWidth().x, s.getWidth().x, s.getMaterial());
setAllChildren(server, (Foundation) s);
} else {//TODO must be revisited to draw rectangular Buildings
builder.buildBuilding(server, s.getLocation().clone().add(1, s.getDepth(), 1), s.getWidth().x - 2, ((Building) s).getHeight(), s.getMaterial());
}
}
}
}
package de._82grfl1bif.KPI_Visualizer.data;
package de._82grfl1bif.KPI_Visualizer.helpers;
import de._82grfl1bif.KPI_Visualizer.data.JsonParser;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabCompleter;
......
package de._82grfl1bif.KPI_Visualizer.helpers;
package de._82grfl1bif.KPI_Visualizer.layouts.SimpleSquare;
import de._82grfl1bif.KPI_Visualizer.structures.Structure;
import java.awt.*;
import java.util.ArrayList;
public class Quadrat extends Shape{
public class Quadrat extends Shape {
private Boolean belegt;
......
package de._82grfl1bif.KPI_Visualizer.helpers;
package de._82grfl1bif.KPI_Visualizer.layouts.SimpleSquare;
import java.awt.*;
import java.util.ArrayList;
......
package de._82grfl1bif.KPI_Visualizer.helpers;
package de._82grfl1bif.KPI_Visualizer.layouts.SimpleSquare;
import java.awt.Point;
......
package de._82grfl1bif.KPI_Visualizer.helpers;
package de._82grfl1bif.KPI_Visualizer.layouts.SimpleSquare;
import de._82grfl1bif.KPI_Visualizer.layouts.SimpleSquare.Quadrat;
import de._82grfl1bif.KPI_Visualizer.layouts.SimpleSquare.Rectangle;
import de._82grfl1bif.KPI_Visualizer.structures.Structure;
import javax.management.AttributeNotFoundException;
......@@ -7,8 +9,7 @@ import java.awt.*;
import java.util.ArrayList;
import java.util.Comparator;
@SuppressWarnings("ALL")
public class Layout {
public class SimpleSquareLayout {
private final ArrayList<Structure> structures;
private final ArrayList<Quadrat> layout = new ArrayList<>();
......@@ -19,7 +20,7 @@ public class Layout {
private int size = 0;
public Layout(ArrayList<Structure> structures){
public SimpleSquareLayout(ArrayList<Structure> structures){
this.structures = structures;//ordered biggest first.
}
......@@ -77,9 +78,9 @@ public class Layout {
layout.add(new Quadrat(new Point(q.bottomLeftCorner.y,q.bottomLeftCorner.x),new Point(q.topRightCorner.y,q.topRightCorner.x))); // gespiegeltes Quadrat
layout.add(new Quadrat(new Point(q.bottomLeftCorner.x,q.bottomLeftCorner.x),structure.getWidth().x)); // Oberes rechtes Quadrat
if((this.size-(2*structure.getWidth().x)) > 0){ //falls Abstand zwischen den Quadraten ist.
Rectangle rTop = new Rectangle(structure.getWidth().x,(this.size-2*structure.getWidth().x),new Point(q .topRightCorner.y,q.bottomLeftCorner.x));
de._82grfl1bif.KPI_Visualizer.layouts.SimpleSquare.Rectangle rTop = new de._82grfl1bif.KPI_Visualizer.layouts.SimpleSquare.Rectangle(structure.getWidth().x,(this.size-2*structure.getWidth().x),new Point(q .topRightCorner.y,q.bottomLeftCorner.x));
layout.addAll(rTop.splitToQuads(rTop));
Rectangle rRight = new Rectangle((this.size-2*structure.getWidth().x),structure.getWidth().x,new Point(q.bottomLeftCorner.x,q.topRightCorner.y));
de._82grfl1bif.KPI_Visualizer.layouts.SimpleSquare.Rectangle rRight = new Rectangle((this.size-2*structure.getWidth().x),structure.getWidth().x,new Point(q.bottomLeftCorner.x,q.topRightCorner.y));
layout.addAll(rRight.splitToQuads(rRight));
}
}
......
package de._82grfl1bif.KPI_Visualizer.layouts.TreeMap;
import de._82grfl1bif.KPI_Visualizer.structures.Structure;
import java.awt.*;
import java.util.ArrayList;
import java.util.HashMap;
public class Rectangle{
private double area;
private double width;
private double height;
private Point origin;
public void setHeight(double height) {
this.height = height;
this.width = area/height;
}
public void setWidth(double width) {
this.width = width;
this.height = area/width;
}
public double getArea() {
return area;
}
public double getWidth() {
return width;
}
public double getHeight() {
return height;
}
public Point getOrigin() {
return origin;
}
public void setOrigin(Point origin) {
this.origin = origin;
}
public Rectangle(double area,double width,Point origin){
this.area = area;
this.origin = origin;
setWidth(width);
}
public double getSideRelation(){
return Math.max(width/height,height/width);
}
public boolean checkSideRelation(double side){
return !(getSideRelation() < Math.max((area/side)/side,side/(area/side)));// false if the Relation gets worse.
}
}
package de._82grfl1bif.KPI_Visualizer.layouts.TreeMap;
import de._82grfl1bif.KPI_Visualizer.structures.Structure;
import java.awt.*;
import java.util.HashMap;
import java.util.Map;
public class Row {
double broad;
boolean horizontal;
public HashMap<Rectangle, Structure> getRectangles() {
return rectangles;
}
HashMap<Rectangle, Structure> rectangles;
Rectangle space;
public Row(Rectangle space) {
this.space = space;
this.rectangles = new HashMap<>();
this.broad = 0;
this.horizontal = (space.getWidth() >= space.getHeight());
}
private double getSideRelation() {
double currentMax = 0;
for (Map.Entry<Rectangle, Structure> entry : rectangles.entrySet()) {
Rectangle r = entry.getKey();
currentMax = Math.max(r.getSideRelation(), currentMax);
}
return currentMax;
}
public void addRectangle(double area, Structure structure) {
double currentArea = getCurrentArea() + area;
if (horizontal) {
this.broad = currentArea / space.getHeight(); //calculating the new broad
int currentHeight = this.space.getOrigin().y; //new temp for height of origins
for (Map.Entry<Rectangle, Structure> entry : rectangles.entrySet()) {
Rectangle r = entry.getKey();
r.setWidth(this.broad);//setting new width&Height for all existing rectangles
r.setOrigin(new Point(this.space.getOrigin().x, currentHeight));//setting new origins for all existing rectangles
currentHeight += (int) Math.round(r.getHeight());//for next origin
}
rectangles.put((new Rectangle(area, this.broad, new Point(this.space.getOrigin().x, currentHeight))), structure);//add new Rectangle
} else {
this.broad = currentArea / space.getWidth(); //calculating the new broad
int currentWidth = this.space.getOrigin().x; //new temp for width of origins
for (Map.Entry<Rectangle, Structure> entry : rectangles.entrySet()) {
Rectangle r = entry.getKey();
r.setHeight(this.broad);//setting new width&Height for all existing rectangles
r.setOrigin(new Point(currentWidth, space.getOrigin().y));//setting new origins for all existing rectangles
currentWidth += (int) Math.round(r.getHeight());//for next origin
}
rectangles.put(new Rectangle(area, area / this.broad, new Point(currentWidth, space.getOrigin().y)), structure);
}
}
private double getCurrentArea() {
double currentArea = 0;
for (Map.Entry<Rectangle, Structure> entry : rectangles.entrySet()) {
Rectangle r = entry.getKey();
currentArea += r.getArea();
}
return currentArea;
}
public boolean checkInsert(double area) {
if (!rectangles.isEmpty()) {
double currentArea = getCurrentArea() + area;
double broadTemp = horizontal ? currentArea / space.getHeight() : currentArea / space.getWidth();
for (Map.Entry<Rectangle, Structure> entry : rectangles.entrySet()) {
Rectangle r = entry.getKey();
if (!r.checkSideRelation(broadTemp))
return false;//returns false if one of the existing rectangles gets worse
}
return !(new Rectangle(area, broad, new Point(0, 0)).getSideRelation() > getSideRelation()); //returns false if the inserted rectangle is worse, than any other before
}else {
return true;
}
}
public Rectangle getLeftover() {
Point origin;
double width;
if (horizontal) {
origin = new Point(space.getOrigin().x + (int)(broad), space.getOrigin().y);
width = space.getWidth() - getWidth();
} else {
origin = new Point(space.getOrigin().x, space.getOrigin().y + (int)(broad));
width = getWidth();
}
return new Rectangle(this.space.getArea() - getCurrentArea(), width, origin);
}
public double getWidth() {
if (horizontal) {
return this.broad;
} else {
return this.space.getWidth();
}
}
public double getHeight() {
if (horizontal) {
return this.space.getHeight();
} else {
return this.broad;
}
}
public boolean isFull(){
return (Math.round(this.space.getArea()) <= Math.round(this.getCurrentArea()));
}
}
package de._82grfl1bif.KPI_Visualizer.layouts.TreeMap;
import de._82grfl1bif.KPI_Visualizer.structures.Foundation;
import de._82grfl1bif.KPI_Visualizer.structures.Structure;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;
public class SquarifiedTreemapLayout {
private ArrayList<Row> rows = new ArrayList<>();
public ArrayList<Row> getRows() {
return rows;
}
public SquarifiedTreemapLayout() {
this.rows = new ArrayList<>();
}
public void generateLayout(Foundation foundation, Rectangle bounds) {
rows.addAll(generateSubLayout(foundation, bounds));
ArrayList<Foundation> foundations = new ArrayList<>();
foundations.add(foundation);
do {
ArrayList<Row> tempRows = new ArrayList<>();
rows.stream().filter(r -> r.rectangles.containsValue(foundations.get(foundations.size()-1))).forEach(row ->
tempRows.addAll(generateSubLayout(foundations.get(foundations.size()-1), new Rectangle(foundations.get(foundations.size()-1).getArea(), row.getWidth(), row.space.getOrigin()))));
rows.addAll(tempRows);//letztes element bearbeitet und ein subLayout dafür angelegt.
ArrayList<Foundation> tempFoundations = new ArrayList<>();
for (Structure s : foundations.get(foundations.size() - 1).getChildren()) {
if (s.getClass() == Foundation.class) {
tempFoundations.add((Foundation) s);
}
}
foundations.remove(foundations.size()-1);
foundations.addAll(tempFoundations);//alle Kinder(nur Foundations) des letzten Elements in die Liste geschrieben und das Element entfernt.
} while (!foundations.isEmpty());
}
private ArrayList<Row> generateSubLayout(Foundation foundation, Rectangle rectangle) {
ArrayList<Row> result = new ArrayList<>();
result.add(new Row(rectangle));
for (Structure s : foundation.getChildren()) {
if (!result.get(result.size() - 1).checkInsert(s.getArea())) {//wenn einfügen in die bestehende Reihe das Seitenverhältnis verschlechtern würde.
Row tempRow = new Row(result.get(result.size() - 1).getLeftover());//erzeige neue Reihe mit dem Rest des alten spaces als space.
result.add(tempRow);//füge die neue Reihe ans Ende der Sammlung ein.
}
result.get(result.size() - 1).addRectangle(s.getArea(), s);//füge das Kind in die letzte Reihe ein, die in der Liste ist.
}
return result;
}
}
......@@ -2,7 +2,7 @@ package de._82grfl1bif.KPI_Visualizer;
import de._82grfl1bif.KPI_Visualizer.commands.SetPreset;
import de._82grfl1bif.KPI_Visualizer.commands.generateLayout;
import de._82grfl1bif.KPI_Visualizer.data.FileInputTabCompleter;
import de._82grfl1bif.KPI_Visualizer.helpers.FileInputTabCompleter;
import org.bukkit.plugin.java.JavaPlugin;
public final class main extends JavaPlugin {
......
......@@ -7,7 +7,13 @@ import org.bukkit.block.Block;
public class Builder {
public void setFoundation(Server server, Location startLocation, int x, int z, Material material) {
Server server;
public Builder(Server server) {
this.server = server;
}
public void setFoundation(Location startLocation, int x, int z, Material material) {
for (int cx = 0; cx < x; cx++) {
for (int cz = 0; cz < z; cz++) {
Block block = server.getWorlds().get(0).getBlockAt(startLocation.clone().add(cx, 0, cz));
......@@ -16,87 +22,78 @@ public class Builder {
}
}
public void fillQube(Server server, Location startLocation, int x, int y, int z, Material material) {
public void fillQube(Location startLocation, int x, int y, int z, Material material) {
for (int cy = 0; cy < y; cy++) {
setFoundation(server, startLocation.clone().add(0, cy, 0), x, z, material);
setFoundation(startLocation.clone().add(0, cy, 0), x, z, material);
}
}
private void setWalls(Server server, Location startLocation, int x, int y,Material material) {
Location save = startLocation.clone();
Location temp = startLocation.clone();
for (int cx = 0; cx < x - 1; cx++) {// x+x Wall
for (int cy = 0; cy < y; cy++) {
server.getWorlds().get(0).getBlockAt(temp.clone().add(cx,cy,1)).setType(material);
}
}
temp = save.clone();
for (int cz = 0; cz < x - 1; cz++) {// z+x Wall
private void setWalls(Location startLocation, int x, int y, int z, Material innerMaterial, Material glassMaterial) {
Location temp = startLocation.clone().add(0,0,1);
for (int cz = 0; cz < z - 2; cz++) {//00-0Z
for (int cy = 0; cy < y; cy++) {
server.getWorlds().get(0).getBlockAt(temp.clone().add(1, cy, cz)).setType(material);
server.getWorlds().get(0).getBlockAt(temp.clone().add(1, cy, cz)).setType(innerMaterial);
server.getWorlds().get(0).getBlockAt(temp.clone().add(0, cy, cz)).setType(glassMaterial);
}
}
temp = save.clone().add(0, 0, x - 1);
for (int cx = 0; cx < x; cx++) {// x+x z+x Wall from x+x
temp = startLocation.clone().add(1,0,0);
for (int cx = 0; cx < x - 2; cx++) {//00-0X
for (int cy = 0; cy < y; cy++) {
server.getWorlds().get(0).getBlockAt(temp.clone().add(cx, cy, -1)).setType(material);
server.getWorlds().get(0).getBlockAt(temp.clone().add(cx, cy, 1)).setType(innerMaterial);
server.getWorlds().get(0).getBlockAt(temp.clone().add(cx, cy, 0)).setType(glassMaterial);
}
}
temp = save.clone().add(x - 1, 0, 0);
for (int cz = 0; cz < x - 1; cz++) {// x+x z+x Wall from x+z
temp = startLocation.clone().add(1, 0, z - 1);
for (int cx = 0; cx < x - 2; cx++) {//0Z-ZX
for (int cy = 0; cy < y; cy++) {
server.getWorlds().get(0).getBlockAt(temp.clone().add(-1, cy, cz)).setType(material);
}
}
server.getWorlds().get(0).getBlockAt(temp.clone().add(cx, cy, -1)).setType(innerMaterial);
server.getWorlds().get(0).getBlockAt(temp.clone().add(cx, cy, 0)).setType(glassMaterial);
temp = save.clone();
for (int cx = 0; cx < x - 1; cx++) {// x+x Wall
for (int cy = 0; cy < y; cy++) {
server.getWorlds().get(0).getBlockAt(temp.clone().add(cx, cy, 0)).setType(Material.GLASS);
}
}
temp = save.clone();
for (int cz = 0; cz < x - 1; cz++) {// z+x Wall
temp = startLocation.clone().add(x - 1, 0, 1);
for (int cz = 0; cz < z - 2; cz++) {//0X-XZ
for (int cy = 0; cy < y; cy++) {
server.getWorlds().get(0).getBlockAt(temp.clone().add(0, cy, cz)).setType(Material.GLASS);
}
}
temp = save.clone().add(0, 0, x - 1);
for (int cx = 0; cx < x; cx++) {// x+x z+x Wall from x+x
for (int cy = 0; cy < y; cy++) {
server.getWorlds().get(0).getBlockAt(temp.clone().add(cx, cy, 0)).setType(Material.GLASS);
}
}
temp = save.clone().add(x - 1, 0, 0);
for (int cz = 0; cz < x - 1; cz++) {// x+x z+x Wall from x+z
for (int cy = 0; cy < y; cy++) {
server.getWorlds().get(0).getBlockAt(temp.clone().add(0, cy, cz)).setType(Material.GLASS);
server.getWorlds().get(0).getBlockAt(temp.clone().add(-1, cy, cz)).setType(innerMaterial);
server.getWorlds().get(0).getBlockAt(temp.clone().add(0, cy, cz)).setType(glassMaterial);
}
}
}
temp = save.clone();
private void setCorners(Location startLocation, int x, int y, int z, Material facade) {
Location temp = startLocation.clone();
for (int cy = 0; cy < y; cy++) {
server.getWorlds().get(0).getBlockAt(temp.clone().add(0, cy, 0)).setType(Material.BLACKSTONE);
server.getWorlds().get(0).getBlockAt(temp.clone().add(0, cy, 0)).setType(facade);
}
temp = save.clone().add(x - 1, 0, 0);
temp = startLocation.clone().add(x - 1, 0, 0);
for (int cy = 0; cy < y; cy++) {
server.getWorlds().get(0).getBlockAt(temp.clone().add(0, cy, 0)).setType(Material.BLACKSTONE);
server.getWorlds().get(0).getBlockAt(temp.clone().add(0, cy, 0)).setType(facade);
}
temp = save.clone().add(0, 0, x - 1);
temp = startLocation.clone().add(0, 0, z - 1);
for (int cy = 0; cy < y; cy++) {
server.getWorlds().get(0).getBlockAt(temp.clone().add(0, cy, 0)).setType(Material.BLACKSTONE);
server.getWorlds().get(0).getBlockAt(temp.clone().add(0, cy, 0)).setType(facade);
}
temp = save.clone().add(x - 1, 0, x - 1);
temp = startLocation.clone().add(x - 1, 0, z - 1);
for (int cy = 0; cy < y; cy++) {
server.getWorlds().get(0).getBlockAt(temp.clone().add(0, cy, 0)).setType(Material.BLACKSTONE);
server.getWorlds().get(0).getBlockAt(temp.clone().add(0, cy, 0)).setType(facade);
}
save.add(0,y,0);//roof
setFoundation(server,save,x,x,Material.BLACKSTONE);
}
public void buildBuilding(Server server, Location startLocation, int x, int y, Material material) {
setWalls(server, startLocation.clone().add(0, 1, 0), x, y, material);
public void buildBuilding(Location startLocation, int x, int y, int z, Material material) {
setWalls(startLocation, x, y, z, material, Material.GLASS);
setCorners(startLocation, x, y, z, Material.BLACKSTONE);
setFoundation(startLocation.clone().add(0, y, 0), x, z, Material.BLACKSTONE);//roof
}
public void setAllChildren(Foundation foundation) {
for (Structure s : foundation.getChildren()) {
if (s.getClass() == Foundation.class) {//TODO must be revisited to draw rectangular Foundations
this.setFoundation(s.getLocation().clone().add(0, s.getDepth(), 0), s.getWidth().x, s.getWidth().x, s.getMaterial());
setAllChildren((Foundation) s);
} else {//TODO must be revisited to draw rectangular Buildings
this.buildBuilding(s.getLocation().clone().add(1, s.getDepth(), 1), s.getWidth().x - 2, ((Building) s).getHeight(),s.getWidth().x-2, s.getMaterial());
}
}
}
}
......@@ -13,7 +13,7 @@ public class Building extends Structure{
this.width.y = width;
this.height = height;
this.material = material;
if(this.width.x < 3){
if(this.width.x < 5){
throw new IllegalArgumentException("keine Gebäude kleiner 3 wegen 2 Gehweg");
}
}
......@@ -22,7 +22,7 @@ public class Building extends Structure{
this.width = width;
this.height = height;
this.material = material;
if(this.width.x < 3 || this.width.y < 3){
if(this.width.x < 5 || this.width.y < 5){
throw new IllegalArgumentException("keine Gebäude kleiner 3 wegen 2 Gehweg");
}
}
......@@ -30,9 +30,10 @@ public class Building extends Structure{
public Building(Material material, Klasse klasse, String name){ //Buildings are Square -> no depth
this.material = material;
this.width = new Point(5,5); //TODO: make this work with treemap and square
this.area = klasse.qloc;
this.name = name;
this.height = klasse.commits; // con be changed to likings TODO: find out which fits best.
if(this.width.x < 3 || this.width.y < 3){
if(this.width.x < 5 || this.width.y < 5){
throw new IllegalArgumentException("keine Gebäude kleiner 3 wegen 2 Gehweg");
}
}
......
package de._82grfl1bif.KPI_Visualizer.structures;
import de._82grfl1bif.KPI_Visualizer.data.Klasse;
import de._82grfl1bif.KPI_Visualizer.helpers.Layout;
import de._82grfl1bif.KPI_Visualizer.layouts.SimpleSquare.SimpleSquareLayout;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.util.Vector;
......@@ -16,7 +16,7 @@ import java.util.Random;
public class Foundation extends Structure {
private ArrayList<Structure> children = new ArrayList<>();
private Layout layout;
private SimpleSquareLayout simpleSquareLayout;
public Foundation(int depth, Material material) { //Foundations are uniform Height
this.width.x = 0;
......@@ -47,7 +47,7 @@ public class Foundation extends Structure {
if (isFoundation) {
result = new Foundation(this.depth + 1, nextMaterial(), name);
} else {
result = new Building(Material.LIME_CONCRETE, klasse, name);
result = new Building(nextMaterial(), klasse, name);
}
this.children.add(result);
return result;
......@@ -143,19 +143,10 @@ public class Foundation extends Structure {
return null;
}
public Structure findByName(String findName) {
if (this.name.equals(findName)) {
return this;
} else {
for (Structure s : this.children) {
if (s.getClass() == Foundation.class) {
if ((((Foundation) s).findByName(findName)) != null) {
return s;
}
}
}
}
return null;
@Override
public double getArea(){
if(area == 0)setAllAreas();
return area;
}
private static class DepthComparator implements Comparator<Foundation> {
......@@ -188,13 +179,13 @@ public class Foundation extends Structure {
} else { //normal Call and recursion
this.children.sort(new WidthComparator());
Collections.reverse(this.children); //Widest Building or Foundation first
this.layout = new Layout(this.children);
this.layout.createLayout();
this.width.x = layout.getSize();
this.simpleSquareLayout = new SimpleSquareLayout(this.children);
this.simpleSquareLayout.createLayout();
this.width.x = simpleSquareLayout.getSize();
}
}
private ArrayList<Foundation> collectAllFoundations() { //called on the base Foundation
public ArrayList<Foundation> collectAllFoundations() { //called on the base Foundation
ArrayList<Foundation> fCollection = new ArrayList<>();
fCollection.add(this);
int currentDepth = this.depth;
......@@ -211,6 +202,18 @@ public class Foundation extends Structure {
return fCollection;
}
public ArrayList<Building> collectAllBuildings() { //called on the base Foundation
ArrayList<Building> buildings = new ArrayList<>();
for (Structure s: children) {
if (s.getClass() == Foundation.class){
buildings.addAll(((Foundation) s).collectAllBuildings());
}else{
buildings.add((Building) s);
}
}
return buildings;
}
private ArrayList<Foundation> getNextDepth() {
ArrayList<Foundation> result = new ArrayList<>();
for (Structure s : this.children) {
......@@ -229,7 +232,7 @@ public class Foundation extends Structure {
public void correctAllLocations(Location location) {
for (Structure s : this.children) {
try {
Point temp = this.layout.getCoordinateOf(s);
Point temp = this.simpleSquareLayout.getCoordinateOf(s);
s.setLocation(location.clone().add(temp.x, 0, temp.y));
if (s.getClass() == Foundation.class) {
Foundation f = (Foundation) s;
......@@ -240,4 +243,17 @@ public class Foundation extends Structure {
}
}
}
private double setAllAreas(){
double myArea = 0;
for (Structure s: children) {
if(s.getClass() == Foundation.class){
myArea += ((Foundation) s).setAllAreas();
}else{
myArea += s.getArea();
}
}
this.area = myArea;
return myArea;
}
}
......@@ -15,6 +15,11 @@ public abstract class Structure{
protected Location location;
protected int depth;
protected String name;
protected double area;
public double getArea() {
return area;
}
public Material getMaterial() {
return material;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment