Automatic Skill Tree.

This commit is contained in:
Ka0rX 2022-08-18 14:45:30 +02:00
parent 467d9263c4
commit 5cc49fd3ef

View File

@ -92,19 +92,22 @@ public class AutomaticSkillTree extends SkillTree {
int leftOffset = 0; int leftOffset = 0;
int rightOffset = 0; int rightOffset = 0;
for (int i = 0; i < childrenSize; i++) { for (int i = 0; i < childrenSize; i++) {
SkillTreeNode child = node.getChildren().get(i); SkillTreeNode child = node.getChildren().get(i);
int yOffset = childrenSize == 1 || child.getChildren().size()== 1 ? 1 : 2;
if (childrenSize % 2 == 1 && i == 0) { if (childrenSize % 2 == 1 && i == 0) {
child.setCoordinates(new IntegerCoordinates(x, y - 1)); child.setCoordinates(new IntegerCoordinates(x, y - yOffset));
leftOffset += 2 + nodeBranches.get(child).getLeftBranches(); leftOffset += 2 + nodeBranches.get(child).getLeftBranches();
rightOffset += 2 + nodeBranches.get(child).getRightBranches(); rightOffset += 2 + nodeBranches.get(child).getRightBranches();
} else if (i % 2 == 0) { } else if (i % 2 == 0) {
child.setCoordinates(new IntegerCoordinates(x - leftOffset - 2 - nodeBranches.get(child).getWidth(), y - 1)); child.setCoordinates(new IntegerCoordinates(x - leftOffset - 2 - nodeBranches.get(child).getWidth(), y - yOffset));
for (SkillTreeNode skillTree : nodeBranches.keySet()) leftOffset += 2 + nodeBranches.get(child).getWidth();
leftOffset += 2 + nodeBranches.get(child).getWidth();
} else { } else {
child.setCoordinates(new IntegerCoordinates(x + rightOffset + 2 + nodeBranches.get(child).getWidth(), y - 1)); child.setCoordinates(new IntegerCoordinates(x + rightOffset + 2 + nodeBranches.get(child).getWidth(), y - yOffset));
rightOffset += 2 + nodeBranches.get(child).getWidth(); rightOffset += 2 + nodeBranches.get(child).getWidth();
} }
@ -112,12 +115,16 @@ public class AutomaticSkillTree extends SkillTree {
int childX = child.getCoordinates().getX(); int childX = child.getCoordinates().getX();
int childY = child.getCoordinates().getY(); int childY = child.getCoordinates().getY();
int parentX=node.getCoordinates().getX(); int parentX = node.getCoordinates().getX();
int parentY = node.getCoordinates().getY();
paths.add(new IntegerCoordinates(childX, childY + 1));
int offset = childX > parentX ? -1 : 1; int offset = childX > parentX ? -1 : 1;
while (childY + 1 != parentY) {
paths.add(new IntegerCoordinates(childX, childY + 1));
childY++;
}
while (childX != parentX) { while (childX != parentX) {
paths.add(new IntegerCoordinates(childX, childY + 2)); paths.add(new IntegerCoordinates(childX, childY + 1));
childX += offset; childX += offset;
} }