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 rightOffset = 0;
for (int i = 0; i < childrenSize; i++) {
SkillTreeNode child = node.getChildren().get(i);
int yOffset = childrenSize == 1 || child.getChildren().size()== 1 ? 1 : 2;
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();
rightOffset += 2 + nodeBranches.get(child).getRightBranches();
} else if (i % 2 == 0) {
child.setCoordinates(new IntegerCoordinates(x - leftOffset - 2 - nodeBranches.get(child).getWidth(), y - 1));
for (SkillTreeNode skillTree : nodeBranches.keySet())
child.setCoordinates(new IntegerCoordinates(x - leftOffset - 2 - nodeBranches.get(child).getWidth(), y - yOffset));
leftOffset += 2 + nodeBranches.get(child).getWidth();
} 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();
}
@ -113,11 +116,15 @@ public class AutomaticSkillTree extends SkillTree {
int childY = child.getCoordinates().getY();
int parentX = node.getCoordinates().getX();
paths.add(new IntegerCoordinates(childX, childY + 1));
int parentY = node.getCoordinates().getY();
int offset = childX > parentX ? -1 : 1;
while (childY + 1 != parentY) {
paths.add(new IntegerCoordinates(childX, childY + 1));
childY++;
}
while (childX != parentX) {
paths.add(new IntegerCoordinates(childX, childY + 2));
paths.add(new IntegerCoordinates(childX, childY + 1));
childX += offset;
}