Moved client side disconnection handling to this branch and reimplemented it with develop functionality.

#refactor #issue[47]
This commit is contained in:
Calum
2017-08-17 12:11:36 +12:00
parent 7b4a70817b
commit 769d1956b3
5 changed files with 155 additions and 134 deletions
+36 -24
View File
@@ -277,7 +277,31 @@ public class GameView extends Pane {
colour = Color.BLACK;
}
//Creating mark arrows.
createMarkArrows(sequence);
//Scale race to markers if there is no border.
if (borderPoints == null) {
rescaleRace(new ArrayList<>(markerObjects.keySet()));
}
//Move the Markers to initial position.
markerObjects.forEach(((mark, marker) -> {
Point2D p2d = findScaledXY(mark.getLat(), mark.getLng());
marker.setLayoutX(p2d.getX());
marker.setLayoutY(p2d.getY());
}));
Platform.runLater(() -> {
markers.getChildren().clear();
markers.getChildren().addAll(gates);
markers.getChildren().addAll(markerObjects.values());
});
}
/**
* Calculates all the data needed for to create mark arrows. Requires that a course has been
* added to the gameview.
* @param sequence The order in which marks are traversed.
*/
private void createMarkArrows (List<Corner> sequence) {
for (int i=1; i < sequence.size()-1; i++) { //General case.
double averageLat = 0;
double averageLng = 0;
@@ -297,7 +321,7 @@ public class GameView extends Pane {
averageLng += mark.getLng();
}
GeoPoint nextMarkAv = new GeoPoint(averageLat / numMarks, averageLng / numMarks);
// TODO: 16/08/17 This comparison is cancer and deserves to die.
// TODO: 16/08/17 This comparison doesn't need to exist but the alternative is to user server enum client side.
for (Mark mark : course.get(i).getMarks()) {
markerObjects.get(mark).addArrows(
mark.getRoundingSide() == RoundingSide.STARBOARD ? MarkArrowFactory.RoundingSide.STARBOARD : MarkArrowFactory.RoundingSide.PORT,
@@ -306,9 +330,11 @@ public class GameView extends Pane {
);
}
}
createStartLineArrows();
createFinishLineArrows();
}
// TODO: 16/08/17 Make this cleaner
//First mark case
private void createStartLineArrows () {
double averageLat = 0;
double averageLng = 0;
int numMarks = 0;
@@ -325,10 +351,12 @@ public class GameView extends Pane {
GeoUtility.getBearing(mark, firstMarkAv)
);
}
//Last Mark case
numMarks = 0;
averageLat = 0;
averageLng = 0;
}
private void createFinishLineArrows () {
double numMarks = 0;
double averageLat = 0;
double averageLng = 0;
for (Mark mark : course.get(course.size()-2).getMarks()) {
numMarks += 1;
averageLat += mark.getLat();
@@ -342,22 +370,6 @@ public class GameView extends Pane {
GeoUtility.getBearing(mark, mark)
);
}
//Scale race to markers if there is no border.
if (borderPoints == null) {
rescaleRace(new ArrayList<>(markerObjects.keySet()));
}
//Move the Markers to initial position.
markerObjects.forEach(((mark, marker) -> {
Point2D p2d = findScaledXY(mark.getLat(), mark.getLng());
marker.setLayoutX(p2d.getX());
marker.setLayoutY(p2d.getY());
}));
Platform.runLater(() -> {
markers.getChildren().clear();
markers.getChildren().addAll(gates);
markers.getChildren().addAll(markerObjects.values());
});
}
/**